Skip to content

fix: use sub-unification roots in type_var_is_sized - #23464

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
ABHIRAM-CREATOR06:fix-23114-sized-subtyping
Oct 4, 2026
Merged

ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
ABHIRAM-CREATOR06:fix-23114-sized-subtyping

Conversation

@ABHIRAM-CREATOR06

@ABHIRAM-CREATOR06 ABHIRAM-CREATOR06 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Part of #23114. This fixes a false positive expected i32, found dyn Send diagnostic when an inference variable is related to a Sized obligation 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 UseSubtyping and uses the sub-unification table when checking Sized obligations. 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) uses UseSubtyping::Yes, together with the subtype-aware obligation matching in compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs. In
rust-analyzer, the corresponding logic is in InferenceTable::obligations_for_self_ty and type_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.

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 ChayimFriedman2 left a comment •

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.

Code LGTM, thank you. But next time please ask before claiming an issue someone has already claimed.

View changes since this review

@ChayimFriedman2
ChayimFriedman2 marked this pull request as ready for review October 4, 2026 23:04
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2026
@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Oct 4, 2026
Merged via the queue into rust-lang:master with commit 65ac641 Oct 4, 2026
20 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants