Skip to content

next_solver: Fix Field::OFFSET normalization - #162698

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:next_solver_field_offset_normalization
Open

Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:next_solver_field_offset_normalization

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #162338

With gca_const_items (previously generic_const_args), Field::OFFSET becomes a type-system constant. MIR normalization sends it to the builtin Field candidate, which assumes it's looking at an associated type and panics on ProjectionConst.

The candidate now handles type and const projections separately. I think this is the right place to fix it because the constant reaches the right candidate, but that candidate is missing the const case. I used evaluate_const_and_instantiate_projection_term, the same helper used for ordinary associated constants. Builtin instance resolution selects the default Field::OFFSET body, and the intrinsic gets the offset from the target layout. Constants that are still too generic become rigid aliases; unresolved inference stays ambiguous. The existing Field trait checks still apply.

Added a gca_const_items revision to the offset test, plus generic structs with u8 and u64 fields. The reduced case also has a regression test with MIR output enabled, since a metadata-only check doesn't reach the crash. With the current feature names, the original example compiles now, and the reduced one reports the expected errors without an ICE.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 12, 2026
@rustbot

rustbot commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 76 candidates
  • Random selection from 21 candidates

@nnethercote

Copy link
Copy Markdown
Contributor

This needs a more appropriate reviewer:

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned nnethercote Sep 13, 2026
}
}
ty::AliasTermKind::ProjectionConst { .. } => {
return ecx.evaluate_const_and_instantiate_projection_term(

@lcnr lcnr Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OFFSET on Field. Its default body in core calls the field_offset intrinsic with Self. 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 ProjectionConst arm. It accepts any associated constant on Field, so the code relies on OFFSET being the only one.

I think matching the field_offset lang 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?

@lcnr

lcnr commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Dnreikronos

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 1, 2026
@rust-bors

This comment has been minimized.

@Dnreikronos
Dnreikronos force-pushed the next_solver_field_offset_normalization branch from 37c6119 to 8f0263a Compare October 3, 2026 16:46
@rustbot

rustbot commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: expected projection ty, found ProjectionConst

4 participants