Skip to content

Commit 9bf5c5b

Browse files
author
Clar Charr
committed
Use #[non_exhaustive] when possible.
This gets rid of the `future_atomic_orderings` and `io_error_internals` feature gates, as they are no longer needed.
1 parent b65f0be commit 9bf5c5b

File tree

24 files changed

+63
-103
lines changed

24 files changed

+63
-103
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/liballoc/boxed.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ use str::from_boxed_utf8_unchecked;
9191
#[unstable(feature = "box_heap",
9292
reason = "may be renamed; uncertain about custom allocator design",
9393
issue = "27779")]
94-
pub const HEAP: ExchangeHeapSingleton = ExchangeHeapSingleton { _force_singleton: () };
94+
pub const HEAP: ExchangeHeapSingleton = ExchangeHeapSingleton { };
9595

9696
/// This the singleton type used solely for `boxed::HEAP`.
9797
#[unstable(feature = "box_heap",
9898
reason = "may be renamed; uncertain about custom allocator design",
9999
issue = "27779")]
100100
#[allow(missing_debug_implementations)]
101101
#[derive(Copy, Clone)]
102-
pub struct ExchangeHeapSingleton {
103-
_force_singleton: (),
104-
}
102+
#[non_exhaustive]
103+
pub struct ExchangeHeapSingleton { }
105104

106105
/// A pointer type for heap allocation.
107106
///

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#![feature(lang_items)]
105105
#![feature(needs_allocator)]
106106
#![feature(nonzero)]
107+
#![feature(non_exhaustive)]
107108
#![feature(offset_to)]
108109
#![feature(optin_builtin_traits)]
109110
#![feature(pattern)]

src/liballoc/string.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ pub struct FromUtf8Error {
357357
/// ```
358358
#[stable(feature = "rust1", since = "1.0.0")]
359359
#[derive(Debug)]
360-
pub struct FromUtf16Error(());
360+
#[non_exhaustive]
361+
pub struct FromUtf16Error { }
361362

362363
impl String {
363364
/// Creates a new empty `String`.
@@ -616,7 +617,7 @@ impl String {
616617
/// ```
617618
#[stable(feature = "rust1", since = "1.0.0")]
618619
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
619-
decode_utf16(v.iter().cloned()).collect::<Result<_, _>>().map_err(|_| FromUtf16Error(()))
620+
decode_utf16(v.iter().cloned()).collect::<Result<_, _>>().map_err(|_| FromUtf16Error { })
620621
}
621622

622623
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing

src/libcore/array.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
6161
/// The error type returned when a conversion from a slice to an array fails.
6262
#[unstable(feature = "try_from", issue = "33417")]
6363
#[derive(Debug, Copy, Clone)]
64-
pub struct TryFromSliceError(());
64+
#[non_exhaustive]
65+
pub struct TryFromSliceError { }
6566

6667
impl fmt::Display for TryFromSliceError {
6768
#[inline]
@@ -157,7 +158,7 @@ macro_rules! array_impls {
157158
let ptr = slice.as_ptr() as *const [T; $N];
158159
unsafe { Ok(&*ptr) }
159160
} else {
160-
Err(TryFromSliceError(()))
161+
Err(TryFromSliceError { })
161162
}
162163
}
163164
}
@@ -171,7 +172,7 @@ macro_rules! array_impls {
171172
let ptr = slice.as_mut_ptr() as *mut [T; $N];
172173
unsafe { Ok(&mut *ptr) }
173174
} else {
174-
Err(TryFromSliceError(()))
175+
Err(TryFromSliceError { })
175176
}
176177
}
177178
}

src/libcore/cell.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,8 @@ pub struct RefCell<T: ?Sized> {
488488

489489
/// An error returned by [`RefCell::try_borrow`](struct.RefCell.html#method.try_borrow).
490490
#[stable(feature = "try_borrow", since = "1.13.0")]
491-
pub struct BorrowError {
492-
_private: (),
493-
}
491+
#[non_exhaustive]
492+
pub struct BorrowError { }
494493

495494
#[stable(feature = "try_borrow", since = "1.13.0")]
496495
impl Debug for BorrowError {
@@ -508,9 +507,8 @@ impl Display for BorrowError {
508507

509508
/// An error returned by [`RefCell::try_borrow_mut`](struct.RefCell.html#method.try_borrow_mut).
510509
#[stable(feature = "try_borrow", since = "1.13.0")]
511-
pub struct BorrowMutError {
512-
_private: (),
513-
}
510+
#[non_exhaustive]
511+
pub struct BorrowMutError { }
514512

515513
#[stable(feature = "try_borrow", since = "1.13.0")]
516514
impl Debug for BorrowMutError {
@@ -725,7 +723,7 @@ impl<T: ?Sized> RefCell<T> {
725723
value: unsafe { &*self.value.get() },
726724
borrow: b,
727725
}),
728-
None => Err(BorrowError { _private: () }),
726+
None => Err(BorrowError { }),
729727
}
730728
}
731729

@@ -801,7 +799,7 @@ impl<T: ?Sized> RefCell<T> {
801799
value: unsafe { &mut *self.value.get() },
802800
borrow: b,
803801
}),
804-
None => Err(BorrowMutError { _private: () }),
802+
None => Err(BorrowMutError { }),
805803
}
806804
}
807805

