Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented#152287
Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom Feb 9, 2026
Merged
Conversation
…l when a supertrait not implemented compiler/rustc_trait_selection/src/traits/vtable.rs@`vtable_entries`: The impossible predicates check in `vtable_entries` used `instantiate_own` which only includes the method's own where-clauses, not the parent trait's bounds. Replace it with `instantiate_and_check_impossible_predicates` which also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is marked `Vacant` instead of ICEing.
Collaborator
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
@bors r+ |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 9, 2026
…enkov Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented compiler/rustc_trait_selection/src/traits/vtable.rs@`vtable_entries`: The impossible predicates check in `vtable_entries` used `instantiate_own` which only includes the method's own `where` clauses, without the parent trait's bounds. Replace it with `instantiate_and_check_impossible_predicates` which also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is marked `Vacant` instead of ICEing. Closes rust-lang#137190. Closes rust-lang#135470.
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 9, 2026
…enkov Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented compiler/rustc_trait_selection/src/traits/vtable.rs@`vtable_entries`: The impossible predicates check in `vtable_entries` used `instantiate_own` which only includes the method's own `where` clauses, without the parent trait's bounds. Replace it with `instantiate_and_check_impossible_predicates` which also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is marked `Vacant` instead of ICEing. Closes rust-lang#137190. Closes rust-lang#135470.
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Feb 9, 2026
…enkov Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented compiler/rustc_trait_selection/src/traits/vtable.rs@`vtable_entries`: The impossible predicates check in `vtable_entries` used `instantiate_own` which only includes the method's own `where` clauses, without the parent trait's bounds. Replace it with `instantiate_and_check_impossible_predicates` which also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is marked `Vacant` instead of ICEing. Closes rust-lang#137190. Closes rust-lang#135470.
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 9, 2026
Rollup of 12 pull requests Successful merges: - #152388 (`rust-analyzer` subtree update) - #151613 (Align `ArrayWindows` trait impls with `Windows`) - #152134 (Set crt_static_allow_dylibs to true for Emscripten target) - #152166 (cleanup some more things in `proc_macro::bridge`) - #152236 (compiletest: `-Zunstable-options` for json targets) - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented) - #142957 (std: introduce path normalize methods at top of `std::path`) - #145504 (Add some conversion trait impls) - #152131 (Port rustc_no_implicit_bounds attribute to parser.) - #152315 (fix: rhs_span to rhs_span_new) - #152327 (Check stalled coroutine obligations eagerly) - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 9, 2026
Rollup of 12 pull requests Successful merges: - #152388 (`rust-analyzer` subtree update) - #151613 (Align `ArrayWindows` trait impls with `Windows`) - #152134 (Set crt_static_allow_dylibs to true for Emscripten target) - #152166 (cleanup some more things in `proc_macro::bridge`) - #152236 (compiletest: `-Zunstable-options` for json targets) - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented) - #142957 (std: introduce path normalize methods at top of `std::path`) - #145504 (Add some conversion trait impls) - #152131 (Port rustc_no_implicit_bounds attribute to parser.) - #152315 (fix: rhs_span to rhs_span_new) - #152327 (Check stalled coroutine obligations eagerly) - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
rust-bors bot
pushed a commit
that referenced
this pull request
Feb 9, 2026
Rollup of 12 pull requests Successful merges: - #152388 (`rust-analyzer` subtree update) - #151613 (Align `ArrayWindows` trait impls with `Windows`) - #152134 (Set crt_static_allow_dylibs to true for Emscripten target) - #152166 (cleanup some more things in `proc_macro::bridge`) - #152236 (compiletest: `-Zunstable-options` for json targets) - #152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented) - #142957 (std: introduce path normalize methods at top of `std::path`) - #145504 (Add some conversion trait impls) - #152131 (Port rustc_no_implicit_bounds attribute to parser.) - #152315 (fix: rhs_span to rhs_span_new) - #152327 (Check stalled coroutine obligations eagerly) - #152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
rust-timer
added a commit
that referenced
this pull request
Feb 9, 2026
Rollup merge of #152287 - jakubadamw:issue-137190, r=petrochenkov Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented compiler/rustc_trait_selection/src/traits/vtable.rs@`vtable_entries`: The impossible predicates check in `vtable_entries` used `instantiate_own` which only includes the method's own `where` clauses, without the parent trait's bounds. Replace it with `instantiate_and_check_impossible_predicates` which also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is marked `Vacant` instead of ICEing. Closes #137190. Closes #135470.
github-actions bot
pushed a commit
to rust-lang/rust-analyzer
that referenced
this pull request
Feb 16, 2026
Rollup of 12 pull requests Successful merges: - rust-lang/rust#152388 (`rust-analyzer` subtree update) - rust-lang/rust#151613 (Align `ArrayWindows` trait impls with `Windows`) - rust-lang/rust#152134 (Set crt_static_allow_dylibs to true for Emscripten target) - rust-lang/rust#152166 (cleanup some more things in `proc_macro::bridge`) - rust-lang/rust#152236 (compiletest: `-Zunstable-options` for json targets) - rust-lang/rust#152287 (Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait not implemented) - rust-lang/rust#142957 (std: introduce path normalize methods at top of `std::path`) - rust-lang/rust#145504 (Add some conversion trait impls) - rust-lang/rust#152131 (Port rustc_no_implicit_bounds attribute to parser.) - rust-lang/rust#152315 (fix: rhs_span to rhs_span_new) - rust-lang/rust#152327 (Check stalled coroutine obligations eagerly) - rust-lang/rust#152377 (Rename the query system's `JobOwner` to `ActiveJobGuard`, and include `key_hash`)
Member
|
This PR ideally should have had a T-types reviewer |
cdown
added a commit
to cdown/rust
that referenced
this pull request
Mar 20, 2026
When a trait impl doesn't satisfy its supertrait bounds (for example, `impl<T: Send> Bar for T` where `trait Bar: Droppable` but `T` has no `Droppable` bound), the compiler emits E0277 and then then continues compilation. If a static initialiser then upcasts through this broken impl, const evaluation builds the vtable and tries to resolve methods for the unsatisfied supertrait (for example, `<bool as Droppable>::drop`). One might think that the `impossible_predicates` guard in `vtable_entries` should catch this, but it doesn't, because it calls `predicates_of(method).instantiate_own()`, which only includes the method's own where clauses, and the parent trait's `Self: Trait` predicate lives on the trait definition, not the method, so the guard passes and we fall through to `expect_resolve_for_vtable`, which hits a `span_bug!` when resolution returns `Ok(None)`. There was a previous attempt to fix this in rust-lang#152287, which worked by switching to `instantiate_and_check_impossible_predicates`, which includes parent predicates and the trait ref. But unfortunately this is unsound and was reverted because `impossible_predicates` has a pre-existing unsoundness with coroutine witness types and opaque types (see rust-lang#153596). Let's take a different approach that avoids `impossible_predicates` entirely. Let's extract the core of `expect_resolve_for_vtable` into a fallible `try_resolve_for_vtable` that returns `Result<Instance, ErrorGuaranteed>`, and on resolution failure emit a `delayed_bug`. `vtable_entries` then can use this and return `VtblEntry::Vacant` on the error path. Fixes rust-lang#154073, rust-lang#137190, rust-lang#135470
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compiler/rustc_trait_selection/src/traits/vtable.rs@
vtable_entries:The impossible predicates check in
vtable_entriesusedinstantiate_ownwhich only includes the method's ownwhereclauses, without the parent trait's bounds. Replace it withinstantiate_and_check_impossible_predicateswhich also checks the trait ref itself, so unsatisfied supertrait bounds are caught and the method is markedVacantinstead of ICEing.Closes #137190.
Closes #135470.