Skip to content

use expect_none and unwrap_none where it makes sense #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
}
}

assert!(
args.next().is_none(),
"start lang item has more arguments than expected"
);
args.next().expect_none("start lang item has more arguments than expected");

// Set the last_error to 0
let errno_layout = ecx.layout_of(ecx.tcx.types.u32)?;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(rustc_private)]
#![feature(option_expect_none, option_unwrap_none)]

#![warn(rust_2018_idioms)]
#![allow(clippy::cast_lossless)]
Expand Down
5 changes: 1 addition & 4 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
ecx.write_scalar(Scalar::from_uint(align, arg.layout.size), arg)?;

// No more arguments.
assert!(
args.next().is_none(),
"`exchange_malloc` lang item has more arguments than expected"
);
args.next().expect_none("`exchange_malloc` lang item has more arguments than expected");
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let arg_dest = this.local_place(arg_local)?;
this.write_scalar(data, arg_dest)?;

assert!(
args.next().is_none(),
"__rust_maybe_catch_panic argument has more arguments than expected"
);
args.next().expect_none("__rust_maybe_catch_panic argument has more arguments than expected");

// We ourselves will return `0`, eventually (because we will not return if we paniced).
this.write_null(dest)?;
Expand Down
7 changes: 4 additions & 3 deletions src/shims/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc::ty::layout::Size;
use crate::stacked_borrows::Tag;
use crate::*;

#[derive(Debug)]
pub struct FileHandle {
file: File,
}
Expand Down Expand Up @@ -103,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let fd = options.open(path).map(|file| {
let mut fh = &mut this.machine.file_handler;
fh.low += 1;
fh.handles.insert(fh.low, FileHandle { file });
fh.handles.insert(fh.low, FileHandle { file }).unwrap_none();
fh.low
});

Expand Down Expand Up @@ -175,7 +176,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
.map(|buffer| handle.file.read(buffer))
});
// Reinsert the file handle
this.machine.file_handler.handles.insert(fd, handle);
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
this.consume_result(bytes?.map(|bytes| bytes as i64))
})
}
Expand Down Expand Up @@ -204,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
.get_bytes(&*this.tcx, buf, Size::from_bytes(count))
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
});
this.machine.file_handler.handles.insert(fd, handle);
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
this.consume_result(bytes?)
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/shims/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_ => {
// Do it in memory
let mplace = this.force_allocation(dest)?;
assert!(mplace.meta.is_none());
mplace.meta.unwrap_none();
// not a zst, must be valid pointer
let ptr = mplace.ptr.to_ptr()?;
// we know the return place is in-bounds
Expand Down Expand Up @@ -547,7 +547,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
_ => {
// Do it in memory
let mplace = this.force_allocation(dest)?;
assert!(mplace.meta.is_none());
mplace.meta.unwrap_none();
let ptr = mplace.ptr.to_ptr()?;
// We know the return place is in-bounds
this.memory
Expand Down
2 changes: 1 addition & 1 deletion src/shims/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'tcx> TlsData<'tcx> {
data: None,
dtor,
},
);
).unwrap_none();
trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor);
new_key
}
Expand Down
4 changes: 2 additions & 2 deletions src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl GlobalState {
pub fn new_call(&mut self) -> CallId {
let id = self.next_call_id;
trace!("new_call: Assigning ID {}", id);
self.active_calls.insert(id);
assert!(self.active_calls.insert(id));
self.next_call_id = NonZeroU64::new(id.get() + 1).unwrap();
id
}
Expand All @@ -189,7 +189,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);
self.base_ptr_ids.insert(id, tag).unwrap_none();
tag
})
}
Expand Down