Skip to content

Commit cfd9599

Browse files
committed
Auto merge of #1009 - RalfJung:expect_none, r=RalfJung
use expect_none and unwrap_none where it makes sense
2 parents fccb239 + 88c8853 commit cfd9599

File tree

8 files changed

+13
-20
lines changed

8 files changed

+13
-20
lines changed

src/eval.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
177177
}
178178
}
179179

180-
assert!(
181-
args.next().is_none(),
182-
"start lang item has more arguments than expected"
183-
);
180+
args.next().expect_none("start lang item has more arguments than expected");
184181

185182
// Set the last_error to 0
186183
let errno_layout = ecx.layout_of(ecx.tcx.types.u32)?;

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(rustc_private)]
2+
#![feature(option_expect_none, option_unwrap_none)]
23

34
#![warn(rust_2018_idioms)]
45
#![allow(clippy::cast_lossless)]

src/machine.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
244244
ecx.write_scalar(Scalar::from_uint(align, arg.layout.size), arg)?;
245245

246246
// No more arguments.
247-
assert!(
248-
args.next().is_none(),
249-
"`exchange_malloc` lang item has more arguments than expected"
250-
);
247+
args.next().expect_none("`exchange_malloc` lang item has more arguments than expected");
251248
Ok(())
252249
}
253250

src/shims/foreign_items.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
349349
let arg_dest = this.local_place(arg_local)?;
350350
this.write_scalar(data, arg_dest)?;
351351

352-
assert!(
353-
args.next().is_none(),
354-
"__rust_maybe_catch_panic argument has more arguments than expected"
355-
);
352+
args.next().expect_none("__rust_maybe_catch_panic argument has more arguments than expected");
356353

357354
// We ourselves will return `0`, eventually (because we will not return if we paniced).
358355
this.write_null(dest)?;

src/shims/fs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc::ty::layout::Size;
77
use crate::stacked_borrows::Tag;
88
use crate::*;
99

10+
#[derive(Debug)]
1011
pub struct FileHandle {
1112
file: File,
1213
}
@@ -103,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
103104
let fd = options.open(path).map(|file| {
104105
let mut fh = &mut this.machine.file_handler;
105106
fh.low += 1;
106-
fh.handles.insert(fh.low, FileHandle { file });
107+
fh.handles.insert(fh.low, FileHandle { file }).unwrap_none();
107108
fh.low
108109
});
109110

@@ -175,7 +176,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
175176
.map(|buffer| handle.file.read(buffer))
176177
});
177178
// Reinsert the file handle
178-
this.machine.file_handler.handles.insert(fd, handle);
179+
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
179180
this.consume_result(bytes?.map(|bytes| bytes as i64))
180181
})
181182
}
@@ -204,7 +205,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
204205
.get_bytes(&*this.tcx, buf, Size::from_bytes(count))
205206
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))
206207
});
207-
this.machine.file_handler.handles.insert(fd, handle);
208+
this.machine.file_handler.handles.insert(fd, handle).unwrap_none();
208209
this.consume_result(bytes?)
209210
})
210211
}

src/shims/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
356356
_ => {
357357
// Do it in memory
358358
let mplace = this.force_allocation(dest)?;
359-
assert!(mplace.meta.is_none());
359+
mplace.meta.unwrap_none();
360360
// not a zst, must be valid pointer
361361
let ptr = mplace.ptr.to_ptr()?;
362362
// we know the return place is in-bounds
@@ -547,7 +547,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
547547
_ => {
548548
// Do it in memory
549549
let mplace = this.force_allocation(dest)?;
550-
assert!(mplace.meta.is_none());
550+
mplace.meta.unwrap_none();
551551
let ptr = mplace.ptr.to_ptr()?;
552552
// We know the return place is in-bounds
553553
this.memory

src/shims/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> TlsData<'tcx> {
5353
data: None,
5454
dtor,
5555
},
56-
);
56+
).unwrap_none();
5757
trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor);
5858
new_key
5959
}

src/stacked_borrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl GlobalState {
172172
pub fn new_call(&mut self) -> CallId {
173173
let id = self.next_call_id;
174174
trace!("new_call: Assigning ID {}", id);
175-
self.active_calls.insert(id);
175+
assert!(self.active_calls.insert(id));
176176
self.next_call_id = NonZeroU64::new(id.get() + 1).unwrap();
177177
id
178178
}
@@ -189,7 +189,7 @@ impl GlobalState {
189189
self.base_ptr_ids.get(&id).copied().unwrap_or_else(|| {
190190
let tag = Tag::Tagged(self.new_ptr());
191191
trace!("New allocation {:?} has base tag {:?}", id, tag);
192-
self.base_ptr_ids.insert(id, tag);
192+
self.base_ptr_ids.insert(id, tag).unwrap_none();
193193
tag
194194
})
195195
}

0 commit comments

Comments
 (0)