diff options
Diffstat (limited to 'tests/ui/traits/object/issue-44454-2.rs')
-rw-r--r-- | tests/ui/traits/object/issue-44454-2.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/traits/object/issue-44454-2.rs b/tests/ui/traits/object/issue-44454-2.rs new file mode 100644 index 000000000..f5178bcdb --- /dev/null +++ b/tests/ui/traits/object/issue-44454-2.rs @@ -0,0 +1,22 @@ +// Taken from https://github.com/rust-lang/rust/issues/44454#issuecomment-1175925928 + +trait Trait<ARG: 'static>: 'static { + type Assoc: AsRef<str>; +} + +fn hr<T: ?Sized, ARG>(x: T::Assoc) -> Box<dyn AsRef<str> + 'static> +where + T: Trait<ARG> +{ + Box::new(x) +} + +fn extend_lt<'a>(x: &'a str) -> Box<dyn AsRef<str> + 'static> { + type DynTrait = dyn for<'a> Trait<&'a str, Assoc = &'a str>; + hr::<DynTrait, _>(x) //~ ERROR: borrowed data escapes outside of function +} + +fn main() { + let extended = extend_lt(&String::from("hello")); + println!("{}", extended.as_ref().as_ref()); +} |