]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-header-lifetime-elision/trait-underscore.rs
Do not eagerly recover for bad impl-trait in macros
[rust.git] / tests / ui / impl-header-lifetime-elision / trait-underscore.rs
1 // Test that `impl MyTrait<'_> for &i32` is equivalent to `impl<'a,
2 // 'b> MyTrait<'a> for &'b i32`.
3 //
4 // run-pass
5
6 #![allow(warnings)]
7
8 trait MyTrait<'a> { }
9
10 // This is equivalent to `MyTrait<'a> for &'b i32`, which is proven by
11 // the code below.
12 impl MyTrait<'_> for &i32 {
13 }
14
15 // When called, T will be `&'x i32` for some `'x`, so since we can
16 // prove that `&'x i32: for<'a> MyTrait<'a>, then we know that the
17 // lifetime parameter above is disconnected.
18 fn impls_my_trait<T: for<'a> MyTrait<'a>>() { }
19
20 fn impls_my_trait_val<T: for<'a> MyTrait<'a>>(_: T) {
21     impls_my_trait::<T>();
22 }
23
24 fn random_where_clause()
25 where for<'a, 'b> &'a i32: MyTrait<'b> { }
26
27 fn main() {
28     let x = 22;
29     let f = &x;
30     impls_my_trait_val(f);
31
32     impls_my_trait::<&'static i32>();
33
34     random_where_clause();
35 }