Skip to content

Commit 959b6e3

Browse files
authoredOct 25, 2019
Rollup merge of #64639 - davidtwco:rfc-2008-stabilization, r=Centril
Stabilize `#[non_exhaustive]` (RFC 2008) Fixes #44109. This pull request stabilizes the `#[non_exhaustive]` attribute, which is used to indicate that a type will have more fields / variants added in the future. It can be applied to `struct`s, `enum`s and `enum` variants. See #44109 (comment) for the stabilization report. r? @Centril
2 parents 85943fd + e0590ea commit 959b6e3

36 files changed

+30
-155
lines changed
 

‎src/doc/unstable-book/src/language-features/non-exhaustive.md

-76
This file was deleted.

‎src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
#![feature(hexagon_target_feature)]
122122
#![feature(const_int_conversion)]
123123
#![feature(const_transmute)]
124-
#![feature(non_exhaustive)]
124+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
125125
#![feature(structural_match)]
126126
#![feature(abi_unadjusted)]
127127
#![feature(adx_target_feature)]

‎src/libproc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#![feature(extern_types)]
2626
#![feature(in_band_lifetimes)]
2727
#![feature(optin_builtin_traits)]
28-
#![feature(non_exhaustive)]
28+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
2929
#![feature(rustc_attrs)]
3030
#![feature(specialization)]
3131

‎src/librustc/error_codes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2105,8 +2105,6 @@ on something other than a struct or enum.
21052105
Examples of erroneous code:
21062106
21072107
```compile_fail,E0701
2108-
# #![feature(non_exhaustive)]
2109-
21102108
#[non_exhaustive]
21112109
trait Foo { }
21122110
```

‎src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#![feature(overlapping_marker_traits)]
4242
#![feature(extern_types)]
4343
#![feature(nll)]
44-
#![feature(non_exhaustive)]
44+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
4545
#![feature(optin_builtin_traits)]
4646
#![feature(option_expect_none)]
4747
#![feature(range_is_empty)]

‎src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
#![feature(needs_panic_runtime)]
284284
#![feature(never_type)]
285285
#![feature(nll)]
286-
#![feature(non_exhaustive)]
286+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
287287
#![feature(on_unimplemented)]
288288
#![feature(optin_builtin_traits)]
289289
#![feature(panic_info_message)]

