next_solver: Fix Field::OFFSET normalization - #162698
Dnreikronos wants to merge 1 commit into
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This needs a more appropriate reviewer: r? @lcnr |
| } | ||
| } | ||
| ty::AliasTermKind::ProjectionConst { .. } => { | ||
| return ecx.evaluate_const_and_instantiate_projection_term( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
37c6119 to
8f0263a
Compare
|
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. |
Fixes #162338
With
gca_const_items(previouslygeneric_const_args),Field::OFFSETbecomes a type-system constant. MIR normalization sends it to the builtinFieldcandidate, which assumes it's looking at an associated type and panics onProjectionConst.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 defaultField::OFFSETbody, and the intrinsic gets the offset from the target layout. Constants that are still too generic become rigid aliases; unresolved inference stays ambiguous. The existingFieldtrait checks still apply.Added a
gca_const_itemsrevision to the offset test, plus generic structs withu8andu64fields. 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.