1
Fork 0

Rollup merge of #122843 - WaffleLapkin:semicolon-vs-the-never, r=compiler-errors

Add a never type option to make diverging blocks `()`

More experiments for ~~the blood god~~ T-lang!

Usage example:
```rust
 #![allow(internal_features)]
 #![feature(never_type, rustc_attrs)]
 #![rustc_never_type_options(diverging_block_default = "unit")]

fn main() {
    let _: u8 = { //~ error: expected `u8`, found `()`
        return;
    };
}
```

r? compiler-errors

I'm not sure how I feel about parsing the attribute every time we create `FnCtxt`. There must be a better way to do this, right?
This commit is contained in:
Matthias Krüger 2024-03-22 01:07:33 +01:00 committed by GitHub
commit b469a6dd9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 111 additions and 41 deletions

View file

@ -597,9 +597,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
rustc_attr!(
rustc_never_type_mode, Normal, template!(NameValueStr: "fallback_to_unit|fallback_to_niko|fallback_to_never|no_fallback"), ErrorFollowing,
rustc_never_type_options,
Normal,
template!(List: r#"/*opt*/ fallback = "unit|niko|never|no""#),
ErrorFollowing,
EncodeCrossCrate::No,
"`rustc_never_type_fallback` is used to experiment with never type fallback and work on \
"`rustc_never_type_options` is used to experiment with never type fallback and work on \
never type stabilization, and will never be stable"
),