‎src/libsyntax/feature_gate/accepted.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ declare_features! (
245245
(accepted, bind_by_move_pattern_guards, "1.39.0", Some(15287), None),
246246
/// Allows attributes in formal function parameters.
247247
(accepted, param_attrs, "1.39.0", Some(60406), None),
248-
// Allows macro invocations in `extern {}` blocks.
248+
/// Allows macro invocations in `extern {}` blocks.
249249
(accepted, macros_in_extern, "1.40.0", Some(49476), None),
250+
/// Allows future-proofing enums/structs with the `#[non_exhaustive]` attribute (RFC 2008).
251+
(accepted, non_exhaustive, "1.40.0", Some(44109), None),
250252

251253
// -------------------------------------------------------------------------
252254
// feature-group-end: accepted features

‎src/libsyntax/feature_gate/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,6 @@ declare_features! (
383383
/// Allows `#[doc(include = "some-file")]`.
384384
(active, external_doc, "1.22.0", Some(44732), None),
385385

386-
/// Allows future-proofing enums/structs with the `#[non_exhaustive]` attribute (RFC 2008).
387-
(active, non_exhaustive, "1.22.0", Some(44109), None),
388-
389386
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
390387
(active, crate_visibility_modifier, "1.23.0", Some(53120), None),
391388

‎src/libsyntax/feature_gate/builtin_attrs.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
252252
ungated!(path, Normal, template!(NameValueStr: "file")),
253253
ungated!(no_std, CrateLevel, template!(Word)),
254254
ungated!(no_implicit_prelude, Normal, template!(Word)),
255+
ungated!(non_exhaustive, Whitelisted, template!(Word)),
255256

256257
// Runtime
257258
ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")),
@@ -314,9 +315,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
314315
test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
315316
"custom test frameworks are an unstable feature",
316317
),
317-
318-
// RFC #2008
319-
gated!(non_exhaustive, Whitelisted, template!(Word), experimental!(non_exhaustive)),
320318
// RFC #1268
321319
gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)),
322320
gated!(

‎src/libsyntax_pos/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![feature(const_fn)]
1010
#![feature(crate_visibility_modifier)]
1111
#![feature(nll)]
12-
#![feature(non_exhaustive)]
12+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
1313
#![feature(optin_builtin_traits)]
1414
#![feature(rustc_attrs)]
1515
#![cfg_attr(bootstrap, feature(proc_macro_hygiene))]

‎src/test/ui/feature-gates/feature-gate-non_exhaustive.rs

-10
This file was deleted.

‎src/test/ui/feature-gates/feature-gate-non_exhaustive.stderr

-12
This file was deleted.

‎src/test/ui/rfc-2008-non-exhaustive/auxiliary/enums.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![crate_type = "rlib"]
2-
#![feature(non_exhaustive)]
32

43
#[non_exhaustive]
54
pub enum NonExhaustiveEnum {

‎src/test/ui/rfc-2008-non-exhaustive/auxiliary/structs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(non_exhaustive)]
2-
31
#[non_exhaustive]
42
pub struct NormalStruct {
53
pub first_field: u16,

‎src/test/ui/rfc-2008-non-exhaustive/auxiliary/variants.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![crate_type = "rlib"]
2-
#![feature(non_exhaustive)]
32

43
pub enum NonExhaustiveVariants {
54
#[non_exhaustive] Unit,

‎src/test/ui/rfc-2008-non-exhaustive/enum_same_crate.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// run-pass
22

3-
#![feature(non_exhaustive)]
4-
53
#[non_exhaustive]
64
pub enum NonExhaustiveEnum {
75
Unit,

‎src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/auxiliary/types.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(non_exhaustive)]
2-
31
#[non_exhaustive]
42
#[repr(C)]
53
pub enum NonExhaustiveEnum {

‎src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/same_crate_proper.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// check-pass
2-
#![feature(non_exhaustive)]
32
#![deny(improper_ctypes)]
43

54
// This test checks that non-exhaustive types with `#[repr(C)]` are considered proper within

‎src/test/ui/rfc-2008-non-exhaustive/invalid-attribute.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(non_exhaustive)]
2-
31
#[non_exhaustive(anything)]
42
//~^ ERROR malformed `non_exhaustive` attribute
53
struct Foo;

‎src/test/ui/rfc-2008-non-exhaustive/invalid-attribute.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: malformed `non_exhaustive` attribute input
2-
--> $DIR/invalid-attribute.rs:3:1
2+
--> $DIR/invalid-attribute.rs:1:1
33
|
44
LL | #[non_exhaustive(anything)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[non_exhaustive]`
66

77
error[E0701]: attribute can only be applied to a struct or enum
8-
--> $DIR/invalid-attribute.rs:7:1
8+
--> $DIR/invalid-attribute.rs:5:1
99
|
1010
LL | #[non_exhaustive]
1111
| ^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL | trait Bar { }
1414
| ------------- not a struct or enum
1515

1616
error[E0701]: attribute can only be applied to a struct or enum
17-
--> $DIR/invalid-attribute.rs:11:1
17+
--> $DIR/invalid-attribute.rs:9:1
1818
|
1919
LL | #[non_exhaustive]
2020
| ^^^^^^^^^^^^^^^^^

‎src/test/ui/rfc-2008-non-exhaustive/struct.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0603]: tuple struct constructor `TupleStruct` is private
1616
LL | let ts_explicit = structs::TupleStruct(640, 480);
1717
| ^^^^^^^^^^^
1818
|
19-
::: $DIR/auxiliary/structs.rs:13:24
19+
::: $DIR/auxiliary/structs.rs:11:24
2020
|
2121
LL | pub struct TupleStruct(pub u16, pub u16);
2222
| ---------------- a constructor is private if any of the fields is private

‎src/test/ui/rfc-2008-non-exhaustive/structs_same_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// run-pass
22

33
#![allow(unused_variables)]
4-
#![feature(non_exhaustive)]
54

65
#[non_exhaustive]
76
pub struct NormalStruct {

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/auxiliary/uninhabited.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![crate_type = "rlib"]
22
#![feature(never_type)]
3-
#![feature(non_exhaustive)]
43

54
#[non_exhaustive]
65
pub enum UninhabitedEnum {

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/coercions_same_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(never_type)]
2-
#![feature(non_exhaustive)]
32

43
#[non_exhaustive]
54
pub enum UninhabitedEnum {

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/coercions_same_crate.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/coercions_same_crate.rs:31:5
2+
--> $DIR/coercions_same_crate.rs:30:5
33
|
44
LL | fn cannot_coerce_empty_enum_to_anything(x: UninhabitedEnum) -> A {
55
| - expected `A` because of return type
@@ -10,7 +10,7 @@ LL | x
1010
found type `UninhabitedEnum`
1111

1212
error[E0308]: mismatched types
13-
--> $DIR/coercions_same_crate.rs:35:5
13+
--> $DIR/coercions_same_crate.rs:34:5
1414
|
1515
LL | fn cannot_coerce_empty_tuple_struct_to_anything(x: UninhabitedTupleStruct) -> A {
1616
| - expected `A` because of return type
@@ -21,7 +21,7 @@ LL | x
2121
found type `UninhabitedTupleStruct`
2222

2323
error[E0308]: mismatched types
24-
--> $DIR/coercions_same_crate.rs:39:5
24+
--> $DIR/coercions_same_crate.rs:38:5
2525
|
2626
LL | fn cannot_coerce_empty_struct_to_anything(x: UninhabitedStruct) -> A {
2727
| - expected `A` because of return type
@@ -32,7 +32,7 @@ LL | x
3232
found type `UninhabitedStruct`
3333

3434
error[E0308]: mismatched types
35-
--> $DIR/coercions_same_crate.rs:43:5
35+
--> $DIR/coercions_same_crate.rs:42:5
3636
|
3737
LL | fn cannot_coerce_enum_with_empty_variants_to_anything(x: UninhabitedVariants) -> A {
3838
| - expected `A` because of return type

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(never_type)]
2-
#![feature(non_exhaustive)]
32

43
#[non_exhaustive]
54
pub enum UninhabitedEnum {

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_same_crate.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedEnum` of type `IndirectUninhabitedEnum` is not handled
2-
--> $DIR/indirect_match_same_crate.rs:35:11
2+
--> $DIR/indirect_match_same_crate.rs:34:11
33
|
44
LL | pub struct IndirectUninhabitedEnum(UninhabitedEnum);
55
| ----------------------------------------------------
@@ -13,7 +13,7 @@ LL | match x {}
1313
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
1414

1515
error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedStruct` of type `IndirectUninhabitedStruct` is not handled
16-
--> $DIR/indirect_match_same_crate.rs:39:11
16+
--> $DIR/indirect_match_same_crate.rs:38:11
1717
|
1818
LL | pub struct IndirectUninhabitedStruct(UninhabitedStruct);
1919
| --------------------------------------------------------
@@ -27,7 +27,7 @@ LL | match x {}
2727
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
2828

2929
error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedTupleStruct` of type `IndirectUninhabitedTupleStruct` is not handled
30-
--> $DIR/indirect_match_same_crate.rs:43:11
30+
--> $DIR/indirect_match_same_crate.rs:42:11
3131
|
3232
LL | pub struct IndirectUninhabitedTupleStruct(UninhabitedTupleStruct);
3333
| ------------------------------------------------------------------
@@ -41,7 +41,7 @@ LL | match x {}
4141
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
4242

4343
error[E0004]: non-exhaustive patterns: pattern `IndirectUninhabitedVariants` of type `IndirectUninhabitedVariants` is not handled
44-
--> $DIR/indirect_match_same_crate.rs:49:11
44+
--> $DIR/indirect_match_same_crate.rs:48:11
4545
|
4646
LL | pub struct IndirectUninhabitedVariants(UninhabitedVariants);
4747
| ------------------------------------------------------------

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![deny(unreachable_patterns)]
44
#![feature(exhaustive_patterns)]
55
#![feature(never_type)]
6-
#![feature(non_exhaustive)]
76

87
#[non_exhaustive]
98
pub enum UninhabitedEnum {

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// aux-build:uninhabited.rs
22
#![deny(unreachable_patterns)]
33
#![feature(never_type)]
4-
#![feature(non_exhaustive)]
54

65
extern crate uninhabited;
76

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/issue-65157-repeated-match-arm.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unreachable pattern
2-
--> $DIR/issue-65157-repeated-match-arm.rs:16:9
2+
--> $DIR/issue-65157-repeated-match-arm.rs:15:9
33
|
44
LL | PartiallyInhabitedVariants::Struct { .. } => {},
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

‎src/test/ui/rfc-2008-non-exhaustive/uninhabited/match_same_crate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(never_type)]
2-
#![feature(non_exhaustive)]
32

43
#[non_exhaustive]
54
pub enum UninhabitedEnum {

0 commit comments

Comments
 (0)
Please sign in to comment.