Rollup merge of #140021 - compiler-errors:no-deep-norm-ice, r=lcnr

Don't ICE on pending obligations from deep normalization in a loop

See the comment I left inline in `compiler/rustc_trait_selection/src/traits/normalize.rs`.

Fixes https://github.com/rust-lang/rust/issues/133868

r? lcnr
This commit is contained in:
Chris Denton 2025-04-21 15:55:58 +00:00 committed by GitHub
commit f79eef91df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 163 additions and 14 deletions

View file

@ -77,7 +77,15 @@ impl<'tcx> At<'_, 'tcx> {
.into_value_registering_obligations(self.infcx, &mut *fulfill_cx); .into_value_registering_obligations(self.infcx, &mut *fulfill_cx);
let errors = fulfill_cx.select_all_or_error(self.infcx); let errors = fulfill_cx.select_all_or_error(self.infcx);
let value = self.infcx.resolve_vars_if_possible(value); let value = self.infcx.resolve_vars_if_possible(value);
if errors.is_empty() { Ok(value) } else { Err(errors) } if errors.is_empty() {
Ok(value)
} else {
// Drop pending obligations, since deep normalization may happen
// in a loop and we don't want to trigger the assertion on the next
// iteration due to pending ambiguous obligations we've left over.
let _ = fulfill_cx.collect_remaining_errors(self.infcx);
Err(errors)
}
} }
} }
} }

View file

@ -1,13 +0,0 @@
//@ known-bug: #133868
trait Foo {
type Assoc;
}
trait Bar {
fn method() -> impl Sized;
}
impl<T> Bar for T where <T as Foo>::Assoc: Sized
{
fn method() {}
}

View file

@ -0,0 +1,24 @@
trait Foo {
type Assoc;
}
trait Bar {
fn method() -> impl Sized;
//~^ ERROR the trait bound `T: Foo` is not satisfied
}
impl<T> Bar for T
//~^ ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
where
<T as Foo>::Assoc: Sized,
{
fn method() {}
//~^ ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
//~| ERROR the trait bound `T: Foo` is not satisfied
}
fn main() {}

View file

@ -0,0 +1,130 @@
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:5
|
LL | fn method() {}
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:9:1
|
LL | / impl<T> Bar for T
LL | |
LL | |
LL | | where
LL | | <T as Foo>::Assoc: Sized,
| |_____________________________^ the trait `Foo` is not implemented for `T`
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:9:1
|
LL | / impl<T> Bar for T
LL | |
LL | |
LL | | where
... |
LL | | }
| |_^ the trait `Foo` is not implemented for `T`
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:5
|
LL | fn method() {}
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:5
|
LL | fn method() {}
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
note: required for `T` to implement `Bar`
--> $DIR/deep-norm-pending.rs:9:9
|
LL | impl<T> Bar for T
| ^^^ ^
...
LL | <T as Foo>::Assoc: Sized,
| ----- unsatisfied trait bound introduced here
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:5
|
LL | fn method() {}
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:6:20
|
LL | fn method() -> impl Sized;
| ^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
note: required for `T` to implement `Bar`
--> $DIR/deep-norm-pending.rs:9:9
|
LL | impl<T> Bar for T
| ^^^ ^
...
LL | <T as Foo>::Assoc: Sized,
| ----- unsatisfied trait bound introduced here
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:5
|
LL | fn method() {}
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `T`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/deep-norm-pending.rs:15:8
|
LL | fn method() {}
| ^^^^^^ the trait `Foo` is not implemented for `T`
|
help: consider further restricting type parameter `T` with trait `Foo`
|
LL | <T as Foo>::Assoc: Sized, T: Foo
| ++++++
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0277`.