diff options
Diffstat (limited to '')
-rw-r--r-- | src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs new file mode 100644 index 000000000..3bae0f173 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs @@ -0,0 +1,31 @@ +#![feature(type_alias_impl_trait)] + +trait Static: 'static {} +impl Static for () {} + +type Gal<T> = impl Static; +fn _defining<T>() -> Gal<T> {} + +trait Callable<Arg> { type Output; } + +/// We can infer `<C as Callable<Arg>>::Output: 'static`, +/// because we know `C: 'static` and `Arg: 'static`, +fn box_str<C, Arg>(s: C::Output) -> Box<dyn AsRef<str> + 'static> +where + Arg: Static, + C: ?Sized + Callable<Arg> + 'static, + C::Output: AsRef<str>, +{ + Box::new(s) +} + +fn extend_lifetime(s: &str) -> Box<dyn AsRef<str> + 'static> { + type MalformedTy = dyn for<'a> Callable<Gal<&'a ()>, Output = &'a str>; + //~^ ERROR binding for associated type `Output` references lifetime `'a` + box_str::<MalformedTy, _>(s) +} + +fn main() { + let extended = extend_lifetime(&String::from("hello")); + println!("{}", extended.as_ref().as_ref()); +} |