about summary refs log tree commit diff
path: root/tests/ui/traits/inductive-overflow
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/traits/inductive-overflow
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/traits/inductive-overflow')
-rw-r--r--tests/ui/traits/inductive-overflow/lifetime.rs32
-rw-r--r--tests/ui/traits/inductive-overflow/lifetime.stderr22
-rw-r--r--tests/ui/traits/inductive-overflow/simultaneous.rs20
-rw-r--r--tests/ui/traits/inductive-overflow/simultaneous.stderr20
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs18
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr35
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait.rs15
-rw-r--r--tests/ui/traits/inductive-overflow/supertrait.stderr20
-rw-r--r--tests/ui/traits/inductive-overflow/two-traits.rs22
-rw-r--r--tests/ui/traits/inductive-overflow/two-traits.stderr32
10 files changed, 236 insertions, 0 deletions
diff --git a/tests/ui/traits/inductive-overflow/lifetime.rs b/tests/ui/traits/inductive-overflow/lifetime.rs
new file mode 100644
index 00000000000..004e477374a
--- /dev/null
+++ b/tests/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 for
+}
diff --git a/tests/ui/traits/inductive-overflow/lifetime.stderr b/tests/ui/traits/inductive-overflow/lifetime.stderr
new file mode 100644
index 00000000000..b72d53bddbc
--- /dev/null
+++ b/tests/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 for `Box<X<C<'_>>>` to implement `NotAuto`
+  --> $DIR/lifetime.rs:18:18
+   |
+LL | impl<T: NotAuto> NotAuto for Box<T> {}
+   |                  ^^^^^^^     ^^^^^^
+   = note: 3 redundant requirements hidden
+   = note: required for `X<C<'static>>` to implement `NotAuto`
+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/tests/ui/traits/inductive-overflow/simultaneous.rs b/tests/ui/traits/inductive-overflow/simultaneous.rs
new file mode 100644
index 00000000000..40ac9214674
--- /dev/null
+++ b/tests/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/tests/ui/traits/inductive-overflow/simultaneous.stderr b/tests/ui/traits/inductive-overflow/simultaneous.stderr
new file mode 100644
index 00000000000..09930e60efe
--- /dev/null
+++ b/tests/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 for `{integer}` to implement `Combo`
+  --> $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/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs
new file mode 100644
index 00000000000..5fea47a1be8
--- /dev/null
+++ b/tests/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/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr
new file mode 100644
index 00000000000..3ec288d1382
--- /dev/null
+++ b/tests/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 for `NoClone` to implement `Magic`
+  --> $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/tests/ui/traits/inductive-overflow/supertrait.rs b/tests/ui/traits/inductive-overflow/supertrait.rs
new file mode 100644
index 00000000000..c7aa4d90f58
--- /dev/null
+++ b/tests/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/tests/ui/traits/inductive-overflow/supertrait.stderr b/tests/ui/traits/inductive-overflow/supertrait.stderr
new file mode 100644
index 00000000000..4b862cf79ce
--- /dev/null
+++ b/tests/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 for `NoClone` to implement `Magic`
+  --> $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/tests/ui/traits/inductive-overflow/two-traits.rs b/tests/ui/traits/inductive-overflow/two-traits.rs
new file mode 100644
index 00000000000..463b55d8581
--- /dev/null
+++ b/tests/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/tests/ui/traits/inductive-overflow/two-traits.stderr b/tests/ui/traits/inductive-overflow/two-traits.stderr
new file mode 100644
index 00000000000..0d0bf88616c
--- /dev/null
+++ b/tests/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`.