-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Fix vtable ICE on unsatisfied supertrait bounds #154129
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
Open
cdown
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
cdown:cdown/2026-03-20/vtable_ice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−43
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,8 @@ LL | drop::<Option<A>>(None); | |
| = note: the full name for the type has been written to '$TEST_BUILD_DIR/type-length-limit-enforcement.long-type-$LONG_TYPE_HASH.txt' | ||
| = note: consider using `--verbose` to print the full type name to the console | ||
|
|
||
| error: reached the type-length limit while instantiating `<{closure@...} as FnMut<()>>::call_mut` | ||
| error: reached the type-length limit while instantiating `<{closure@...} as FnOnce<()>>::call_once` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also because of the change in ordering. |
||
| --> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
| | | ||
| = help: consider adding a `#![type_length_limit="10"]` attribute to your crate | ||
| = note: the full name for the type has been written to '$TEST_BUILD_DIR/type-length-limit-enforcement.long-type-$LONG_TYPE_HASH.txt' | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Regression test for #154073. | ||
| // Verify that we don't ICE when building vtable entries | ||
| // for a trait whose impl is missing a required method body. | ||
|
|
||
| //@ compile-flags: --crate-type lib | ||
|
|
||
| trait Bar: Sync { | ||
| fn method(&self); | ||
| } | ||
| impl<T: Sync> Bar for T { | ||
| //~^ ERROR not all trait items implemented | ||
| } | ||
|
|
||
| static BAR: &dyn Sync = &false as &dyn Bar; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| error[E0046]: not all trait items implemented, missing: `method` | ||
| --> $DIR/vtable-missing-method-impl.rs:10:1 | ||
| | | ||
| LL | fn method(&self); | ||
| | ----------------- `method` from trait | ||
| LL | } | ||
| LL | impl<T: Sync> Bar for T { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ missing `method` in implementation | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0046`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/traits/vtable/vtable-unsatisfied-supertrait-const.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Regression test for #154073. | ||
| // Verify that we don't ICE when building vtable entries | ||
| // for a trait whose supertrait is not implemented, during | ||
| // const evaluation of a static initializer. | ||
|
|
||
| //@ compile-flags: --crate-type lib | ||
|
|
||
| trait Bar: Send + Sync + Droppable {} | ||
|
|
||
| impl<T: Send> Bar for T {} | ||
| //~^ ERROR the trait bound `T: Droppable` is not satisfied | ||
| //~| ERROR `T` cannot be shared between threads safely | ||
|
|
||
| trait Droppable { | ||
| fn drop(&self); | ||
| } | ||
|
|
||
| const fn upcast(x: &dyn Bar) -> &(dyn Send + Sync) { | ||
| x | ||
| } | ||
|
|
||
| static BAR: &(dyn Send + Sync) = upcast(&false); |
35 changes: 35 additions & 0 deletions
35
tests/ui/traits/vtable/vtable-unsatisfied-supertrait-const.stderr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| error[E0277]: the trait bound `T: Droppable` is not satisfied | ||
| --> $DIR/vtable-unsatisfied-supertrait-const.rs:10:23 | ||
| | | ||
| LL | impl<T: Send> Bar for T {} | ||
| | ^ the trait `Droppable` is not implemented for `T` | ||
| | | ||
| note: required by a bound in `Bar` | ||
| --> $DIR/vtable-unsatisfied-supertrait-const.rs:8:26 | ||
| | | ||
| LL | trait Bar: Send + Sync + Droppable {} | ||
| | ^^^^^^^^^ required by this bound in `Bar` | ||
| help: consider further restricting type parameter `T` with trait `Droppable` | ||
| | | ||
| LL | impl<T: Send + Droppable> Bar for T {} | ||
| | +++++++++++ | ||
|
|
||
| error[E0277]: `T` cannot be shared between threads safely | ||
| --> $DIR/vtable-unsatisfied-supertrait-const.rs:10:23 | ||
| | | ||
| LL | impl<T: Send> Bar for T {} | ||
| | ^ `T` cannot be shared between threads safely | ||
| | | ||
| note: required by a bound in `Bar` | ||
| --> $DIR/vtable-unsatisfied-supertrait-const.rs:8:19 | ||
| | | ||
| LL | trait Bar: Send + Sync + Droppable {} | ||
| | ^^^^ required by this bound in `Bar` | ||
| help: consider further restricting type parameter `T` with trait `Sync` | ||
| | | ||
| LL | impl<T: Send + std::marker::Sync> Bar for T {} | ||
| | +++++++++++++++++++ | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
25 changes: 25 additions & 0 deletions
25
tests/ui/traits/vtable/vtable-unsatisfied-supertrait-generics.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Regression test for #137190. | ||
| // Variant of vtable-unsatisfied-supertrait.rs with generic traits. | ||
| // Verify that we don't ICE when building vtable entries | ||
| // for a generic trait whose supertrait is not implemented. | ||
|
|
||
| //@ compile-flags: --crate-type lib | ||
|
|
||
| trait Supertrait<T> { | ||
| fn method(&self) {} | ||
| } | ||
|
|
||
| trait Trait<P>: Supertrait<()> {} | ||
|
|
||
| impl<P> Trait<P> for () {} | ||
| //~^ ERROR the trait bound `(): Supertrait<()>` is not satisfied | ||
|
|
||
| const fn upcast<P>(x: &dyn Trait<P>) -> &dyn Supertrait<()> { | ||
| x | ||
| } | ||
|
|
||
| const fn foo() -> &'static dyn Supertrait<()> { | ||
| upcast::<()>(&()) | ||
| } | ||
|
|
||
| const _: &'static dyn Supertrait<()> = foo(); |
20 changes: 20 additions & 0 deletions
20
tests/ui/traits/vtable/vtable-unsatisfied-supertrait-generics.stderr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| error[E0277]: the trait bound `(): Supertrait<()>` is not satisfied | ||
| --> $DIR/vtable-unsatisfied-supertrait-generics.rs:14:22 | ||
| | | ||
| LL | impl<P> Trait<P> for () {} | ||
| | ^^ the trait `Supertrait<()>` is not implemented for `()` | ||
| | | ||
| help: this trait has no implementations, consider adding one | ||
| --> $DIR/vtable-unsatisfied-supertrait-generics.rs:8:1 | ||
| | | ||
| LL | trait Supertrait<T> { | ||
| | ^^^^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `Trait` | ||
| --> $DIR/vtable-unsatisfied-supertrait-generics.rs:12:17 | ||
| | | ||
| LL | trait Trait<P>: Supertrait<()> {} | ||
| | ^^^^^^^^^^^^^^ required by this bound in `Trait` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Regression test for #137190. | ||
| // Verify that we don't ICE when building vtable entries | ||
| // for a trait whose supertrait is not implemented. | ||
|
|
||
| //@ compile-flags: --crate-type lib | ||
|
|
||
| trait Supertrait { | ||
| fn method(&self) {} | ||
| } | ||
|
|
||
| trait Trait: Supertrait {} | ||
|
|
||
| impl Trait for () {} | ||
| //~^ ERROR the trait bound `(): Supertrait` is not satisfied | ||
|
|
||
| const _: &dyn Supertrait = &() as &dyn Trait as &dyn Supertrait; |
20 changes: 20 additions & 0 deletions
20
tests/ui/traits/vtable/vtable-unsatisfied-supertrait.stderr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| error[E0277]: the trait bound `(): Supertrait` is not satisfied | ||
| --> $DIR/vtable-unsatisfied-supertrait.rs:13:16 | ||
| | | ||
| LL | impl Trait for () {} | ||
| | ^^ the trait `Supertrait` is not implemented for `()` | ||
| | | ||
| help: this trait has no implementations, consider adding one | ||
| --> $DIR/vtable-unsatisfied-supertrait.rs:7:1 | ||
| | | ||
| LL | trait Supertrait { | ||
| | ^^^^^^^^^^^^^^^^ | ||
| note: required by a bound in `Trait` | ||
| --> $DIR/vtable-unsatisfied-supertrait.rs:11:14 | ||
| | | ||
| LL | trait Trait: Supertrait {} | ||
| | ^^^^^^^^^^ required by this bound in `Trait` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because of the change in ordering.