-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
trait A {}
struct B<'a, T> { f: &'a T }
impl<'a, T> A for B<'a, T> {}
fn foo(_: &A) {}
fn bar<T>(b: &B<T>) { foo(b) }
fn main() {}
Compiles with:
foo.rs:7:27: 7:28 error: value may contain references; add `'static` bound
foo.rs:7 fn bar<T>(b: &B<T>) { foo(b) }
^
error: aborting due to previous error
If I change it to foo(b as &A)
the code compiles just fine. Perhaps a coercion bug?
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
nikomatsakis commentedon Feb 10, 2014
cc me
gavinb commentedon May 14, 2014
Just had this same problem, in a slightly different situation. In my failing code, the trait is templated, and the struct is empty. It's just for a function wrapper. Same error, and casting it explicitly to the trait type works. If it makes a difference, there are type bounds on T in the impll but none in the trait.
I can try to reduce the code to something simpler and standalone to post if that would help.
rustonaut commentedon Jun 6, 2014
I have the same problem, but with Box insted of & (and a slightly different setup)
won't compile unless I change
self.check(matcher);
toself.check(matcher as Box<A<T>>);
it fails with the same error message:
luqmana commentedon Jun 6, 2014
@Naicode Yep, that's the same issue. I have a pull which should hopefully land sometime today to fix it.
alexcrichton commentedon Jun 13, 2014
Closed by #14682