summaryrefslogtreecommitdiffstats
path: root/tests/ui/lifetimes/issue-105507.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/ui/lifetimes/issue-105507.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/lifetimes/issue-105507.rs b/tests/ui/lifetimes/issue-105507.rs
new file mode 100644
index 000000000..f46c6b6f2
--- /dev/null
+++ b/tests/ui/lifetimes/issue-105507.rs
@@ -0,0 +1,43 @@
+// run-rustfix
+//
+#![allow(warnings)]
+struct Wrapper<'a, T: ?Sized>(&'a T);
+
+trait Project {
+ type Projected<'a> where Self: 'a;
+ fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_>;
+}
+trait MyTrait {}
+trait ProjectedMyTrait {}
+
+impl<T> Project for Option<T> {
+ type Projected<'a> = Option<Wrapper<'a, T>> where T: 'a;
+ fn project(this: Wrapper<'_, Self>) -> Self::Projected<'_> {
+ this.0.as_ref().map(Wrapper)
+ }
+}
+
+impl<T: MyTrait> MyTrait for Option<Wrapper<'_, T>> {}
+
+impl<T: ProjectedMyTrait> MyTrait for Wrapper<'_, T> {}
+
+impl<T> ProjectedMyTrait for T
+ where
+ T: Project,
+ for<'a> T::Projected<'a>: MyTrait,
+ //~^ NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime
+ //~| NOTE due to current limitations in the borrow checker, this implies a `'static` lifetime
+{}
+
+fn require_trait<T: MyTrait>(_: T) {}
+
+fn foo<T : MyTrait, U : MyTrait>(wrap: Wrapper<'_, Option<T>>, wrap1: Wrapper<'_, Option<U>>) {
+ //~^ HELP consider restricting the type parameter to the `'static` lifetime
+ //~| HELP consider restricting the type parameter to the `'static` lifetime
+ require_trait(wrap);
+ //~^ ERROR `T` does not live long enough
+ require_trait(wrap1);
+ //~^ ERROR `U` does not live long enough
+}
+
+fn main() {}