diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /tests/ui/traits/next-solver/overflow | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/next-solver/overflow')
11 files changed, 222 insertions, 0 deletions
diff --git a/tests/ui/traits/next-solver/overflow/exponential-trait-goals.rs b/tests/ui/traits/next-solver/overflow/exponential-trait-goals.rs new file mode 100644 index 000000000..a465bcecf --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/exponential-trait-goals.rs @@ -0,0 +1,19 @@ +// compile-flags: -Znext-solver + +trait Trait {} + +struct W<T>(T); + +impl<T, U> Trait for W<(W<T>, W<U>)> +where + W<T>: Trait, + W<U>: Trait, +{ +} + +fn impls<T: Trait>() {} + +fn main() { + impls::<W<_>>(); + //~^ ERROR overflow evaluating the requirement `W<_>: Trait` +} diff --git a/tests/ui/traits/next-solver/overflow/exponential-trait-goals.stderr b/tests/ui/traits/next-solver/overflow/exponential-trait-goals.stderr new file mode 100644 index 000000000..90b54b1e7 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/exponential-trait-goals.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `W<_>: Trait` + --> $DIR/exponential-trait-goals.rs:17:13 + | +LL | impls::<W<_>>(); + | ^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`exponential_trait_goals`) +note: required by a bound in `impls` + --> $DIR/exponential-trait-goals.rs:14:13 + | +LL | fn impls<T: Trait>() {} + | ^^^^^ required by this bound in `impls` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/overflow/global-cache.rs b/tests/ui/traits/next-solver/overflow/global-cache.rs new file mode 100644 index 000000000..fe4032ca6 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/global-cache.rs @@ -0,0 +1,23 @@ +// compile-flags: -Znext-solver + +// Check that we consider the reached depth of global cache +// entries when detecting overflow. We would otherwise be unstable +// wrt to incremental compilation. +#![recursion_limit = "9"] + +trait Trait {} + +struct Inc<T>(T); + +impl<T: Trait> Trait for Inc<T> {} +impl Trait for () {} + +fn impls_trait<T: Trait>() {} + +type Four<T> = Inc<Inc<Inc<Inc<T>>>>; + +fn main() { + impls_trait::<Four<Four<()>>>(); + impls_trait::<Four<Four<Four<Four<()>>>>>(); + //~^ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/traits/next-solver/overflow/global-cache.stderr b/tests/ui/traits/next-solver/overflow/global-cache.stderr new file mode 100644 index 000000000..676166193 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/global-cache.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `Inc<Inc<Inc<Inc<Inc<Inc<Inc<...>>>>>>>: Trait` + --> $DIR/global-cache.rs:21:19 + | +LL | impls_trait::<Four<Four<Four<Four<()>>>>>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "18"]` attribute to your crate (`global_cache`) +note: required by a bound in `impls_trait` + --> $DIR/global-cache.rs:15:19 + | +LL | fn impls_trait<T: Trait>() {} + | ^^^^^ required by this bound in `impls_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/overflow/recursion-limit-normalizes-to-constraints.rs b/tests/ui/traits/next-solver/overflow/recursion-limit-normalizes-to-constraints.rs new file mode 100644 index 000000000..03ef93dc2 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursion-limit-normalizes-to-constraints.rs @@ -0,0 +1,25 @@ +// compile-flags: -Znext-solver=coherence +// check-pass + +// A regression test for trait-system-refactor-initiative#70. + +trait Trait { + type Assoc; +} + +struct W<T: ?Sized>(*mut T); +impl<T: ?Sized> Trait for W<W<T>> +where + W<T>: Trait, +{ + type Assoc = (); +} + +trait NoOverlap {} +impl<T: Trait<Assoc = u32>> NoOverlap for T {} +// `Projection(<W<_> as Trait>::Assoc, u32)` should result in error even +// though applying the impl results in overflow. This is necessary to match +// the behavior of the old solver. +impl<T: ?Sized> NoOverlap for W<T> {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.rs b/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.rs new file mode 100644 index 000000000..52a17a142 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.rs @@ -0,0 +1,12 @@ +//~ ERROR overflow evaluating the requirement `Self well-formed` +//~| ERROR overflow evaluating the requirement `Self: Trait` + +// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE. +// compile-flags: -Znext-solver --crate-type=lib +// check-fail + +#![recursion_limit = "0"] +trait Trait {} +impl Trait for u32 {} +//~^ ERROR overflow evaluating the requirement `u32: Trait` +//~| ERROR overflow evaluating the requirement `u32 well-formed` diff --git a/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.stderr b/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.stderr new file mode 100644 index 000000000..16b25d90a --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.stderr @@ -0,0 +1,27 @@ +error[E0275]: overflow evaluating the requirement `Self: Trait` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `Self well-formed` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `u32: Trait` + --> $DIR/recursion-limit-zero-issue-115351.rs:10:16 + | +LL | impl Trait for u32 {} + | ^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error[E0275]: overflow evaluating the requirement `u32 well-formed` + --> $DIR/recursion-limit-zero-issue-115351.rs:10:16 + | +LL | impl Trait for u32 {} + | ^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`) + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs new file mode 100644 index 000000000..327ef865d --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs @@ -0,0 +1,20 @@ +// compile-flags: -Znext-solver + +trait Foo1 { + type Assoc1; +} + +trait Foo2 { + type Assoc2; +} + +trait Bar {} +fn needs_bar<S: Bar>() {} + +fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() { + needs_bar::<T::Assoc1>(); + //~^ ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` + //~| ERROR overflow evaluating the requirement `<T as Foo2>::Assoc2` +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr new file mode 100644 index 000000000..eda62b99c --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr @@ -0,0 +1,24 @@ +error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` + --> $DIR/recursive-self-normalization-2.rs:15:17 + | +LL | needs_bar::<T::Assoc1>(); + | ^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) +note: required by a bound in `needs_bar` + --> $DIR/recursive-self-normalization-2.rs:12:17 + | +LL | fn needs_bar<S: Bar>() {} + | ^^^ required by this bound in `needs_bar` + +error[E0275]: overflow evaluating the requirement `<T as Foo2>::Assoc2` + --> $DIR/recursive-self-normalization-2.rs:15:5 + | +LL | needs_bar::<T::Assoc1>(); + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs new file mode 100644 index 000000000..f45d208e6 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs @@ -0,0 +1,16 @@ +// compile-flags: -Znext-solver + +trait Foo { + type Assoc; +} + +trait Bar {} +fn needs_bar<S: Bar>() {} + +fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() { + needs_bar::<T::Assoc>(); + //~^ ERROR overflow evaluating the requirement `<T as Foo>::Assoc: Bar` + //~| ERROR overflow evaluating the requirement `<T as Foo>::Assoc` [E0275] +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr new file mode 100644 index 000000000..b0a0a6976 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr @@ -0,0 +1,24 @@ +error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar` + --> $DIR/recursive-self-normalization.rs:11:17 + | +LL | needs_bar::<T::Assoc>(); + | ^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) +note: required by a bound in `needs_bar` + --> $DIR/recursive-self-normalization.rs:8:17 + | +LL | fn needs_bar<S: Bar>() {} + | ^^^ required by this bound in `needs_bar` + +error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc` + --> $DIR/recursive-self-normalization.rs:11:5 + | +LL | needs_bar::<T::Assoc>(); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`. |