diff options
Diffstat (limited to 'tests/ui/traits/inductive-overflow')
10 files changed, 243 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 000000000..bf536d21c --- /dev/null +++ b/tests/ui/traits/inductive-overflow/lifetime.rs @@ -0,0 +1,33 @@ +// 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 +//~^ NOTE unsatisfied trait bound introduced here +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 000000000..357e59991 --- /dev/null +++ b/tests/ui/traits/inductive-overflow/lifetime.stderr @@ -0,0 +1,24 @@ +error[E0275]: overflow evaluating the requirement `X<C<'_>>: NotAuto` + --> $DIR/lifetime.rs:29: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> {} + | ------- ^^^^^^^ ^^^^^^ + | | + | unsatisfied trait bound introduced here + = 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:23: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 000000000..40ac92146 --- /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 000000000..e3b4ec07d --- /dev/null +++ b/tests/ui/traits/inductive-overflow/simultaneous.stderr @@ -0,0 +1,22 @@ +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 {} + | ---------- ^^^^^ ^ + | | + | unsatisfied trait bound introduced here +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 000000000..5fea47a1b --- /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 000000000..3ec288d13 --- /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 000000000..c7aa4d90f --- /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 000000000..b537ecf17 --- /dev/null +++ b/tests/ui/traits/inductive-overflow/supertrait.stderr @@ -0,0 +1,22 @@ +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 {} + | ----- ^^^^^ ^ + | | + | unsatisfied trait bound introduced here +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 000000000..463b55d85 --- /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 000000000..0d0bf8861 --- /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`. |