mgca: Register ConstArgHasType when normalizing projection consts#154853
mgca: Register ConstArgHasType when normalizing projection consts#154853lapla-cogito wants to merge 2 commits intorust-lang:mainfrom
ConstArgHasType when normalizing projection consts#154853Conversation
|
|
This comment has been minimized.
This comment has been minimized.
b93677c to
672dfb8
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. |
| assoc_term_own_obligations(selcx, obligation, &mut nested); | ||
| Progress { term: term.instantiate(tcx, args), obligations: nested } | ||
| let instantiated_term: Term<'tcx> = term.instantiate(tcx, args); | ||
| if let Some(ct) = instantiated_term.as_const() { |
There was a problem hiding this comment.
Boxy and I discussed the fix approach and settled on registering a nested goal when normalizing type consts to verify that the normalized term has the type of the type const item. However, this implementation applies the same nested goal to all associated consts, not just type consts. This better expresses the invariant that the normalized result of a const should match its declared type (I think only type consts currently go through this path, but this also guards against future changes).
This comment has been minimized.
This comment has been minimized.
672dfb8 to
90e8301
Compare
fixes #152962
When a
type consthas a value whose type doesn't match the declared type, normalizing a reference to it can trigger CTFE, which in turn runs MIR validation on the const body. The MIR body contains a type mismatch, and since no prior error has been reported at that point, MIR validation fires aspan_bug!. The existingConstArgHasTypecheck inwfcheck::check_type_constdoes catch this at the definition site, but due to query evaluation ordering, the normalization path can reach MIR validation before that check has run.Fix this by registering a
ConstArgHasType(ct, expected_ty)obligation/goal when normalizing projection consts (both trait and inherent), in both the old and new trait solvers. This ensures the type mismatch is reported as an error during normalization itself, which taints the MIR before validation runs.The first commit fixes the original case reported in the issue. The second commit fixes a different ICE pattern reported within the issue (see #152962 (comment)).
r? BoxyUwU