2018-03-21 16:12:39 -05:00
|
|
|
// Test that `impl MyTrait<'_> for &i32` is equivalent to `impl<'a,
|
|
|
|
// 'b> MyTrait<'a> for &'b i32`.
|
|
|
|
|
|
|
|
#![allow(warnings)]
|
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
// Equivalent to `Box<dyn Debug + 'static>`:
|
|
|
|
trait StaticTrait { }
|
|
|
|
impl StaticTrait for Box<dyn Debug> { }
|
|
|
|
|
|
|
|
// Equivalent to `Box<dyn Debug + 'static>`:
|
|
|
|
trait NotStaticTrait { }
|
|
|
|
impl NotStaticTrait for Box<dyn Debug + '_> { }
|
|
|
|
|
2022-05-11 15:49:39 -05:00
|
|
|
// Check that we don't err when the trait has a lifetime parameter.
|
|
|
|
trait TraitWithLifetime<'a> { }
|
|
|
|
impl NotStaticTrait for &dyn TraitWithLifetime<'_> { }
|
|
|
|
|
2018-03-21 16:12:39 -05:00
|
|
|
fn static_val<T: StaticTrait>(_: T) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
|
2022-05-21 14:14:11 -05:00
|
|
|
static_val(x);
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR borrowed data escapes outside of function
|
2018-03-21 16:12:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn not_static_val<T: NotStaticTrait>(_: T) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn with_dyn_debug_not_static<'a>(x: Box<dyn Debug + 'a>) {
|
|
|
|
not_static_val(x); // OK
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|