1 // Check that method matching does not make "guesses" depending on
2 // Deref impls that don't eventually end up being picked.
6 // An impl with less derefs will get called over an impl with more derefs,
7 // so `(t: Foo<_>).my_fn()` will use `<Foo<u32> as MyTrait1>::my_fn(t)`,
8 // and does *not* force the `_` to equal `()`, because the Deref impl
15 impl MyTrait1 for Foo<u32> {}
19 impl Deref for Foo<()> {
20 type Target = dyn MyTrait1 + 'static;
21 fn deref(&self) -> &(dyn MyTrait1 + 'static) {
26 // ...but if there is no impl with less derefs, the "guess" will be
27 // forced, so `(t: Bar<_>).my_fn2()` is `<dyn MyTrait2 as MyTrait2>::my_fn2(*t)`,
28 // and because the deref impl is used, the `_` is forced to equal `u8`.
34 impl MyTrait2 for u32 {}
35 struct Bar<T>(T, u32);
36 impl Deref for Bar<u8> {
37 type Target = dyn MyTrait2 + 'static;
38 fn deref(&self) -> &(dyn MyTrait2 + 'static) {
43 // actually invoke things
46 let mut foo: Option<Foo<_>> = None;
47 let mut bar: Option<Bar<_>> = None;
48 let mut first_iter = true;
51 foo.as_ref().unwrap().my_fn();
52 bar.as_ref().unwrap().my_fn2();
56 bar = Some(Bar(Default::default(), 0));