Skip to content

Commit 6e98ed9

Browse files
authored
Rollup merge of rust-lang#53395 - varkor:__Nonexhaustive-to-non_exhaustive, r=shepmaster
Use #[non_exhaustive] on internal enums This replaces `__Nonexhaustive` variants (and variants thereof) with `#[non_exhaustive]`. These were mostly unstable previously, with the exception of the `cloudabi` enums and `Level` in proc_macro: these were `#[doc(hidden)]`, so clearly intended not to be used directly. It should be safe to replace all of these.
2 parents 0c9e0e3 + 27f2a84 commit 6e98ed9

File tree

10 files changed

+15
-56
lines changed

10 files changed

+15
-56
lines changed

src/doc/unstable-book/src/library-features/future-atomic-orderings.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/doc/unstable-book/src/library-features/io-error-internals.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
#![feature(const_slice_len)]
121121
#![feature(const_str_as_bytes)]
122122
#![feature(const_str_len)]
123+
#![feature(non_exhaustive)]
123124

124125
#[prelude_import]
125126
#[allow(unused)]

src/libcore/sync/atomic.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
185185
/// [nomicon]: ../../../nomicon/atomics.html
186186
#[stable(feature = "rust1", since = "1.0.0")]
187187
#[derive(Copy, Clone, Debug)]
188+
#[non_exhaustive]
188189
pub enum Ordering {
189190
/// No ordering constraints, only atomic operations.
190191
///
@@ -256,10 +257,6 @@ pub enum Ordering {
256257
/// [`AcqRel`]: https://llvm.org/docs/Atomics.html#acquirerelease
257258
#[stable(feature = "rust1", since = "1.0.0")]
258259
SeqCst,
259-
// Prevent exhaustive matching to allow for future extension
260-
#[doc(hidden)]
261-
#[unstable(feature = "future_atomic_orderings", issue = "0")]
262-
__Nonexhaustive,
263260
}
264261

265262
/// An [`AtomicBool`] initialized to `false`.
@@ -1954,7 +1951,6 @@ fn strongest_failure_ordering(order: Ordering) -> Ordering {
19541951
SeqCst => SeqCst,
19551952
Acquire => Acquire,
19561953
AcqRel => Acquire,
1957-
__Nonexhaustive => __Nonexhaustive,
19581954
}
19591955
}
19601956

@@ -1966,7 +1962,6 @@ unsafe fn atomic_store<T>(dst: *mut T, val: T, order: Ordering) {
19661962
SeqCst => intrinsics::atomic_store(dst, val),
19671963
Acquire => panic!("there is no such thing as an acquire store"),
19681964
AcqRel => panic!("there is no such thing as an acquire/release store"),
1969-
__Nonexhaustive => panic!("invalid memory ordering"),
19701965
}
19711966
}
19721967

@@ -1978,7 +1973,6 @@ unsafe fn atomic_load<T>(dst: *const T, order: Ordering) -> T {
19781973
SeqCst => intrinsics::atomic_load(dst),
19791974
Release => panic!("there is no such thing as a release load"),
19801975
AcqRel => panic!("there is no such thing as an acquire/release load"),
1981-
__Nonexhaustive => panic!("invalid memory ordering"),
19821976
}
19831977
}
19841978

@@ -1991,7 +1985,6 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
19911985
AcqRel => intrinsics::atomic_xchg_acqrel(dst, val),
19921986
Relaxed => intrinsics::atomic_xchg_relaxed(dst, val),
19931987
SeqCst => intrinsics::atomic_xchg(dst, val),
1994-
__Nonexhaustive => panic!("invalid memory ordering"),
19951988
}
19961989
}
19971990

@@ -2004,7 +1997,6 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
20041997
AcqRel => intrinsics::atomic_xadd_acqrel(dst, val),
20051998
Relaxed => intrinsics::atomic_xadd_relaxed(dst, val),
20061999
SeqCst => intrinsics::atomic_xadd(dst, val),
2007-
__Nonexhaustive => panic!("invalid memory ordering"),
20082000
}
20092001
}
20102002

@@ -2017,7 +2009,6 @@ unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
20172009
AcqRel => intrinsics::atomic_xsub_acqrel(dst, val),
20182010
Relaxed => intrinsics::atomic_xsub_relaxed(dst, val),
20192011
SeqCst => intrinsics::atomic_xsub(dst, val),
2020-
__Nonexhaustive => panic!("invalid memory ordering"),
20212012
}
20222013
}
20232014