src/libcore/char.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl TryFrom<u32> for char {
272272
#[inline]
273273
fn try_from(i: u32) -> Result<Self, Self::Error> {
274274
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
275-
Err(CharTryFromError(()))
275+
Err(CharTryFromError { })
276276
} else {
277277
Ok(unsafe { from_u32_unchecked(i) })
278278
}
@@ -282,7 +282,8 @@ impl TryFrom<u32> for char {
282282
/// The error type returned when a conversion from u32 to char fails.
283283
#[unstable(feature = "try_from", issue = "33417")]
284284
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
285-
pub struct CharTryFromError(());
285+
#[non_exhaustive]
286+
pub struct CharTryFromError { }
286287

287288
#[unstable(feature = "try_from", issue = "33417")]
288289
impl fmt::Display for CharTryFromError {
@@ -818,7 +819,8 @@ pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter>
818819
/// `<DecodeUtf8 as Iterator>::next` returns this for an invalid input sequence.
819820
#[unstable(feature = "decode_utf8", issue = "33906")]
820821
#[derive(PartialEq, Eq, Debug)]
821-
pub struct InvalidSequence(());
822+
#[non_exhaustive]
823+
pub struct InvalidSequence { }
822824

823825
#[unstable(feature = "decode_utf8", issue = "33906")]
824826
impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
@@ -849,7 +851,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
849851
code_point = (code_point << 6) | u32::from(byte & 0b0011_1111);
850852
self.0.next();
851853
}
852-
_ => return Err(InvalidSequence(()))
854+
_ => return Err(InvalidSequence { })
853855
}
854856
}
855857
}
@@ -895,7 +897,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
895897
continuation_byte!();
896898
continuation_byte!();
897899
}
898-
_ => return Err(InvalidSequence(())) // Illegal first byte, overlong, or beyond MAX
900+
_ => return Err(InvalidSequence { }) // Illegal first byte, overlong, or beyond MAX
899901
}
900902
unsafe {
901903
Ok(from_u32_unchecked(code_point))

src/libcore/fmt/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ pub struct Formatter<'a> {
260260
// equivalent to `exists T.(&T, fn(&T, &mut Formatter) -> Result`.
261261

262262
struct Void {
263-
_priv: (),
264263
/// Erases all oibits, because `Void` erases the type of the object that
265264
/// will be used to produce formatted output. Since we do not know what
266265
/// oibits the real types have (and they can have any or none), we need to

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![feature(lang_items)]
8181
#![feature(never_type)]
8282
#![feature(no_core)]
83+
#![feature(non_exhaustive)]
8384
#![feature(on_unimplemented)]
8485
#![feature(optin_builtin_traits)]
8586
#![feature(prelude_import)]

src/libcore/num/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,8 @@ from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
29592959
/// The error type returned when a checked integral type conversion fails.
29602960
#[unstable(feature = "try_from", issue = "33417")]
29612961
#[derive(Debug, Copy, Clone)]
2962-
pub struct TryFromIntError(());
2962+
#[non_exhaustive]
2963+
pub struct TryFromIntError { }
29632964

29642965
impl TryFromIntError {
29652966
#[unstable(feature = "int_error_internals",
@@ -3014,7 +3015,7 @@ macro_rules! try_from_lower_bounded {
30143015
if u >= 0 {
30153016
Ok(u as $target)
30163017
} else {
3017-
Err(TryFromIntError(()))
3018+
Err(TryFromIntError { })
30183019
}
30193020
}
30203021
}
@@ -3031,7 +3032,7 @@ macro_rules! try_from_upper_bounded {
30313032
#[inline]
30323033
fn try_from(u: $source) -> Result<$target, TryFromIntError> {
30333034
if u > (<$target>::max_value() as $source) {
3034-
Err(TryFromIntError(()))
3035+
Err(TryFromIntError { })
30353036
} else {
30363037
Ok(u as $target)
30373038
}
@@ -3052,7 +3053,7 @@ macro_rules! try_from_both_bounded {
30523053
let min = <$target>::min_value() as $source;
30533054
let max = <$target>::max_value() as $source;
30543055
if u < min || u > max {
3055-
Err(TryFromIntError(()))
3056+
Err(TryFromIntError { })
30563057
} else {
30573058
Ok(u as $target)
30583059
}

src/libcore/str/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl FromStr for bool {
132132
match s {
133133
"true" => Ok(true),
134134
"false" => Ok(false),
135-
_ => Err(ParseBoolError { _priv: () }),
135+
_ => Err(ParseBoolError { }),
136136
}
137137
}
138138
}
@@ -142,7 +142,8 @@ impl FromStr for bool {
142142
/// [`from_str`]: ../../std/primitive.bool.html#method.from_str
143143
#[derive(Debug, Clone, PartialEq, Eq)]
144144
#[stable(feature = "rust1", since = "1.0.0")]
145-
pub struct ParseBoolError { _priv: () }
145+
#[non_exhaustive]
146+
pub struct ParseBoolError { }
146147

147148
#[stable(feature = "rust1", since = "1.0.0")]
148149
impl fmt::Display for ParseBoolError {

src/libcore/sync/atomic.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ unsafe impl<T> Sync for AtomicPtr<T> {}
182182
/// [nomicon]: ../../../nomicon/atomics.html
183183
#[stable(feature = "rust1", since = "1.0.0")]
184184
#[derive(Copy, Clone, Debug)]
185+
#[non_exhaustive]
185186
pub enum Ordering {
186187
/// No ordering constraints, only atomic operations.
187188
///
@@ -215,10 +216,6 @@ pub enum Ordering {
215216
/// sequentially consistent operations in the same order.
216217
#[stable(feature = "rust1", since = "1.0.0")]
217218
SeqCst,
218-
// Prevent exhaustive matching to allow for future extension
219-
#[doc(hidden)]
220-
#[unstable(feature = "future_atomic_orderings", issue = "0")]
221-
__Nonexhaustive,
222219
}
223220

224221
/// An [`AtomicBool`] initialized to `false`.
@@ -1468,7 +1465,6 @@ fn strongest_failure_ordering(order: Ordering) -> Ordering {
14681465
SeqCst => SeqCst,
14691466
Acquire => Acquire,
14701467
AcqRel => Acquire,
1471-
__Nonexhaustive => __Nonexhaustive,
14721468
}
14731469
}
14741470

@@ -1480,7 +1476,6 @@ unsafe fn atomic_store<T>(dst: *mut T, val: T, order: Ordering) {
14801476
SeqCst => intrinsics::atomic_store(dst, val),
14811477
Acquire => panic!("there is no such thing as an acquire store"),
14821478
AcqRel => panic!("there is no such thing as an acquire/release store"),
1483-
__Nonexhaustive => panic!("invalid memory ordering"),
14841479
}
14851480
}
14861481

@@ -1492,7 +1487,6 @@ unsafe fn atomic_load<T>(dst: *const T, order: Ordering) -> T {
14921487
SeqCst => intrinsics::atomic_load(dst),
14931488
Release => panic!("there is no such thing as a release load"),
14941489
AcqRel => panic!("there is no such thing as an acquire/release load"),
1495-
__Nonexhaustive => panic!("invalid memory ordering"),
14961490
}
14971491
}
14981492

@@ -1504,7 +1498,6 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
15041498
AcqRel => intrinsics::atomic_xchg_acqrel(dst, val),
15051499
Relaxed => intrinsics::atomic_xchg_relaxed(dst, val),
15061500
SeqCst => intrinsics::atomic_xchg(dst, val),
1507-
__Nonexhaustive => panic!("invalid memory ordering"),
15081501
}
15091502
}
15101503

@@ -1517,7 +1510,6 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
15171510
AcqRel => intrinsics::atomic_xadd_acqrel(dst, val),
15181511
Relaxed => intrinsics::atomic_xadd_relaxed(dst, val),
15191512
SeqCst => intrinsics::atomic_xadd(dst, val),
1520-
__Nonexhaustive => panic!("invalid memory ordering"),
15211513
}
15221514
}
15231515

@@ -1530,7 +1522,6 @@ unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
15301522
AcqRel => intrinsics::atomic_xsub_acqrel(dst, val),
15311523
Relaxed => intrinsics::atomic_xsub_relaxed(dst, val),
15321524
SeqCst => intrinsics::atomic_xsub(dst, val),
1533-
__Nonexhaustive => panic!("invalid memory ordering"),
15341525
}
15351526
}
15361527

@@ -1551,8 +1542,6 @@ unsafe fn atomic_compare_exchange<T>(dst: *mut T,
15511542
(AcqRel, Relaxed) => intrinsics::atomic_cxchg_acqrel_failrelaxed(dst, old, new),
15521543
(SeqCst, Relaxed) => intrinsics::atomic_cxchg_failrelaxed(dst, old, new),
15531544
(SeqCst, Acquire) => intrinsics::atomic_cxchg_failacq(dst, old, new),
1554-
(__Nonexhaustive, _) => panic!("invalid memory ordering"),
1555-
(_, __Nonexhaustive) => panic!("invalid memory ordering"),
15561545
(_, AcqRel) => panic!("there is no such thing as an acquire/release failure ordering"),
15571546
(_, Release) => panic!("there is no such thing as a release failure ordering"),
15581547
_ => panic!("a failure ordering can't be stronger than a success ordering"),
@@ -1577,8 +1566,6 @@ unsafe fn atomic_compare_exchange_weak<T>(dst: *mut T,
15771566
(AcqRel, Relaxed) => intrinsics::atomic_cxchgweak_acqrel_failrelaxed(dst, old, new),
15781567
(SeqCst, Relaxed) => intrinsics::atomic_cxchgweak_failrelaxed(dst, old, new),
15791568
(SeqCst, Acquire) => intrinsics::atomic_cxchgweak_failacq(dst, old, new),
1580-
(__Nonexhaustive, _) => panic!("invalid memory ordering"),
1581-
(_, __Nonexhaustive) => panic!("invalid memory ordering"),
15821569
(_, AcqRel) => panic!("there is no such thing as an acquire/release failure ordering"),
15831570
(_, Release) => panic!("there is no such thing as a release failure ordering"),
15841571
_ => panic!("a failure ordering can't be stronger than a success ordering"),
@@ -1594,7 +1581,6 @@ unsafe fn atomic_and<T>(dst: *mut T, val: T, order: Ordering) -> T {
15941581
AcqRel => intrinsics::atomic_and_acqrel(dst, val),
15951582
Relaxed => intrinsics::atomic_and_relaxed(dst, val),
15961583
SeqCst => intrinsics::atomic_and(dst, val),
1597-
__Nonexhaustive => panic!("invalid memory ordering"),
15981584
}
15991585
}
16001586

@@ -1606,7 +1592,6 @@ unsafe fn atomic_or<T>(dst: *mut T, val: T, order: Ordering) -> T {
16061592
AcqRel => intrinsics::atomic_or_acqrel(dst, val),
16071593
Relaxed => intrinsics::atomic_or_relaxed(dst, val),
16081594
SeqCst => intrinsics::atomic_or(dst, val),
1609-
__Nonexhaustive => panic!("invalid memory ordering"),
16101595
}
16111596
}
16121597

