From 5bd5ea21ea97800e4173a8793beebc424d45358b Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 8 Mar 2021 16:57:09 +0100 Subject: [PATCH] Remove unwrap_none as it won't be stabilized. This upgrades to the latest rustc to be able to use try_insert() instead. --- rust-version | 2 +- src/helpers.rs | 2 +- src/lib.rs | 2 +- src/machine.rs | 4 ++-- src/shims/posix/fs.rs | 4 ++-- src/shims/tls.rs | 2 +- src/stacked_borrows.rs | 2 +- src/thread.rs | 8 ++++---- tests/run-pass/panic/std-panic-locations.rs | 5 ----- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/rust-version b/rust-version index 65644e75d977..e518870d5b77 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -09db05762b283bed62d4f92729cfee4646519833 +1d6b0f626aad4ee9f2eaec4d5582f45620ccab80 diff --git a/src/helpers.rs b/src/helpers.rs index 2baaebb0ae20..07356ab02032 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -179,7 +179,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx )?; this.write_immediate(*arg, &callee_arg)?; } - callee_args.next().expect_none("callee has more arguments than expected"); + assert_eq!(callee_args.next(), None, "callee has more arguments than expected"); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 5ed3d8950d04..7fc080a937f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] -#![feature(option_expect_none, option_unwrap_none)] #![feature(map_first_last)] +#![feature(map_try_insert)] #![feature(never_type)] #![feature(or_patterns)] #![feature(try_blocks)] diff --git a/src/machine.rs b/src/machine.rs index 32aae4a8c8e5..1415f7506a4e 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -179,8 +179,8 @@ impl MemoryExtra { this.memory .extra .extern_statics - .insert(Symbol::intern(name), ptr.alloc_id) - .unwrap_none(); + .try_insert(Symbol::intern(name), ptr.alloc_id) + .unwrap(); } /// Sets up the "extern statics" for this machine. diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index 2f1efee8c893..def2aca292a5 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -223,7 +223,7 @@ impl<'tcx> FileHandler { self.handles.last_key_value().map(|(fd, _)| fd.checked_add(1).unwrap()).unwrap_or(min_fd) }); - self.handles.insert(new_fd, file_handle).unwrap_none(); + self.handles.try_insert(new_fd, file_handle).unwrap(); new_fd } } @@ -381,7 +381,7 @@ impl DirHandler { fn insert_new(&mut self, read_dir: ReadDir) -> u64 { let id = self.next_id; self.next_id += 1; - self.streams.insert(id, read_dir).unwrap_none(); + self.streams.try_insert(id, read_dir).unwrap(); id } } diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 7f19fd167366..36bae2af9cd0 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -65,7 +65,7 @@ impl<'tcx> TlsData<'tcx> { pub fn create_tls_key(&mut self, dtor: Option>, max_size: Size) -> InterpResult<'tcx, TlsKey> { let new_key = self.next_key; self.next_key += 1; - self.keys.insert(new_key, TlsEntry { data: Default::default(), dtor }).unwrap_none(); + self.keys.try_insert(new_key, TlsEntry { data: Default::default(), dtor }).unwrap(); trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor); if max_size.bits() < 128 && new_key >= (1u128 << max_size.bits() as u128) { diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index cfaf8a9005ca..fbcd265baa11 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -201,7 +201,7 @@ impl GlobalState { self.base_ptr_ids.get(&id).copied().unwrap_or_else(|| { let tag = Tag::Tagged(self.new_ptr()); trace!("New allocation {:?} has base tag {:?}", id, tag); - self.base_ptr_ids.insert(id, tag).unwrap_none(); + self.base_ptr_ids.try_insert(id, tag).unwrap(); tag }) } diff --git a/src/thread.rs b/src/thread.rs index 5d783430417b..4fe44ef9d4a7 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -257,8 +257,8 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> { fn set_thread_local_alloc_id(&self, def_id: DefId, new_alloc_id: AllocId) { self.thread_local_alloc_ids .borrow_mut() - .insert((def_id, self.active_thread), new_alloc_id) - .unwrap_none(); + .try_insert((def_id, self.active_thread), new_alloc_id) + .unwrap(); } /// Borrow the stack of the active thread. @@ -404,8 +404,8 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> { callback: TimeoutCallback<'mir, 'tcx>, ) { self.timeout_callbacks - .insert(thread, TimeoutCallbackInfo { call_time, callback }) - .unwrap_none(); + .try_insert(thread, TimeoutCallbackInfo { call_time, callback }) + .unwrap(); } /// Unregister the callback for the `thread`. diff --git a/tests/run-pass/panic/std-panic-locations.rs b/tests/run-pass/panic/std-panic-locations.rs index ac2e8d5305df..e3050ad11835 100644 --- a/tests/run-pass/panic/std-panic-locations.rs +++ b/tests/run-pass/panic/std-panic-locations.rs @@ -1,4 +1,3 @@ -#![feature(option_expect_none, option_unwrap_none)] //! Test that panic locations for `#[track_caller]` functions in std have the correct //! location reported. @@ -25,10 +24,6 @@ fn main() { assert_panicked(|| nope.unwrap()); assert_panicked(|| nope.expect("")); - let yep: Option<()> = Some(()); - assert_panicked(|| yep.unwrap_none()); - assert_panicked(|| yep.expect_none("")); - let oops: Result<(), ()> = Err(()); assert_panicked(|| oops.unwrap()); assert_panicked(|| oops.expect(""));