Skip to content

consider subtyping when checking if an infer var is sized#157820

Open
WaffleLapkin wants to merge 1 commit into
rust-lang:mainfrom
WaffleLapkin:sized-infer-sub
Open

consider subtyping when checking if an infer var is sized#157820
WaffleLapkin wants to merge 1 commit into
rust-lang:mainfrom
WaffleLapkin:sized-infer-sub

Conversation

@WaffleLapkin

@WaffleLapkin WaffleLapkin commented Jun 12, 2026

Copy link
Copy Markdown
Member

That is, when checking if an inference variable (say ?0) is sized, with this PR, we now check for obligations like ?1: Sized, where either exists X. (?0 <: X || ?0 :> X) && (?1 <: X || ?1 :> X) holds (previously we were checking for ?0 = ?1). This is sound because subtyping cannot change sized-ness.

This fixes the 4-th point/issue from #155924. Specifically, it makes this code compile:

fn blah(e: !) {
    let source = Box::new(e);
    let _: Box<dyn Send> = source;
}

This also fixes tests/ui/impl-trait/unsized_coercion.rs on new solver, although I'm not exactly sure why.

r? types

@WaffleLapkin WaffleLapkin added F-never_type `#![feature(never_type)]` T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jun 12, 2026
@rustbot

rustbot commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

changes to inspect_obligations.rs

cc @lcnr

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 12, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs Outdated
@rust-log-analyzer

This comment was marked as off-topic.

Comment on lines +23 to +24
/// Use subtyping. [`FnCtxt::obligations_for_self_ty`] will return obligations
/// where the self type is a subtype or a supertype of the provided vid.

@WaffleLapkin WaffleLapkin Jun 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite true.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-never_type `#![feature(never_type)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants