Auto merge of #1009 - RalfJung:expect_none, r=RalfJung

use expect_none and unwrap_none where it makes sense
This commit is contained in:
bors 2019-10-20 10:21:28 +00:00
commit cfd95998d7
8 changed files with 13 additions and 20 deletions

View file

@ -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)?;

View file

@ -1,4 +1,5 @@
#![feature(rustc_private)]
#![feature(option_expect_none, option_unwrap_none)]
#![warn(rust_2018_idioms)]
#![allow(clippy::cast_lossless)]

View file

@ -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(())
}

View file

@ -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)?;

View file

@ -7,6 +7,7 @@ use rustc::ty::layout::Size;
use crate::stacked_borrows::Tag;
use crate::*;
#[derive(Debug)]
pub struct FileHandle {
file: File,
}
@ -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
});
@ -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))
})
}
@ -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?)
})
}

View file

@ -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
@ -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

View file

@ -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
}

View file

@ -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
}
@ -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
})
}