Check compare_impl_item before resolving free-item consts - #162635
Check compare_impl_item before resolving free-item consts#162635biscuitrescue wants to merge 1 commit into
compare_impl_item before resolving free-item consts#162635Conversation
|
r? @Enselic rustbot has assigned @Enselic. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ice, r=<try> Check `compare_impl_item` before resolving free-item consts
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (6a59b21): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -0.2%, secondary -4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 494.036s -> 493.96s (-0.02%) |
Fixes #161532.
Problem
An associated const whose generic parameter type mismatches between trait declaration and its impl is correctly rejected with code E0053 with the following reproducing code, but doesn't stop compilation and evaluates the impl's
Kanyway and hits an internalscalar_immediate size does not match layoutassertion, since the impl body expected au32, but the args were evaluated against the trait's expectedu16Root cause
resolve_instance_rawcan go on two paths:When
def_idis a trait item,resolve_associated_itemruns and already guards against this exact case by callingcompare_impl_itembefore resolving to the impl's definition.When
def_idis already a concrete item, as happens here when the next-generation trait solver'sevaluate_const_and_instantiate_projection_termresolves the projection directly to the impl'sK,trait_of_assocreturnsNonewhich leads to the free-item branch running instead, which has never checkedcompare_impl_itemat all.Fix
Added the same
compare_impl_itemguard to the free-item branch, gated on the item actually overriding a trait item(
trait_item_def_id().is_some()). This rejects an E0053-tainted impl item before evaluation.Testing
Added
tests/ui/const-generics/mismatched-assoc-const-generic-ice.rsreproducing the original ICE. With the fix, only the E0053 is reported and compilation aborts cleanly.Note: an earlier attempt guarded
confirm_impl_candidate(the old-solver projection-confirmation path) instead that never fired for this since resolution goes through the next-gen solver, and produces a different ICE. Mentioning it here in case it's useful context for reviewers, though it's not a part of this diff.