-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Fix ICE in next-solver dyn-compatibility check #154923
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
rust-bors
merged 1 commit into
rust-lang:main
from
cijiugechu:fix-ice-unsafe-binders-next-solver
Apr 8, 2026
+92
−0
Merged
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
23 changes: 23 additions & 0 deletions
23
tests/ui/dyn-compatibility/unsafe-binders-bare-trait-object-next-solver.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,23 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/151311> | ||
| //@ edition: 2024 | ||
| //@ compile-flags: -Znext-solver=globally | ||
|
|
||
| #![feature(unsafe_binders)] | ||
|
|
||
| use std::ops::Deref; | ||
|
|
||
| trait Foo: Deref<Target = unsafe<'a> &'a dyn Bar> { | ||
| fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| //~^ ERROR expected a type, found a trait | ||
| //~| ERROR use of undeclared lifetime name `'a` | ||
| } | ||
|
|
||
| trait Bar {} | ||
|
|
||
| fn test(x: &dyn Foo) { | ||
| //~^ ERROR the trait `Foo` is not dyn compatible | ||
| x.method(); | ||
| //~^ ERROR no method named `method` found for reference `&dyn Foo` | ||
| } | ||
|
|
||
| fn main() {} | ||
62 changes: 62 additions & 0 deletions
62
tests/ui/dyn-compatibility/unsafe-binders-bare-trait-object-next-solver.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,62 @@ | ||
| error[E0261]: use of undeclared lifetime name `'a` | ||
| --> $DIR/unsafe-binders-bare-trait-object-next-solver.rs:10:36 | ||
| | | ||
| LL | fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| | ^^ undeclared lifetime | ||
| | | ||
| = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html | ||
| help: consider making the type lifetime-generic with a new `'a` lifetime | ||
| | | ||
| LL | fn method(self: &unsafe<'a, 'ops> &'a Bar) {} | ||
| | +++ | ||
| help: consider introducing lifetime `'a` here | ||
| | | ||
| LL | fn method<'a>(self: &unsafe<'ops> &'a Bar) {} | ||
| | ++++ | ||
| help: consider introducing lifetime `'a` here | ||
| | | ||
| LL | trait Foo<'a>: Deref<Target = unsafe<'a> &'a dyn Bar> { | ||
| | ++++ | ||
|
|
||
| error[E0782]: expected a type, found a trait | ||
| --> $DIR/unsafe-binders-bare-trait-object-next-solver.rs:10:39 | ||
| | | ||
| LL | fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| | ^^^ | ||
| | | ||
| help: you can add the `dyn` keyword if you want a trait object | ||
| | | ||
| LL | fn method(self: &unsafe<'ops> &'a dyn Bar) {} | ||
| | +++ | ||
|
|
||
| error[E0038]: the trait `Foo` is not dyn compatible | ||
| --> $DIR/unsafe-binders-bare-trait-object-next-solver.rs:17:13 | ||
| | | ||
| LL | fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| | --------------------- help: consider changing method `method`'s `self` parameter to be `&self`: `&Self` | ||
| ... | ||
| LL | fn test(x: &dyn Foo) { | ||
| | ^^^^^^^ `Foo` is not dyn compatible | ||
| | | ||
| note: for a trait to be dyn compatible it needs to allow building a vtable | ||
| for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> | ||
| --> $DIR/unsafe-binders-bare-trait-object-next-solver.rs:10:21 | ||
| | | ||
| LL | trait Foo: Deref<Target = unsafe<'a> &'a dyn Bar> { | ||
| | --- this trait is not dyn compatible... | ||
| LL | fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^ ...because method `method`'s `self` parameter cannot be dispatched on | ||
|
|
||
| error[E0599]: no method named `method` found for reference `&dyn Foo` in the current scope | ||
| --> $DIR/unsafe-binders-bare-trait-object-next-solver.rs:19:7 | ||
| | | ||
| LL | fn method(self: &unsafe<'ops> &'a Bar) {} | ||
| | --------------------- the method might not be found because of this arbitrary self type | ||
| ... | ||
| LL | x.method(); | ||
| | ^^^^^^ method not found in `&dyn Foo` | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0038, E0261, E0599, E0782. | ||
| For more information about an error, try `rustc --explain E0038`. |
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.
Uh oh!
There was an error while loading. Please reload this page.