Skip to content

Stop skewing inference in ?'s desugaring#122412

Closed
WaffleLapkin wants to merge 4 commits intorust-lang:masterfrom
WaffleLapkin:if-we-ask-question-mark-operator-to-not-screw-with-inference-will-it-obey
Closed

Stop skewing inference in ?'s desugaring#122412
WaffleLapkin wants to merge 4 commits intorust-lang:masterfrom
WaffleLapkin:if-we-ask-question-mark-operator-to-not-screw-with-inference-will-it-obey

Conversation

@WaffleLapkin
Copy link
Copy Markdown
Member

NB: this is a breaking change (although arguably a bug fix) and as such shouldn't be taken lightly.

This changes expr?'s desugaring like so (simplified, see code for more info):

// old
match expr {
    Ok(val) => val,
    Err(err) => return Err(err),
}

// new
match expr {
    Ok(val) => val,
    Err(err) => core::convert::absurd(return Err(err)),
}

// core::convert
pub const fn absurd<T>(x: !) -> T { x }

This prevents ! from the return from skewing inference:

// previously: ok (never type spontaneous decay skews inference, `T = ()`)
// with this pr: can't infer the type for `T`
Err(())?;

Fixes #51125
Closes #39216

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

Labels

A-maybe-future-edition Something we may consider for a future edition. F-never_type `#![feature(never_type)]` needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defaulted unit types no longer error out (regression?) Tracking issue for future-incompatibility lint resolve_trait_on_defaulted_unit