rust icon indicating copy to clipboard operation
rust copied to clipboard

Cannot use &Trait as argument for generic functions

Open 14427 opened this issue 13 years ago • 2 comments

This code fails to compile

trait Foo {
    fn bar(&self);
}

impl int: Foo {
    fn bar(&self) { }
}

fn test<T: Foo>(arr: T) { }

fn main() {
    let x = 5;
    test(&x as &Foo);
}

with: mismatched types: expected@Foobut found&/Foo(trait storage differs: expected @ but found &)

This is with the current master.

14427 avatar Jan 13 '13 16:01 14427

May be related to #3794

catamorphism avatar Jan 14 '13 00:01 catamorphism

This is by design.

pcwalton avatar Mar 20 '13 17:03 pcwalton