Skip to content

Commit 8dc0ae2

Browse files
committed
Remove Option::{unwrap_none, expect_none}.
1 parent f293f70 commit 8dc0ae2

File tree

5 files changed

+10
-108
lines changed

5 files changed

+10
-108
lines changed

Diff for: library/core/src/option.rs

+1-93
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
151151
use crate::pin::Pin;
152152
use crate::{
153-
fmt, hint, mem,
153+
hint, mem,
154154
ops::{self, Deref, DerefMut},
155155
};
156156

@@ -1121,90 +1121,6 @@ impl<T: Clone> Option<&mut T> {
11211121
}
11221122
}
11231123

1124-
impl<T: fmt::Debug> Option<T> {
1125-
/// Consumes `self` while expecting [`None`] and returning nothing.
1126-
///
1127-
/// # Panics
1128-
///
1129-
/// Panics if the value is a [`Some`], with a panic message including the
1130-
/// passed message, and the content of the [`Some`].
1131-
///
1132-
/// # Examples
1133-
///
1134-
/// ```
1135-
/// #![feature(option_expect_none)]
1136-
///
1137-
/// use std::collections::HashMap;
1138-
/// let mut squares = HashMap::new();
1139-
/// for i in -10..=10 {
1140-
/// // This will not panic, since all keys are unique.
1141-
/// squares.insert(i, i * i).expect_none("duplicate key");
1142-
/// }
1143-
/// ```
1144-
///
1145-
/// ```should_panic
1146-
/// #![feature(option_expect_none)]
1147-
///
1148-
/// use std::collections::HashMap;
1149-
/// let mut sqrts = HashMap::new();
1150-
/// for i in -10..=10 {
1151-
/// // This will panic, since both negative and positive `i` will
1152-
/// // insert the same `i * i` key, returning the old `Some(i)`.
1153-
/// sqrts.insert(i * i, i).expect_none("duplicate key");
1154-
/// }
1155-
/// ```
1156-
#[inline]
1157-
#[track_caller]
1158-
#[unstable(feature = "option_expect_none", reason = "newly added", issue = "62633")]
1159-
pub fn expect_none(self, msg: &str) {
1160-
if let Some(val) = self {
1161-
expect_none_failed(msg, &val);
1162-
}
1163-
}
1164-
1165-
/// Consumes `self` while expecting [`None`] and returning nothing.
1166-
///
1167-
/// # Panics
1168-
///
1169-
/// Panics if the value is a [`Some`], with a custom panic message provided
1170-
/// by the [`Some`]'s value.
1171-
///
1172-
/// [`Some(v)`]: Some
1173-
///
1174-
/// # Examples
1175-
///
1176-
/// ```
1177-
/// #![feature(option_unwrap_none)]
1178-
///
1179-
/// use std::collections::HashMap;
1180-
/// let mut squares = HashMap::new();
1181-
/// for i in -10..=10 {
1182-
/// // This will not panic, since all keys are unique.
1183-
/// squares.insert(i, i * i).unwrap_none();
1184-
/// }
1185-
/// ```
1186-
///
1187-
/// ```should_panic
1188-
/// #![feature(option_unwrap_none)]
1189-
///
1190-
/// use std::collections::HashMap;
1191-
/// let mut sqrts = HashMap::new();
1192-
/// for i in -10..=10 {
1193-
/// // This will panic, since both negative and positive `i` will
1194-
/// // insert the same `i * i` key, returning the old `Some(i)`.
1195-
/// sqrts.insert(i * i, i).unwrap_none();
1196-
/// }
1197-
/// ```
1198-
#[inline]
1199-
#[track_caller]
1200-
#[unstable(feature = "option_unwrap_none", reason = "newly added", issue = "62633")]
1201-
pub fn unwrap_none(self) {
1202-
if let Some(val) = self {
1203-
expect_none_failed("called `Option::unwrap_none()` on a `Some` value", &val);
1204-
}
1205-
}
1206-
}
1207-
12081124
impl<T: Default> Option<T> {
12091125
/// Returns the contained [`Some`] value or a default
12101126
///
@@ -1321,14 +1237,6 @@ fn expect_failed(msg: &str) -> ! {
13211237
panic!("{}", msg)
13221238
}
13231239

1324-
// This is a separate function to reduce the code size of .expect_none() itself.
1325-
#[inline(never)]
1326-
#[cold]
1327-
#[track_caller]
1328-
fn expect_none_failed(msg: &str, value: &dyn fmt::Debug) -> ! {
1329-
panic!("{}: {:?}", msg, value)
1330-
}
1331-
13321240
/////////////////////////////////////////////////////////////////////////////
13331241
// Trait implementations
13341242
/////////////////////////////////////////////////////////////////////////////

Diff for: library/core/tests/iter/adapters/chain.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ fn test_iterator_chain_size_hint() {
174174
fn test_iterator_chain_unfused() {
175175
// Chain shouldn't be fused in its second iterator, depending on direction
176176
let mut iter = NonFused::new(empty()).chain(Toggle { is_empty: true });
177-
iter.next().unwrap_none();
178-
iter.next().unwrap();
179-
iter.next().unwrap_none();
177+
assert!(iter.next().is_none());
178+
assert!(iter.next().is_some());
179+
assert!(iter.next().is_none());
180180

181181
let mut iter = Toggle { is_empty: true }.chain(NonFused::new(empty()));
182-
iter.next_back().unwrap_none();
183-
iter.next_back().unwrap();
184-
iter.next_back().unwrap_none();
182+
assert!(iter.next_back().is_none());
183+
assert!(iter.next_back().is_some());
184+
assert!(iter.next_back().is_none());
185185
}
186186

187187
#[test]

Diff for: library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
#![feature(unwrap_infallible)]
6969
#![feature(option_result_unwrap_unchecked)]
7070
#![feature(result_into_ok_or_err)]
71-
#![feature(option_unwrap_none)]
7271
#![feature(peekable_peek_mut)]
7372
#![cfg_attr(not(bootstrap), feature(ptr_metadata))]
7473
#![feature(once_cell)]

Diff for: library/test/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#![feature(nll)]
2626
#![feature(available_concurrency)]
2727
#![feature(internal_output_capture)]
28-
#![feature(option_unwrap_none)]
2928
#![feature(panic_unwind)]
3029
#![feature(staged_api)]
3130
#![feature(termination_trait_lib)]
@@ -298,8 +297,9 @@ where
298297
let test = remaining.pop().unwrap();
299298
let event = TestEvent::TeWait(test.desc.clone());
300299
notify_about_test_event(event)?;
301-
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No)
302-
.unwrap_none();
300+
let join_handle =
301+
run_test(opts, !opts.run_tests, test, run_strategy, tx.clone(), Concurrent::No);
302+
assert!(join_handle.is_none());
303303
let completed_test = rx.recv().unwrap();
304304

305305
let event = TestEvent::TeResult(completed_test);

Diff for: src/test/ui/rfc-2091-track-caller/std-panic-locations.rs

-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// revisions: default mir-opt
44
//[mir-opt] compile-flags: -Zmir-opt-level=4
55

6-
#![feature(option_expect_none, option_unwrap_none)]
76
#![allow(unconditional_panic)]
87

98
//! Test that panic locations for `#[track_caller]` functions in std have the correct
@@ -32,10 +31,6 @@ fn main() {
3231
assert_panicked(|| nope.unwrap());
3332
assert_panicked(|| nope.expect(""));
3433

35-
let yep: Option<()> = Some(());
36-
assert_panicked(|| yep.unwrap_none());
37-
assert_panicked(|| yep.expect_none(""));
38-
3934
let oops: Result<(), ()> = Err(());
4035
assert_panicked(|| oops.unwrap());
4136
assert_panicked(|| oops.expect(""));

0 commit comments

Comments
 (0)