]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/infer-from-object-issue-26952.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / traits / infer-from-object-issue-26952.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Test that when we match a trait reference like `Foo<A>: Foo<_#0t>`,
5 // we unify with `_#0t` with `A`. In this code, if we failed to do
6 // that, then you get an unconstrained type-variable in `call`.
7 //
8 // Also serves as a regression test for issue #26952, though the test
9 // was derived from another reported regression with the same cause.
10
11 use std::marker::PhantomData;
12
13 trait Trait<A> { fn foo(&self); }
14
15 struct Type<A> { a: PhantomData<A> }
16
17 fn as_trait<A>(t: &Type<A>) -> &dyn Trait<A> { loop {  } }
18
19 fn want<A,T:Trait<A>+?Sized>(t: &T) { }
20
21 fn call<A>(p: Type<A>) {
22     let q = as_trait(&p);
23     want(q); // parameter A to `want` *would* be unconstrained
24 }
25
26 fn main() { }