You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of rust-lang#122412 - WaffleLapkin:if-we-ask-question-mark-operator-to-not-screw-with-inference-will-it-obey, r=<try>
Stop skewing inference in ?'s desugaring
**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):
```rust
// 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:
```rust
// previously: ok (never type spontaneous decay skews inference, `T = ()`)
// with this pr: can't infer the type for `T`
Err(())?;
```
Fixesrust-lang#51125Closesrust-lang#39216
0 commit comments