Skip to content

Trait coercion may ask for a static bound #11612

Closed
@alexcrichton

Description

@alexcrichton
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?

cc @pcwalton, @luqmana

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions