about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2025-02-13 17:46:07 -0800
committerGitHub <noreply@github.com>2025-02-13 17:46:07 -0800
commite2ee9f73189de5b64012fd9ce2ae4e1411db0ed4 (patch)
tree2e0f00d1dfdcbd71bdf1117e4abb25bd9aa70b7e /tests
parenta567209daab72b7ea59eac533278064396bb0534 (diff)
parent059288ed442f34c336c759486bfe4373b61288a0 (diff)
Rollup merge of #136863 - lcnr:treat-as-rigid, r=compiler-errors
rework rigid alias handling

Necessary for https://github.com/rust-lang/rust/pull/136824 if we treat coinductive cycles as errors as we otherwise don't emit an error for

```rust
trait Overflow {
    type Assoc;
}
impl<T> Overflow for T {
    type Assoc = <T as Overflow>::Assoc;
}
```

The important part is that we only add a `RigidAlias` candidate in cases where the alias is actually supposed to be rigid:
- its trait bound has been proven via a `ParamEnv` or `ItemBound` candidate
- it's one of the special builtin traits which have a blanket impl with a `default` assoc type

This means that we now more explicitly control which aliases should rigid to avoid accidentally accepting cyclic aliases. This requires changes to diagnostics as we no longer enter an explicit `RigidAlias` candidate for `NormalizesTo` goals whose trait bound doesn't hold.

To fix this I've modified the `BestObligation` visitor always ignore `RigidAlias` candidates and to instead manually check these requirements if there are no applicable candidates. I also removed the hack for handling `structurally_normalize_ty` failures. This fixes #134905 as we no longer continue to use the `EvalCtxt` even though a nested goal failed.

r? ``@compiler-errors``
Diffstat (limited to 'tests')
-rw-r--r--tests/crashes/134905.rs16
-rw-r--r--tests/ui/auto-traits/assoc-ty.next.stderr25
-rw-r--r--tests/ui/auto-traits/assoc-ty.rs4
-rw-r--r--tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr14
-rw-r--r--tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs8
-rw-r--r--tests/ui/specialization/fuzzed/fuzzing-ice-134905.rs22
-rw-r--r--tests/ui/specialization/fuzzed/fuzzing-ice-134905.stderr40
7 files changed, 96 insertions, 33 deletions
diff --git a/tests/crashes/134905.rs b/tests/crashes/134905.rs
deleted file mode 100644
index 9f0f0f4b3f2..00000000000
--- a/tests/crashes/134905.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-//@ known-bug: #134905
-
-trait Iterate<'a> {
-    type Ty: Valid;
-}
-impl<'a, T> Iterate<'a> for T
-where
-    T: Check,
-{
-    default type Ty = ();
-}
-
-trait Check {}
-impl<'a, T> Eq for T where <T as Iterate<'a>>::Ty: Valid {}
-
-trait Valid {}
diff --git a/tests/ui/auto-traits/assoc-ty.next.stderr b/tests/ui/auto-traits/assoc-ty.next.stderr
index b9f56d6c99c..4ce00d17475 100644
--- a/tests/ui/auto-traits/assoc-ty.next.stderr
+++ b/tests/ui/auto-traits/assoc-ty.next.stderr
@@ -21,20 +21,21 @@ LL | | }
    = help: add `#![feature(auto_traits)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error[E0308]: mismatched types
-  --> $DIR/assoc-ty.rs:15:36
+error[E0271]: type mismatch resolving `<() as Trait>::Output normalizes-to _`
+  --> $DIR/assoc-ty.rs:15:12
    |
 LL |     let _: <() as Trait>::Output = ();
-   |            ---------------------   ^^ types differ
-   |            |
-   |            expected due to this
+   |            ^^^^^^^^^^^^^^^^^^^^^ types differ
+
+error[E0271]: type mismatch resolving `<() as Trait>::Output normalizes-to _`
+  --> $DIR/assoc-ty.rs:15:12
+   |
+LL |     let _: <() as Trait>::Output = ();
+   |            ^^^^^^^^^^^^^^^^^^^^^ types differ
    |
-   = note: expected associated type `<() as Trait>::Output`
-                    found unit type `()`
-   = help: consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
-   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0308, E0380, E0658.
-For more information about an error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0271, E0380, E0658.
+For more information about an error, try `rustc --explain E0271`.
diff --git a/tests/ui/auto-traits/assoc-ty.rs b/tests/ui/auto-traits/assoc-ty.rs
index ada75147f6e..efbfead9cd0 100644
--- a/tests/ui/auto-traits/assoc-ty.rs
+++ b/tests/ui/auto-traits/assoc-ty.rs
@@ -13,5 +13,7 @@ auto trait Trait {
 
 fn main() {
     let _: <() as Trait>::Output = ();
-    //~^ ERROR mismatched types
+    //[current]~^ ERROR mismatched types
+    //[next]~^^ ERROR type mismatch resolving `<() as Trait>::Output normalizes-to _`
+    //[next]~| ERROR type mismatch resolving `<() as Trait>::Output normalizes-to _`
 }
diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr
index 3c24eb9adbe..ce64a022214 100644
--- a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr
+++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr
@@ -23,7 +23,19 @@ error[E0271]: type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> == ()`
 LL |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
 
-error: aborting due to 3 previous errors
+error[E0271]: type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> normalizes-to _`
+  --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:73
+   |
+LL |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
+   |                                                                         ^^ types differ
+
+error[E0271]: type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> normalizes-to _`
+  --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:5
+   |
+LL |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
+
+error: aborting due to 5 previous errors
 
 Some errors have detailed explanations: E0049, E0271, E0407.
 For more information about an error, try `rustc --explain E0049`.
diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs
index c97bd179943..cb32723b22d 100644
--- a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs
+++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs
@@ -26,9 +26,11 @@ impl X for Y {
     //~^ ERROR type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter
     type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>;
     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
-    //[current]~^ ERROR `()` is not a future
-    //[next]~^^ ERROR type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> == ()`
-    //~^^^ method `line_stream` is not a member of trait `X`
+    //~^ method `line_stream` is not a member of trait `X`
+    //[current]~^^ ERROR `()` is not a future
+    //[next]~^^^ ERROR type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> == ()`
+    //[next]~| ERROR type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> normalizes-to _`
+    //[next]~| ERROR type mismatch resolving `<Y as X>::LineStreamFut<'a, Repr> normalizes-to _`
 }
 
 pub fn main() {}
diff --git a/tests/ui/specialization/fuzzed/fuzzing-ice-134905.rs b/tests/ui/specialization/fuzzed/fuzzing-ice-134905.rs
new file mode 100644
index 00000000000..559c2345527
--- /dev/null
+++ b/tests/ui/specialization/fuzzed/fuzzing-ice-134905.rs
@@ -0,0 +1,22 @@
+// This test previously tried to use a tainted `EvalCtxt` when emitting
+// an error during coherence.
+#![feature(specialization)]
+//~^ WARN the feature `specialization` is incomplete
+trait Iterate<'a> {
+    type Ty: Valid;
+}
+impl<'a, T> Iterate<'a> for T
+where
+    T: Check,
+{
+    default type Ty = ();
+    //~^ ERROR the trait bound `(): Valid` is not satisfied
+}
+
+trait Check {}
+impl<'a, T> Eq for T where <T as Iterate<'a>>::Ty: Valid {}
+//~^ ERROR type parameter `T` must be used as the type parameter for some local type
+
+trait Valid {}
+
+fn main() {}
diff --git a/tests/ui/specialization/fuzzed/fuzzing-ice-134905.stderr b/tests/ui/specialization/fuzzed/fuzzing-ice-134905.stderr
new file mode 100644
index 00000000000..611fef1df66
--- /dev/null
+++ b/tests/ui/specialization/fuzzed/fuzzing-ice-134905.stderr
@@ -0,0 +1,40 @@
+warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/fuzzing-ice-134905.rs:3:12
+   |
+LL | #![feature(specialization)]
+   |            ^^^^^^^^^^^^^^
+   |
+   = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
+   = help: consider using `min_specialization` instead, which is more stable and complete
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0277]: the trait bound `(): Valid` is not satisfied
+  --> $DIR/fuzzing-ice-134905.rs:12:23
+   |
+LL |     default type Ty = ();
+   |                       ^^ the trait `Valid` is not implemented for `()`
+   |
+help: this trait has no implementations, consider adding one
+  --> $DIR/fuzzing-ice-134905.rs:20:1
+   |
+LL | trait Valid {}
+   | ^^^^^^^^^^^
+note: required by a bound in `Iterate::Ty`
+  --> $DIR/fuzzing-ice-134905.rs:6:14
+   |
+LL |     type Ty: Valid;
+   |              ^^^^^ required by this bound in `Iterate::Ty`
+
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
+  --> $DIR/fuzzing-ice-134905.rs:17:10
+   |
+LL | impl<'a, T> Eq for T where <T as Iterate<'a>>::Ty: Valid {}
+   |          ^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
+Some errors have detailed explanations: E0210, E0277.
+For more information about an error, try `rustc --explain E0210`.