about summary refs log tree commit diff
path: root/tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs')
-rw-r--r--tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs b/tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs
new file mode 100644
index 00000000000..0bf32a2624f
--- /dev/null
+++ b/tests/ui/impl-trait/member-constraints/nested-impl-trait-fail.rs
@@ -0,0 +1,33 @@
+// Nested impl-traits can impose different member constraints on the same region variable.
+
+//@ check-fail
+
+trait Cap<'a> {}
+impl<T> Cap<'_> for T {}
+
+// Assuming the hidden type is `[&'?15 u8; 1]`, we have two distinct member constraints:
+// - '?15 member ['static, 'a, 'b] // from outer impl-trait
+// - '?15 member ['static, 'a, 'b] // from inner impl-trait
+// To satisfy both we can choose 'a or 'b, so it's a failure due to ambiguity.
+fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>
+where
+    's: 'a,
+    's: 'b,
+{
+    [a]
+    //~^ ERROR E0700
+    //~| ERROR E0700
+}
+
+// Same as the above but with late-bound regions.
+fn fail_late_bound<'s, 'a, 'b>(
+    a: &'s u8,
+    _: &'a &'s u8,
+    _: &'b &'s u8,
+) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> {
+    [a]
+    //~^ ERROR E0700
+    //~| ERROR E0700
+}
+
+fn main() {}