@@ -2039,8 +2030,6 @@ unsafe fn atomic_compare_exchange<T>(dst: *mut T,
20392030
(AcqRel, Relaxed) => intrinsics::atomic_cxchg_acqrel_failrelaxed(dst, old, new),
20402031
(SeqCst, Relaxed) => intrinsics::atomic_cxchg_failrelaxed(dst, old, new),
20412032
(SeqCst, Acquire) => intrinsics::atomic_cxchg_failacq(dst, old, new),
2042-
(__Nonexhaustive, _) => panic!("invalid memory ordering"),
2043-
(_, __Nonexhaustive) => panic!("invalid memory ordering"),
20442033
(_, AcqRel) => panic!("there is no such thing as an acquire/release failure ordering"),
20452034
(_, Release) => panic!("there is no such thing as a release failure ordering"),
20462035
_ => panic!("a failure ordering can't be stronger than a success ordering"),
@@ -2065,8 +2054,6 @@ unsafe fn atomic_compare_exchange_weak<T>(dst: *mut T,
20652054
(AcqRel, Relaxed) => intrinsics::atomic_cxchgweak_acqrel_failrelaxed(dst, old, new),
20662055
(SeqCst, Relaxed) => intrinsics::atomic_cxchgweak_failrelaxed(dst, old, new),
20672056
(SeqCst, Acquire) => intrinsics::atomic_cxchgweak_failacq(dst, old, new),
2068-
(__Nonexhaustive, _) => panic!("invalid memory ordering"),
2069-
(_, __Nonexhaustive) => panic!("invalid memory ordering"),
20702057
(_, AcqRel) => panic!("there is no such thing as an acquire/release failure ordering"),
20712058
(_, Release) => panic!("there is no such thing as a release failure ordering"),
20722059
_ => panic!("a failure ordering can't be stronger than a success ordering"),
@@ -2082,7 +2069,6 @@ unsafe fn atomic_and<T>(dst: *mut T, val: T, order: Ordering) -> T {
20822069
AcqRel => intrinsics::atomic_and_acqrel(dst, val),
20832070
Relaxed => intrinsics::atomic_and_relaxed(dst, val),
20842071
SeqCst => intrinsics::atomic_and(dst, val),
2085-
__Nonexhaustive => panic!("invalid memory ordering"),
20862072
}
20872073
}
20882074

@@ -2094,7 +2080,6 @@ unsafe fn atomic_nand<T>(dst: *mut T, val: T, order: Ordering) -> T {
20942080
AcqRel => intrinsics::atomic_nand_acqrel(dst, val),
20952081
Relaxed => intrinsics::atomic_nand_relaxed(dst, val),
20962082
SeqCst => intrinsics::atomic_nand(dst, val),
2097-
__Nonexhaustive => panic!("invalid memory ordering"),
20982083
}
20992084
}
21002085

@@ -2106,7 +2091,6 @@ unsafe fn atomic_or<T>(dst: *mut T, val: T, order: Ordering) -> T {
21062091
AcqRel => intrinsics::atomic_or_acqrel(dst, val),
21072092
Relaxed => intrinsics::atomic_or_relaxed(dst, val),
21082093
SeqCst => intrinsics::atomic_or(dst, val),
2109-
__Nonexhaustive => panic!("invalid memory ordering"),
21102094
}
21112095
}
21122096

@@ -2118,7 +2102,6 @@ unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T {
21182102
AcqRel => intrinsics::atomic_xor_acqrel(dst, val),
21192103
Relaxed => intrinsics::atomic_xor_relaxed(dst, val),
21202104
SeqCst => intrinsics::atomic_xor(dst, val),
2121-
__Nonexhaustive => panic!("invalid memory ordering"),
21222105
}
21232106
}
21242107

@@ -2131,7 +2114,6 @@ unsafe fn atomic_max<T>(dst: *mut T, val: T, order: Ordering) -> T {
21312114
AcqRel => intrinsics::atomic_max_acqrel(dst, val),
21322115
Relaxed => intrinsics::atomic_max_relaxed(dst, val),
21332116
SeqCst => intrinsics::atomic_max(dst, val),
2134-
__Nonexhaustive => panic!("invalid memory ordering"),
21352117
}
21362118
}
21372119

@@ -2144,7 +2126,6 @@ unsafe fn atomic_min<T>(dst: *mut T, val: T, order: Ordering) -> T {
21442126
AcqRel => intrinsics::atomic_min_acqrel(dst, val),
21452127
Relaxed => intrinsics::atomic_min_relaxed(dst, val),
21462128
SeqCst => intrinsics::atomic_min(dst, val),
2147-
__Nonexhaustive => panic!("invalid memory ordering"),
21482129
}
21492130
}
21502131

@@ -2157,7 +2138,6 @@ unsafe fn atomic_umax<T>(dst: *mut T, val: T, order: Ordering) -> T {
21572138
AcqRel => intrinsics::atomic_umax_acqrel(dst, val),
21582139
Relaxed => intrinsics::atomic_umax_relaxed(dst, val),
21592140
SeqCst => intrinsics::atomic_umax(dst, val),
2160-
__Nonexhaustive => panic!("invalid memory ordering"),
21612141
}
21622142
}
21632143

