summaryrefslogtreecommitdiffstats
path: root/src/test/ui/traits/inductive-overflow
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/traits/inductive-overflow')
-rw-r--r--src/test/ui/traits/inductive-overflow/lifetime.rs32
-rw-r--r--src/test/ui/traits/inductive-overflow/lifetime.stderr22
-rw-r--r--src/test/ui/traits/inductive-overflow/simultaneous.rs20
-rw-r--r--src/test/ui/traits/inductive-overflow/simultaneous.stderr20
-rw-r--r--src/test/ui/traits/inductive-overflow/supertrait-auto-trait.rs18
-rw-r--r--src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr35
-rw-r--r--src/test/ui/traits/inductive-overflow/supertrait.rs15
-rw-r--r--src/test/ui/traits/inductive-overflow/supertrait.stderr20
-rw-r--r--src/test/ui/traits/inductive-overflow/two-traits.rs22
-rw-r--r--src/test/ui/traits/inductive-overflow/two-traits.stderr32
10 files changed, 236 insertions, 0 deletions
diff --git a/src/test/ui/traits/inductive-overflow/lifetime.rs b/src/test/ui/traits/inductive-overflow/lifetime.rs
new file mode 100644
index 000000000..c36c17d3d
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/lifetime.rs
@@ -0,0 +1,32 @@
+// Test that we don't hit the recursion limit for short cycles involving lifetimes.
+
+// Shouldn't hit this, we should realize that we're in a cycle sooner.
+#![recursion_limit="20"]
+
+trait NotAuto {}
+trait Y {
+ type P;
+}
+
+impl<'a> Y for C<'a> {
+ type P = Box<X<C<'a>>>;
+}
+
+struct C<'a>(&'a ());
+struct X<T: Y>(T::P);
+
+impl<T: NotAuto> NotAuto for Box<T> {} //~ NOTE: required
+impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
+impl<'a> NotAuto for C<'a> {}
+
+fn is_send<S: NotAuto>() {}
+//~^ NOTE: required
+//~| NOTE: required
+
+fn main() {
+ // Should only be a few notes.
+ is_send::<X<C<'static>>>();
+ //~^ ERROR overflow evaluating
+ //~| 3 redundant requirements hidden
+ //~| required because of
+}
diff --git a/src/test/ui/traits/inductive-overflow/lifetime.stderr b/src/test/ui/traits/inductive-overflow/lifetime.stderr
new file mode 100644
index 000000000..9ca615aac
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/lifetime.stderr
@@ -0,0 +1,22 @@
+error[E0275]: overflow evaluating the requirement `X<C<'_>>: NotAuto`
+ --> $DIR/lifetime.rs:28:5
+ |
+LL | is_send::<X<C<'static>>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: required because of the requirements on the impl of `NotAuto` for `Box<X<C<'_>>>`
+ --> $DIR/lifetime.rs:18:18
+ |
+LL | impl<T: NotAuto> NotAuto for Box<T> {}
+ | ^^^^^^^ ^^^^^^
+ = note: 3 redundant requirements hidden
+ = note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
+note: required by a bound in `is_send`
+ --> $DIR/lifetime.rs:22:15
+ |
+LL | fn is_send<S: NotAuto>() {}
+ | ^^^^^^^ required by this bound in `is_send`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/traits/inductive-overflow/simultaneous.rs b/src/test/ui/traits/inductive-overflow/simultaneous.rs
new file mode 100644
index 000000000..40ac92146
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/simultaneous.rs
@@ -0,0 +1,20 @@
+// Regression test for #33344, initial version. This example allowed
+// arbitrary trait bounds to be synthesized.
+
+trait Tweedledum: IntoIterator {}
+trait Tweedledee: IntoIterator {}
+
+impl<T: Tweedledum> Tweedledee for T {}
+impl<T: Tweedledee> Tweedledum for T {}
+
+trait Combo: IntoIterator {}
+impl<T: Tweedledee + Tweedledum> Combo for T {}
+
+fn is_ee<T: Combo>(t: T) {
+ t.into_iter();
+}
+
+fn main() {
+ is_ee(4);
+ //~^ ERROR overflow evaluating the requirement `{integer}: Tweedle
+}
diff --git a/src/test/ui/traits/inductive-overflow/simultaneous.stderr b/src/test/ui/traits/inductive-overflow/simultaneous.stderr
new file mode 100644
index 000000000..230c2638c
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/simultaneous.stderr
@@ -0,0 +1,20 @@
+error[E0275]: overflow evaluating the requirement `{integer}: Tweedledum`
+ --> $DIR/simultaneous.rs:18:5
+ |
+LL | is_ee(4);
+ | ^^^^^
+ |
+note: required because of the requirements on the impl of `Combo` for `{integer}`
+ --> $DIR/simultaneous.rs:11:34
+ |
+LL | impl<T: Tweedledee + Tweedledum> Combo for T {}
+ | ^^^^^ ^
+note: required by a bound in `is_ee`
+ --> $DIR/simultaneous.rs:13:13
+ |
+LL | fn is_ee<T: Combo>(t: T) {
+ | ^^^^^ required by this bound in `is_ee`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.rs b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.rs
new file mode 100644
index 000000000..5fea47a1b
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.rs
@@ -0,0 +1,18 @@
+// Auto-trait-based version of #29859, supertrait version. Test that using
+// a simple auto trait `..` impl alone still doesn't allow arbitrary bounds
+// to be synthesized.
+
+#![feature(auto_traits)]
+#![feature(negative_impls)]
+
+auto trait Magic: Copy {} //~ ERROR E0568
+
+fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+
+#[derive(Debug)]
+struct NoClone;
+
+fn main() {
+ let (a, b) = copy(NoClone); //~ ERROR
+ println!("{:?} {:?}", a, b);
+}
diff --git a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
new file mode 100644
index 000000000..d7697dcc6
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
@@ -0,0 +1,35 @@
+error[E0568]: auto traits cannot have super traits or lifetime bounds
+ --> $DIR/supertrait-auto-trait.rs:8:17
+ |
+LL | auto trait Magic: Copy {}
+ | -----^^^^^^ help: remove the super traits or lifetime bounds
+ | |
+ | auto trait cannot have super traits or lifetime bounds
+
+error[E0277]: the trait bound `NoClone: Copy` is not satisfied
+ --> $DIR/supertrait-auto-trait.rs:16:23
+ |
+LL | let (a, b) = copy(NoClone);
+ | ---- ^^^^^^^ the trait `Copy` is not implemented for `NoClone`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required because of the requirements on the impl of `Magic` for `NoClone`
+ --> $DIR/supertrait-auto-trait.rs:8:12
+ |
+LL | auto trait Magic: Copy {}
+ | ^^^^^
+note: required by a bound in `copy`
+ --> $DIR/supertrait-auto-trait.rs:10:12
+ |
+LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+ | ^^^^^ required by this bound in `copy`
+help: consider annotating `NoClone` with `#[derive(Copy)]`
+ |
+LL | #[derive(Copy)]
+ |
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0277, E0568.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/traits/inductive-overflow/supertrait.rs b/src/test/ui/traits/inductive-overflow/supertrait.rs
new file mode 100644
index 000000000..c7aa4d90f
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/supertrait.rs
@@ -0,0 +1,15 @@
+// Regression test for #29859, supertrait version. This example
+// allowed arbitrary trait bounds to be synthesized.
+
+trait Magic: Copy {}
+impl<T: Magic> Magic for T {}
+
+fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+
+#[derive(Debug)]
+struct NoClone;
+
+fn main() {
+ let (a, b) = copy(NoClone); //~ ERROR E0275
+ println!("{:?} {:?}", a, b);
+}
diff --git a/src/test/ui/traits/inductive-overflow/supertrait.stderr b/src/test/ui/traits/inductive-overflow/supertrait.stderr
new file mode 100644
index 000000000..95325a534
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/supertrait.stderr
@@ -0,0 +1,20 @@
+error[E0275]: overflow evaluating the requirement `NoClone: Magic`
+ --> $DIR/supertrait.rs:13:18
+ |
+LL | let (a, b) = copy(NoClone);
+ | ^^^^
+ |
+note: required because of the requirements on the impl of `Magic` for `NoClone`
+ --> $DIR/supertrait.rs:5:16
+ |
+LL | impl<T: Magic> Magic for T {}
+ | ^^^^^ ^
+note: required by a bound in `copy`
+ --> $DIR/supertrait.rs:7:12
+ |
+LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+ | ^^^^^ required by this bound in `copy`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/traits/inductive-overflow/two-traits.rs b/src/test/ui/traits/inductive-overflow/two-traits.rs
new file mode 100644
index 000000000..463b55d85
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/two-traits.rs
@@ -0,0 +1,22 @@
+// Regression test for #29859, initial version. This example allowed
+// arbitrary trait bounds to be synthesized.
+
+// Trait that you want all types to implement.
+use std::marker::{Sync as Trait};
+
+pub trait Magic {
+ type X: Trait;
+}
+impl<T: Magic> Magic for T {
+ type X = Self;
+ //~^ ERROR E0277
+}
+
+fn check<T: Trait>() {}
+
+fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
+
+fn main() {
+ wizard::<*mut ()>(); //~ ERROR E0275
+ // check::<*mut ()>();
+}
diff --git a/src/test/ui/traits/inductive-overflow/two-traits.stderr b/src/test/ui/traits/inductive-overflow/two-traits.stderr
new file mode 100644
index 000000000..0d0bf8861
--- /dev/null
+++ b/src/test/ui/traits/inductive-overflow/two-traits.stderr
@@ -0,0 +1,32 @@
+error[E0277]: `T` cannot be shared between threads safely
+ --> $DIR/two-traits.rs:11:14
+ |
+LL | type X = Self;
+ | ^^^^ `T` cannot be shared between threads safely
+ |
+note: required by a bound in `Magic::X`
+ --> $DIR/two-traits.rs:8:13
+ |
+LL | type X: Trait;
+ | ^^^^^ required by this bound in `Magic::X`
+help: consider further restricting this bound
+ |
+LL | impl<T: Magic + std::marker::Sync> Magic for T {
+ | +++++++++++++++++++
+
+error[E0275]: overflow evaluating the requirement `*mut (): Magic`
+ --> $DIR/two-traits.rs:20:5
+ |
+LL | wizard::<*mut ()>();
+ | ^^^^^^^^^^^^^^^^^
+ |
+note: required by a bound in `wizard`
+ --> $DIR/two-traits.rs:17:14
+ |
+LL | fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
+ | ^^^^^ required by this bound in `wizard`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0275, E0277.
+For more information about an error, try `rustc --explain E0275`.