]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/user-annotations/normalization-infer.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
[rust.git] / tests / ui / nll / user-annotations / normalization-infer.rs
1 // Annnotations may contain projection types with inference variables as input.
2 // Make sure we don't get ambiguities when normalizing them.
3
4 // check-fail
5
6 // Single impl.
7 fn test1<A, B, C, D>(a: A, b: B, c: C) {
8     trait Tr { type Ty; }
9     impl<T: 'static> Tr for (T,) { type Ty = T; }
10
11     let _: <(_,) as Tr>::Ty = a; //~ ERROR type `A`
12     Some::<<(_,) as Tr>::Ty>(b); //~ ERROR type `B`
13     || -> <(_,) as Tr>::Ty { c }; //~ ERROR type `C`
14     |d: <(_,) as Tr>::Ty| -> D { d }; //~ ERROR type `D`
15 }
16
17
18 // Two impls. The selected impl depends on the actual type.
19 fn test2<A, B, C>(a: A, b: B, c: C) {
20     trait Tr { type Ty; }
21     impl<T: 'static> Tr for (u8, T) { type Ty = T; }
22     impl<T>          Tr for (i8, T) { type Ty = T; }
23     type Alias<X, Y> = (<(X, Y) as Tr>::Ty, X);
24
25     fn temp() -> String { todo!() }
26
27     // `u8` impl, requires static.
28     let _: Alias<_, _> = (a, 0u8); //~ ERROR type `A`
29     Some::<Alias<_, _>>((b, 0u8)); //~ ERROR type `B`
30     || -> Alias<_, _> { (c, 0u8) }; //~ ERROR type `C`
31
32     let _: Alias<_, _> = (&temp(), 0u8); //~ ERROR temporary value
33     Some::<Alias<_, _>>((&temp(), 0u8)); //~ ERROR temporary value
34
35     // `i8` impl, no region constraints.
36     let _: Alias<_, _> = (&temp(), 0i8);
37     Some::<Alias<_, _>>((&temp(), 0i8));
38 }
39
40 fn main() {}