@@ -1618,7 +1603,6 @@ unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T {
16181603
AcqRel => intrinsics::atomic_xor_acqrel(dst, val),
16191604
Relaxed => intrinsics::atomic_xor_relaxed(dst, val),
16201605
SeqCst => intrinsics::atomic_xor(dst, val),
1621-
__Nonexhaustive => panic!("invalid memory ordering"),
16221606
}
16231607
}
16241608

@@ -1708,7 +1692,6 @@ pub fn fence(order: Ordering) {
17081692
AcqRel => intrinsics::atomic_fence_acqrel(),
17091693
SeqCst => intrinsics::atomic_fence(),
17101694
Relaxed => panic!("there is no such thing as a relaxed fence"),
1711-
__Nonexhaustive => panic!("invalid memory ordering"),
17121695
}
17131696
}
17141697
}
@@ -1798,7 +1781,6 @@ pub fn compiler_fence(order: Ordering) {
17981781
AcqRel => intrinsics::atomic_singlethreadfence_acqrel(),
17991782
SeqCst => intrinsics::atomic_singlethreadfence(),
18001783
Relaxed => panic!("there is no such thing as a relaxed compiler fence"),
1801-
__Nonexhaustive => panic!("invalid memory ordering"),
18021784
}
18031785
}
18041786
}

src/libproc_macro/diagnostic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_errors as rustc;
1515
/// An enum representing a diagnostic level.
1616
#[unstable(feature = "proc_macro", issue = "38356")]
1717
#[derive(Copy, Clone, Debug)]
18+
#[non_exhaustive]
1819
pub enum Level {
1920
/// An error.
2021
Error,
@@ -24,8 +25,6 @@ pub enum Level {
2425
Note,
2526
/// A help message.
2627
Help,
27-
#[doc(hidden)]
28-
__Nonexhaustive,
2928
}
3029

3130
/// A structure representing a diagnostic message and associated children
@@ -128,7 +127,6 @@ pub mod __internal {
128127
Level::Warning => rustc::Level::Warning,
129128
Level::Note => rustc::Level::Note,
130129
Level::Help => rustc::Level::Help,
131-
Level::__Nonexhaustive => unreachable!("Level::__Nonexhaustive")
132130
}
133131
}
134132
}

0 commit comments

Comments
 (0)