Skip to content

Commit 413e341

Browse files
committed
Auto merge of #1735 - m-ou-se:remove-unwrap-none, r=RalfJung
Remove unwrap_none/expect_none, take 2. This is #1734, but now with a better alternative. This also upgrades rustc to the latest version, to be able to use the better alternative (`try_insert`).
2 parents 0a0e366 + 90e218a commit 413e341

File tree

9 files changed

+14
-19
lines changed

9 files changed

+14
-19
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
09db05762b283bed62d4f92729cfee4646519833
1+
1d6b0f626aad4ee9f2eaec4d5582f45620ccab80

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179179
)?;
180180
this.write_immediate(*arg, &callee_arg)?;
181181
}
182-
callee_args.next().expect_none("callee has more arguments than expected");
182+
assert_eq!(callee_args.next(), None, "callee has more arguments than expected");
183183

184184
Ok(())
185185
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(rustc_private)]
2-
#![feature(option_expect_none, option_unwrap_none)]
32
#![feature(map_first_last)]
3+
#![feature(map_try_insert)]
44
#![feature(never_type)]
55
#![feature(or_patterns)]
66
#![feature(try_blocks)]

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ impl MemoryExtra {
179179
this.memory
180180
.extra
181181
.extern_statics
182-
.insert(Symbol::intern(name), ptr.alloc_id)
183-
.unwrap_none();
182+
.try_insert(Symbol::intern(name), ptr.alloc_id)
183+
.unwrap();
184184
}
185185

186186
/// Sets up the "extern statics" for this machine.

src/shims/posix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'tcx> FileHandler {
223223
self.handles.last_key_value().map(|(fd, _)| fd.checked_add(1).unwrap()).unwrap_or(min_fd)
224224
});
225225

226-
self.handles.insert(new_fd, file_handle).unwrap_none();
226+
self.handles.try_insert(new_fd, file_handle).unwrap();
227227
new_fd
228228
}
229229
}
@@ -381,7 +381,7 @@ impl DirHandler {
381381
fn insert_new(&mut self, read_dir: ReadDir) -> u64 {
382382
let id = self.next_id;
383383
self.next_id += 1;
384-
self.streams.insert(id, read_dir).unwrap_none();
384+
self.streams.try_insert(id, read_dir).unwrap();
385385
id
386386
}
387387
}

src/shims/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> TlsData<'tcx> {
6565
pub fn create_tls_key(&mut self, dtor: Option<ty::Instance<'tcx>>, max_size: Size) -> InterpResult<'tcx, TlsKey> {
6666
let new_key = self.next_key;
6767
self.next_key += 1;
68-
self.keys.insert(new_key, TlsEntry { data: Default::default(), dtor }).unwrap_none();
68+
self.keys.try_insert(new_key, TlsEntry { data: Default::default(), dtor }).unwrap();
6969
trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor);
7070

7171
if max_size.bits() < 128 && new_key >= (1u128 << max_size.bits() as u128) {

src/stacked_borrows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl GlobalState {
201201
self.base_ptr_ids.get(&id).copied().unwrap_or_else(|| {
202202
let tag = Tag::Tagged(self.new_ptr());
203203
trace!("New allocation {:?} has base tag {:?}", id, tag);
204-
self.base_ptr_ids.insert(id, tag).unwrap_none();
204+
self.base_ptr_ids.try_insert(id, tag).unwrap();
205205
tag
206206
})
207207
}

src/thread.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
257257
fn set_thread_local_alloc_id(&self, def_id: DefId, new_alloc_id: AllocId) {
258258
self.thread_local_alloc_ids
259259
.borrow_mut()
260-
.insert((def_id, self.active_thread), new_alloc_id)
261-
.unwrap_none();
260+
.try_insert((def_id, self.active_thread), new_alloc_id)
261+
.unwrap();
262262
}
263263

264264
/// Borrow the stack of the active thread.
@@ -404,8 +404,8 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
404404
callback: TimeoutCallback<'mir, 'tcx>,
405405
) {
406406
self.timeout_callbacks
407-
.insert(thread, TimeoutCallbackInfo { call_time, callback })
408-
.unwrap_none();
407+
.try_insert(thread, TimeoutCallbackInfo { call_time, callback })
408+
.unwrap();
409409
}
410410

411411
/// Unregister the callback for the `thread`.

tests/run-pass/panic/std-panic-locations.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(option_expect_none, option_unwrap_none)]
21
//! Test that panic locations for `#[track_caller]` functions in std have the correct
32
//! location reported.
43
@@ -25,10 +24,6 @@ fn main() {
2524
assert_panicked(|| nope.unwrap());
2625
assert_panicked(|| nope.expect(""));
2726

28-
let yep: Option<()> = Some(());
29-
assert_panicked(|| yep.unwrap_none());
30-
assert_panicked(|| yep.expect_none(""));
31-
3227
let oops: Result<(), ()> = Err(());
3328
assert_panicked(|| oops.unwrap());
3429
assert_panicked(|| oops.expect(""));
@@ -40,5 +35,5 @@ fn main() {
4035
// Cleanup: reset to default hook.
4136
drop(std::panic::take_hook());
4237

43-
assert_eq!(HOOK_COUNT.load(Ordering::Relaxed), 8);
38+
assert_eq!(HOOK_COUNT.load(Ordering::Relaxed), 6);
4439
}

0 commit comments

Comments
 (0)