summaryrefslogtreecommitdiffstats
path: root/tests/ui/impl-trait/region-escape-via-bound-contravariant.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/impl-trait/region-escape-via-bound-contravariant.rs')
-rw-r--r--tests/ui/impl-trait/region-escape-via-bound-contravariant.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/region-escape-via-bound-contravariant.rs b/tests/ui/impl-trait/region-escape-via-bound-contravariant.rs
new file mode 100644
index 000000000..79319dfe7
--- /dev/null
+++ b/tests/ui/impl-trait/region-escape-via-bound-contravariant.rs
@@ -0,0 +1,22 @@
+// In contrast to `region-escape-via-bound-invariant`, in this case we
+// *can* return a value of type `&'x u32`, even though `'x` does not
+// appear in the bounds. This is because `&` is contravariant, and so
+// we are *actually* returning a `&'y u32`.
+//
+// See https://github.com/rust-lang/rust/issues/46541 for more details.
+
+// run-pass
+
+#![allow(dead_code)]
+
+trait Trait<'a> { }
+
+impl<'a, 'b> Trait<'b> for &'a u32 { }
+
+fn foo<'x, 'y>(x: &'x u32) -> impl Trait<'y>
+where 'x: 'y
+{
+ x
+}
+
+fn main() { }