]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-header-lifetime-elision/dyn-trait.rs
Rollup merge of #99786 - obeis:issue-99625, r=compiler-errors
[rust.git] / src / test / ui / impl-header-lifetime-elision / dyn-trait.rs
1 // Test that `impl MyTrait<'_> for &i32` is equivalent to `impl<'a,
2 // 'b> MyTrait<'a> for &'b i32`.
3
4 #![allow(warnings)]
5
6 use std::fmt::Debug;
7
8 // Equivalent to `Box<dyn Debug + 'static>`:
9 trait StaticTrait { }
10 impl StaticTrait for Box<dyn Debug> { }
11
12 // Equivalent to `Box<dyn Debug + 'static>`:
13 trait NotStaticTrait { }
14 impl NotStaticTrait for Box<dyn Debug + '_> { }
15
16 // Check that we don't err when the trait has a lifetime parameter.
17 trait TraitWithLifetime<'a> { }
18 impl NotStaticTrait for &dyn TraitWithLifetime<'_> { }
19
20 fn static_val<T: StaticTrait>(_: T) {
21 }
22
23 fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
24     static_val(x);
25     //~^ ERROR borrowed data escapes outside of function
26 }
27
28 fn not_static_val<T: NotStaticTrait>(_: T) {
29 }
30
31 fn with_dyn_debug_not_static<'a>(x: Box<dyn Debug + 'a>) {
32     not_static_val(x); // OK
33 }
34
35 fn main() {
36 }