-
Notifications
You must be signed in to change notification settings - Fork 386
Remove unwrap_none/expect_none. #1734
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
That's a bummer, I felt it made the code here a lot cleaner. :( |
this.memory | ||
.extra | ||
.extern_statics | ||
.insert(Symbol::intern(name), ptr.alloc_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's bad style for assertions to have important side-effects like this. Can you let-bind the result of insert
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I should have just said "and the same everywhere else", sorry for that... but when I realized it affects basically all the lines you changed, I was already half-way through...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can change it. I'd be curious to hear why you think this is bad style though. Assertions with side effects are quite common in rustc
. In C and C++ it's to be avoided because it's only conditionally compiled, but in Rust it's not much different than a panic!()
in an if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I answered that in rust-lang/rust#62633 (comment).
@@ -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(); | |||
assert!(self.handles.insert(new_fd, file_handle).is_none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
@@ -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(); | |||
assert!(self.streams.insert(id, read_dir).is_none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
@@ -65,7 +65,7 @@ impl<'tcx> TlsData<'tcx> { | |||
pub fn create_tls_key(&mut self, dtor: Option<ty::Instance<'tcx>>, 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(); | |||
assert!(self.keys.insert(new_key, TlsEntry { data: Default::default(), dtor }).is_none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
@@ -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(); | |||
assert_eq!(self.base_ptr_ids.insert(id, tag), None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
assert_eq!( | ||
self.thread_local_alloc_ids | ||
.borrow_mut() | ||
.insert((def_id, self.active_thread), new_alloc_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
.unwrap_none(); | ||
assert!( | ||
self.timeout_callbacks | ||
.insert(thread, TimeoutCallbackInfo { call_time, callback }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, please add a let-binding to avoid assertions with side-effects.
Another alternative is to use |
Yeah that's what I did in |
Putting this on hold until we figure out a better alternative for Thanks for the feedback. |
Thanks for opening the issue! EDIT: And PR ❤️ If the libs team wants to get rid of these functions, I certainly won't block that. I can also help figure out panic messages for |
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`).
We're not going to stabilize
Option::{unwrap_none, expect_none}
. (See rust-lang/rust#62633.) This removes the usage of those unstable methods from miri.