Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ impl<'tcx> At<'_, 'tcx> {
.into_value_registering_obligations(self.infcx, &mut *fulfill_cx);
let errors = fulfill_cx.select_all_or_error(self.infcx);
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)
}
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions tests/crashes/133868.rs

This file was deleted.

24 changes: 24 additions & 0 deletions tests/ui/traits/deep-norm-pending.rs
Original file line number Diff line number Diff line change
@@ -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() {}
130 changes: 130 additions & 0 deletions tests/ui/traits/deep-norm-pending.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading