2018-03-21 21:12:39 +00: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 20:49:39 +00: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 21:12:39 +00:00
|
|
|
fn static_val<T: StaticTrait>(_: T) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
|
2022-05-21 19:14:11 +00:00
|
|
|
static_val(x);
|
2022-04-01 17:13:25 +00:00
|
|
|
//~^ ERROR borrowed data escapes outside of function
|
2018-03-21 21:12:39 +00: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() {
|
|
|
|
}
|