@@ -2170,7 +2150,6 @@ unsafe fn atomic_umin<T>(dst: *mut T, val: T, order: Ordering) -> T {
21702150
AcqRel => intrinsics::atomic_umin_acqrel(dst, val),
21712151
Relaxed => intrinsics::atomic_umin_relaxed(dst, val),
21722152
SeqCst => intrinsics::atomic_umin(dst, val),
2173-
__Nonexhaustive => panic!("invalid memory ordering"),
21742153
}
21752154
}
21762155

@@ -2260,7 +2239,6 @@ pub fn fence(order: Ordering) {
22602239
AcqRel => intrinsics::atomic_fence_acqrel(),
22612240
SeqCst => intrinsics::atomic_fence(),
22622241
Relaxed => panic!("there is no such thing as a relaxed fence"),
2263-
__Nonexhaustive => panic!("invalid memory ordering"),
22642242
}
22652243
}
22662244
}
@@ -2350,7 +2328,6 @@ pub fn compiler_fence(order: Ordering) {
23502328
AcqRel => intrinsics::atomic_singlethreadfence_acqrel(),
23512329
SeqCst => intrinsics::atomic_singlethreadfence(),
23522330
Relaxed => panic!("there is no such thing as a relaxed compiler fence"),
2353-
__Nonexhaustive => panic!("invalid memory ordering"),
23542331
}
23552332
}
23562333
}

src/libproc_macro/diagnostic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use syntax_pos::MultiSpan;
1616
/// An enum representing a diagnostic level.
1717
#[unstable(feature = "proc_macro_diagnostic", issue = "38356")]
1818
#[derive(Copy, Clone, Debug)]
19+
#[non_exhaustive]
1920
pub enum Level {
2021
/// An error.
2122
Error,
@@ -25,8 +26,6 @@ pub enum Level {
2526
Note,
2627
/// A help message.
2728
Help,
28-
#[doc(hidden)]
29-
__Nonexhaustive,
3029
}
3130

3231
/// A structure representing a diagnostic message and associated children

src/libproc_macro/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![feature(staged_api)]
3737
#![feature(lang_items)]
3838
#![feature(optin_builtin_traits)]
39+
#![feature(non_exhaustive)]
3940

4041
#![recursion_limit="256"]
4142

src/libproc_macro/rustc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ impl Level {
278278
Level::Warning => errors::Level::Warning,
279279
Level::Note => errors::Level::Note,
280280
Level::Help => errors::Level::Help,
281-
Level::__Nonexhaustive => unreachable!("Level::__Nonexhaustive"),
282281
}
283282
}
284283
}

src/libstd/io/error.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct Custom {
9797
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
9898
#[stable(feature = "rust1", since = "1.0.0")]
9999
#[allow(deprecated)]
100+
#[non_exhaustive]
100101
pub enum ErrorKind {
101102
/// An entity was not found, often a file.
102103
#[stable(feature = "rust1", since = "1.0.0")]
@@ -180,15 +181,6 @@ pub enum ErrorKind {
180181
/// read.
181182
#[stable(feature = "read_exact", since = "1.6.0")]
182183
UnexpectedEof,
183-
184-
/// A marker variant that tells the compiler that users of this enum cannot
185-
/// match it exhaustively.
186-
#[unstable(feature = "io_error_internals",
187-
reason = "better expressed through extensible enums that this \
188-
enum cannot be exhaustively matched against",
189-
issue = "0")]
190-
#[doc(hidden)]
191-
__Nonexhaustive,
192184
}
193185

194186
impl ErrorKind {
@@ -212,7 +204,6 @@ impl ErrorKind {
212204
ErrorKind::Interrupted => "operation interrupted",
213205
ErrorKind::Other => "other os error",
214206
ErrorKind::UnexpectedEof => "unexpected end of file",
215-
ErrorKind::__Nonexhaustive => unreachable!()
216207
}
217208
}
218209
}

src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
#![feature(doc_keyword)]
312312
#![feature(panic_info_message)]
313313
#![feature(panic_implementation)]
314+
#![feature(non_exhaustive)]
314315

315316
#![default_lib_allocator]
316317

