summaryrefslogtreecommitdiffstats
path: root/tests/ui/implied-bounds
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/implied-bounds')
-rw-r--r--tests/ui/implied-bounds/ice-unbound-region-vars.rs24
-rw-r--r--tests/ui/implied-bounds/normalization-nested.lifetime.stderr18
-rw-r--r--tests/ui/implied-bounds/normalization-nested.rs39
-rw-r--r--tests/ui/implied-bounds/normalization.rs58
4 files changed, 139 insertions, 0 deletions
diff --git a/tests/ui/implied-bounds/ice-unbound-region-vars.rs b/tests/ui/implied-bounds/ice-unbound-region-vars.rs
new file mode 100644
index 000000000..9e1e3feae
--- /dev/null
+++ b/tests/ui/implied-bounds/ice-unbound-region-vars.rs
@@ -0,0 +1,24 @@
+// Because of #109628, we can have unbounded region vars in implied bounds.
+// Make sure we don't ICE in this case!
+//
+// check-pass
+
+pub trait MapAccess {
+ type Error;
+ fn next_key_seed(&mut self) -> Option<Self::Error>;
+}
+
+struct Access<'a> {
+ _marker: std::marker::PhantomData<&'a ()>,
+}
+
+// implied_bounds(Option<Self::Error>) = ['?1: 'a, ]
+// where '?1 is a fresh region var.
+impl<'a, 'b: 'a> MapAccess for Access<'a> {
+ type Error = ();
+ fn next_key_seed(&mut self) -> Option<Self::Error> {
+ unimplemented!()
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/implied-bounds/normalization-nested.lifetime.stderr b/tests/ui/implied-bounds/normalization-nested.lifetime.stderr
new file mode 100644
index 000000000..898e5e951
--- /dev/null
+++ b/tests/ui/implied-bounds/normalization-nested.lifetime.stderr
@@ -0,0 +1,18 @@
+error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
+ --> $DIR/normalization-nested.rs:35:20
+ |
+LL | pub fn test<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
+ | ^^^^^^^^^^^^^^^^
+ | |
+ | this data with lifetime `'x`...
+ | ...is used and required to live as long as `'static` here
+ |
+note: `'static` lifetime requirement introduced by this bound
+ --> $DIR/normalization-nested.rs:33:14
+ |
+LL | I::Item: 'static;
+ | ^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0759`.
diff --git a/tests/ui/implied-bounds/normalization-nested.rs b/tests/ui/implied-bounds/normalization-nested.rs
new file mode 100644
index 000000000..5f1cbb3f6
--- /dev/null
+++ b/tests/ui/implied-bounds/normalization-nested.rs
@@ -0,0 +1,39 @@
+// Test for normalization of projections that appear in the item bounds
+// (versus those that appear directly in the input types).
+// Both revisions should pass. `lifetime` revision is a bug.
+//
+// revisions: param_ty lifetime
+// [param_ty] check-pass
+// [lifetime] check-fail
+// [lifetime] known-bug: #109799
+
+pub trait Iter {
+ type Item;
+}
+
+#[cfg(param_ty)]
+impl<X, I> Iter for I
+where
+ I: IntoIterator<Item = X>,
+{
+ type Item = X;
+}
+
+#[cfg(lifetime)]
+impl<'x, I> Iter for I
+where
+ I: IntoIterator<Item = &'x ()>,
+{
+ type Item = &'x ();
+}
+
+pub struct Map<I>(I)
+where
+ I: Iter,
+ I::Item: 'static;
+
+pub fn test<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
+ s
+}
+
+fn main() {}
diff --git a/tests/ui/implied-bounds/normalization.rs b/tests/ui/implied-bounds/normalization.rs
new file mode 100644
index 000000000..f776fc98a
--- /dev/null
+++ b/tests/ui/implied-bounds/normalization.rs
@@ -0,0 +1,58 @@
+// Test that we get implied bounds from complex projections after normalization.
+
+// check-pass
+
+// implementations wil ensure that
+// WF(<T as Combine<'a>>::Ty) implies T: 'a
+trait Combine<'a> {
+ type Ty;
+}
+
+impl<'a, T: 'a> Combine<'a> for Box<T> {
+ type Ty = &'a T;
+}
+
+// ======= Wrappers ======
+
+// normalizes to a projection
+struct WrapA<T>(T);
+impl<'a, T> Combine<'a> for WrapA<T>
+where
+ T: Combine<'a>,
+{
+ type Ty = T::Ty;
+}
+
+// <WrapB<T> as Combine<'a>>::Ty normalizes to a type variable ?X
+// with constraint `<T as Combine<'a>>::Ty == ?X`
+struct WrapB<T>(T);
+impl<'a, X, T> Combine<'a> for WrapB<T>
+where
+ T: Combine<'a, Ty = X>,
+{
+ type Ty = X;
+}
+
+// <WrapC<T> as Combine<'a>>::Ty normalizes to `&'a &'?x ()`
+// with constraint `<T as Combine<'a>>::Ty == &'a &'?x ()`
+struct WrapC<T>(T);
+impl<'a, 'x: 'a, T> Combine<'a> for WrapC<T>
+where
+ T: Combine<'a, Ty = &'a &'x ()>,
+{
+ type Ty = &'a &'x ();
+}
+
+//==== Test implied bounds ======
+
+fn test_wrap<'a, 'b, 'c1, 'c2, A, B>(
+ _: <WrapA<Box<A>> as Combine<'a>>::Ty, // normalized: &'a A
+ _: <WrapB<Box<B>> as Combine<'b>>::Ty, // normalized: &'b B
+ _: <WrapC<Box<&'c1 ()>> as Combine<'c2>>::Ty, // normalized: &'c2 &'c1 ()
+) {
+ None::<&'a A>;
+ None::<&'b B>;
+ None::<&'c2 &'c1 ()>;
+}
+
+fn main() {}