fix: use sub-unification roots in type_var_is_sized - #23464
Merged
ChayimFriedman2 merged 1 commit intoOct 4, 2026
Merged
ChayimFriedman2 merged 1 commit into
ChayimFriedman2 merged 1 commit into
Conversation
When checking whether an inference variable is Sized (used during unsize coercions), ype_var_is_sized previously compared equality-only roots via oot_var. This meant that a Sized obligation on a variable related through subtyping (e.g. from Box::new(y) unsized to Box<dyn Send>) was missed, causing spurious type mismatches. Thread a UseSubtyping flag (modeled on rust-lang/rust#157820) through obligations_for_self_ty, predicate_has_self_ty, and ype_matches_expected_vid. ype_var_is_sized passes Yes (since sizedness is preserved under subtyping), while all closure callers pass No. Fixes rust-lang#23114
ChayimFriedman2
approved these changes
Oct 4, 2026
ChayimFriedman2
marked this pull request as ready for review
October 4, 2026 23:04
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #23114. This fixes a false positive
expected i32, found dyn Senddiagnostic when an inference variable is related to aSizedobligation through subtyping.Previously, sizedness checks only considered inference variables connected through the regular unification table. This could miss obligations connected through subtyping. The fix introduces
UseSubtypingand uses the sub-unification table when checkingSizedobligations. Other callers keep the existing equality-based behavior.This follows the corresponding rustc change in rust-lang/rust#157820,
where
FnCtxt::type_var_is_sized(compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs) usesUseSubtyping::Yes, together with the subtype-aware obligation matching incompiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs. Inrust-analyzer, the corresponding logic is in
InferenceTable::obligations_for_self_tyandtype_matches_expected_vid.Adds one regression test,
coerce_unsize_infer_var_via_default_and_box, based on the first snippet in the issue. It failed before this change and passes now.The second snippet in the issue is not fixed by this PR. It reports the same error with and without this change, so it appears to be a separate problem.