rust
rust copied to clipboard
Cannot use &Trait as argument for generic functions
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.
May be related to #3794
This is by design.