Skip to content

Instantly share code, notes, and snippets.

@DaGenix
Last active August 29, 2015 13:55
Show Gist options
  • Save DaGenix/8772910 to your computer and use it in GitHub Desktop.
Save DaGenix/8772910 to your computer and use it in GitHub Desktop.
Question about generic impls
trait SomeTrait { }
struct SomeStruct;
impl SomeTrait for SomeStruct { }
fn foo<T: SomeTrait>(_: T) { }
fn main() {
// This works fine
let x = SomeStruct;
foo(x);
// This fails with: error: failed to find an implementation of trait SomeTrait for &SomeStruct
let y = SomeStruct;
foo(&y);
// If I add this to the code: impl <'a> SomeTrait for &'a SomeStruct { }
// everything compiles. Is there some reason Rust can't derive that impl automatically?
// Is there a plan to have Rust automatically derive it in the future? Does this have
// something to do with DSTs?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment