-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
next_solver: Fix Field::OFFSET normalization #162698
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
Dnreikronos
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Dnreikronos:next_solver_field_offset_normalization
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.
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
21 changes: 21 additions & 0 deletions
21
tests/ui/field_representing_types/offset-missing-features-issue-162338.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,21 @@ | ||
| // Request MIR so normalization runs even though the crate has feature errors. | ||
| //@ compile-flags: -Znext-solver --emit=mir | ||
|
|
||
| #![feature(gca_const_items)] | ||
| //~^ ERROR `gca_const_items` requires `gca_min_const_items` to be enabled | ||
| #![allow(incomplete_features)] | ||
|
|
||
| use std::field::{field_of, Field}; | ||
| //~^ ERROR use of unstable library feature `field_projections` | ||
| //~| ERROR use of unstable library feature `field_projections` | ||
|
|
||
| struct Struct { | ||
| b: i64, | ||
| } | ||
|
|
||
| fn project_ref() { | ||
| <field_of!(Struct, b)>::OFFSET; | ||
| //~^ ERROR use of unstable library feature `field_projections` | ||
| //~| ERROR use of unstable library feature `field_projections` | ||
| } | ||
| //~^ ERROR `main` function not found |
58 changes: 58 additions & 0 deletions
58
tests/ui/field_representing_types/offset-missing-features-issue-162338.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,58 @@ | ||
| error[E0658]: use of unstable library feature `field_projections` | ||
| --> $DIR/offset-missing-features-issue-162338.rs:17:6 | ||
| | | ||
| LL | <field_of!(Struct, b)>::OFFSET; | ||
| | ^^^^^^^^ | ||
| | | ||
| = note: see issue #145383 <https://github.com/rust-lang/rust/issues/145383> for more information | ||
| = help: add `#![feature(field_projections)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: `gca_const_items` requires `gca_min_const_items` to be enabled | ||
| --> $DIR/offset-missing-features-issue-162338.rs:4:12 | ||
| | | ||
| LL | #![feature(gca_const_items)] | ||
| | ^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: enable all of these features | ||
|
|
||
| error[E0601]: `main` function not found in crate `offset_missing_features_issue_162338` | ||
| --> $DIR/offset-missing-features-issue-162338.rs:20:2 | ||
| | | ||
| LL | } | ||
| | ^ consider adding a `main` function to `$DIR/offset-missing-features-issue-162338.rs` | ||
|
|
||
| error[E0658]: use of unstable library feature `field_projections` | ||
| --> $DIR/offset-missing-features-issue-162338.rs:8:18 | ||
| | | ||
| LL | use std::field::{field_of, Field}; | ||
| | ^^^^^^^^ | ||
| | | ||
| = note: see issue #145383 <https://github.com/rust-lang/rust/issues/145383> for more information | ||
| = help: add `#![feature(field_projections)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `field_projections` | ||
| --> $DIR/offset-missing-features-issue-162338.rs:8:28 | ||
| | | ||
| LL | use std::field::{field_of, Field}; | ||
| | ^^^^^ | ||
| | | ||
| = note: see issue #145383 <https://github.com/rust-lang/rust/issues/145383> for more information | ||
| = help: add `#![feature(field_projections)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `field_projections` | ||
| --> $DIR/offset-missing-features-issue-162338.rs:17:5 | ||
| | | ||
| LL | <field_of!(Struct, b)>::OFFSET; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #145383 <https://github.com/rust-lang/rust/issues/145383> for more information | ||
| = help: add `#![feature(field_projections)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 6 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0601, E0658. | ||
| For more information about an error, try `rustc --explain E0601`. |
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
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.
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.
hmm, unsure about this 🤔
what is the builtin constant we're evaluating here? also, given this is builtin, should we not match on the lang item here to deal with changes to this trait?
View changes since the review
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.
It's
OFFSETonField. Its default body in core calls thefield_offsetintrinsic withSelf. The evaluator goes through builtin instance resolution, which selects that body, and the intrinsic computes the offset from the layout.I used the existing evaluator because it already handles generic constants and unresolved inference. The part I'd change is the catch-all
ProjectionConstarm. It accepts any associated constant onField, so the code relies onOFFSETbeing the only one.I think matching the
field_offsetlang item here is cleaner. It makes the supported constant explicit, and adding another constant to the trait would require us to decide how to handle it. I'd keep the evaluator and extend the solver's lang-item lookup to support const projections. Does that match what you had in mind?