src/libstd/sys/cloudabi/abi/cloudabi.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ include!("bitflags.rs");
121121
/// File or memory access pattern advisory information.
122122
#[repr(u8)]
123123
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
124+
#[non_exhaustive]
124125
pub enum advice {
125126
/// The application expects that it will not access the
126127
/// specified data in the near future.
@@ -140,12 +141,12 @@ pub enum advice {
140141
/// The application expects to access the specified data
141142
/// in the near future.
142143
WILLNEED = 6,
143-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
144144
}
145145

146146
/// Enumeration describing the kind of value stored in [`auxv`](struct.auxv.html).
147147
#[repr(u32)]
148148
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
149+
#[non_exhaustive]
149150
pub enum auxtype {
150151
/// Base address of the binary argument data provided to
151152
/// [`proc_exec()`](fn.proc_exec.html).
@@ -210,12 +211,12 @@ pub enum auxtype {
210211
SYSINFO_EHDR = 262,
211212
/// Thread ID of the initial thread of the process.
212213
TID = 261,
213-
#[doc(hidden)] _NonExhaustive = -1 as isize as u32,
214214
}
215215

216216
/// Identifiers for clocks.
217217
#[repr(u32)]
218218
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
219+
#[non_exhaustive]
219220
pub enum clockid {
220221
/// The system-wide monotonic clock, which is defined as a
221222
/// clock measuring real time, whose value cannot be
@@ -232,7 +233,6 @@ pub enum clockid {
232233
REALTIME = 3,
233234
/// The CPU-time clock associated with the current thread.
234235
THREAD_CPUTIME_ID = 4,
235-
#[doc(hidden)] _NonExhaustive = -1 as isize as u32,
236236
}
237237

238238
/// A userspace condition variable.
@@ -267,6 +267,7 @@ pub const DIRCOOKIE_START: dircookie = dircookie(0);
267267
/// exclusively or merely provided for alignment with POSIX.
268268
#[repr(u16)]
269269
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
270+
#[non_exhaustive]
270271
pub enum errno {
271272
/// No error occurred. System call completed successfully.
272273
SUCCESS = 0,
@@ -422,7 +423,6 @@ pub enum errno {
422423
XDEV = 75,
423424
/// Extension: Capabilities insufficient.
424425
NOTCAPABLE = 76,
425-
#[doc(hidden)] _NonExhaustive = -1 as isize as u16,
426426
}
427427

428428
bitflags! {
@@ -438,6 +438,7 @@ bitflags! {
438438
/// Type of a subscription to an event or its occurrence.
439439
#[repr(u8)]
440440
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
441+
#[non_exhaustive]
441442
pub enum eventtype {
442443
/// The time value of clock [`subscription.union.clock.clock_id`](struct.subscription_clock.html#structfield.clock_id)
443444
/// has reached timestamp [`subscription.union.clock.timeout`](struct.subscription_clock.html#structfield.timeout).
@@ -463,7 +464,6 @@ pub enum eventtype {
463464
/// The process associated with process descriptor
464465
/// [`subscription.union.proc_terminate.fd`](struct.subscription_proc_terminate.html#structfield.fd) has terminated.
465466
PROC_TERMINATE = 7,
466-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
467467
}
468468

469469
/// Exit code generated by a process when exiting.
@@ -530,6 +530,7 @@ pub type filesize = u64;
530530
/// The type of a file descriptor or file.
531531
#[repr(u8)]
532532
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
533+
#[non_exhaustive]
533534
pub enum filetype {
534535
/// The type of the file descriptor or file is unknown or
535536
/// is different from any of the other types specified.
@@ -558,7 +559,6 @@ pub enum filetype {
558559
SOCKET_STREAM = 130,
559560
/// The file refers to a symbolic link inode.
560561
SYMBOLIC_LINK = 144,
561-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
562562
}
563563

564564
bitflags! {
@@ -847,12 +847,12 @@ bitflags! {
847847
/// memory.
848848
#[repr(u8)]
849849
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
850+
#[non_exhaustive]
850851
pub enum scope {
851852
/// The object is stored in private memory.
852853
PRIVATE = 4,
853854
/// The object is stored in shared memory.
854855
SHARED = 8,
855-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
856856
}
857857

858858
bitflags! {
@@ -878,6 +878,7 @@ bitflags! {
878878
/// Signal condition.
879879
#[repr(u8)]
880880
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
881+
#[non_exhaustive]
881882
pub enum signal {
882883
/// Process abort signal.
883884
///
@@ -983,7 +984,6 @@ pub enum signal {
983984
///
984985
/// Action: Terminates the process.
985986
XFSZ = 26,
986-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
987987
}
988988

989989
bitflags! {
@@ -1049,14 +1049,14 @@ pub type userdata = u64;
10491049
/// should be set.
10501050
#[repr(u8)]
10511051
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1052+
#[non_exhaustive]
10521053
pub enum whence {
10531054
/// Seek relative to current position.
10541055
CUR = 1,
10551056
/// Seek relative to end-of-file.
10561057
END = 2,
10571058
/// Seek relative to start-of-file.
10581059
SET = 3,
1059-
#[doc(hidden)] _NonExhaustive = -1 as isize as u8,
10601060
}
10611061

10621062
/// Auxiliary vector entry.

0 commit comments

Comments
 (0)