Skip to content

Commit a6b1e5c

Browse files
authored
Merge pull request #4756 from RalfJung/clippy-manual_let_else
fix clippy::manual_let_else
2 parents aac2d74 + e7d5319 commit a6b1e5c

File tree

12 files changed

+59
-106
lines changed

12 files changed

+59
-106
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,12 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
826826
// FIXME: If we cannot determine the size (because the unsized tail is an `extern type`),
827827
// bail out -- we cannot reasonably figure out which memory range to reborrow.
828828
// See https://github.com/rust-lang/unsafe-code-guidelines/issues/276.
829-
let size = match size {
830-
Some(size) => size,
831-
None => {
832-
static DEDUP: AtomicBool = AtomicBool::new(false);
833-
if !DEDUP.swap(true, std::sync::atomic::Ordering::Relaxed) {
834-
this.emit_diagnostic(NonHaltingDiagnostic::ExternTypeReborrow);
835-
}
836-
return interp_ok(place.clone());
829+
let Some(size) = size else {
830+
static DEDUP: AtomicBool = AtomicBool::new(false);
831+
if !DEDUP.swap(true, std::sync::atomic::Ordering::Relaxed) {
832+
this.emit_diagnostic(NonHaltingDiagnostic::ExternTypeReborrow);
837833
}
834+
return interp_ok(place.clone());
838835
};
839836

840837
// Compute new borrow.

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,18 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
220220
};
221221

222222
trace!("Reborrow of size {:?}", ptr_size);
223-
let (alloc_id, base_offset, parent_prov) = match this.ptr_try_get_alloc_id(place.ptr(), 0) {
224-
Ok(data) => {
225-
// Unlike SB, we *do* a proper retag for size 0 if can identify the allocation.
226-
// After all, the pointer may be lazily initialized outside this initial range.
227-
data
228-
}
229-
Err(_) => {
230-
assert_eq!(ptr_size, Size::ZERO); // we did the deref check above, size has to be 0 here
231-
// This pointer doesn't come with an AllocId, so there's no
232-
// memory to do retagging in.
233-
let new_prov = place.ptr().provenance;
234-
trace!(
235-
"reborrow of size 0: reusing {:?} (pointee {})",
236-
place.ptr(),
237-
place.layout.ty,
238-
);
239-
log_creation(this, None)?;
240-
// Keep original provenance.
241-
return interp_ok(new_prov);
242-
}
223+
// Unlike SB, we *do* a proper retag for size 0 if can identify the allocation.
224+
// After all, the pointer may be lazily initialized outside this initial range.
225+
let Ok((alloc_id, base_offset, parent_prov)) = this.ptr_try_get_alloc_id(place.ptr(), 0)
226+
else {
227+
assert_eq!(ptr_size, Size::ZERO); // we did the deref check above, size has to be 0 here
228+
// This pointer doesn't come with an AllocId, so there's no
229+
// memory to do retagging in.
230+
let new_prov = place.ptr().provenance;
231+
trace!("reborrow of size 0: reusing {:?} (pointee {})", place.ptr(), place.layout.ty,);
232+
log_creation(this, None)?;
233+
// Keep original provenance.
234+
return interp_ok(new_prov);
243235
};
244236
let new_prov = Provenance::Concrete { alloc_id, tag: new_tag };
245237

@@ -612,8 +604,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
612604
let this = self.eval_context_mut();
613605
let (tag, alloc_id) = match ptr.provenance {
614606
Some(Provenance::Concrete { tag, alloc_id }) => (tag, alloc_id),
615-
_ => {
616-
eprintln!("Can't give the name {name} to Wildcard pointer");
607+
Some(Provenance::Wildcard) => {
608+
eprintln!("Can't give the name {name} to wildcard pointer");
609+
return interp_ok(());
610+
}
611+
None => {
612+
eprintln!("Can't give the name {name} to pointer without provenance");
617613
return interp_ok(());
618614
}
619615
};

src/concurrency/weak_memory.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,10 @@ impl StoreBufferAlloc {
208208
range: AllocRange,
209209
) -> InterpResult<'tcx, Option<Ref<'_, StoreBuffer>>> {
210210
let access_type = self.store_buffers.borrow().access_type(range);
211-
let pos = match access_type {
212-
AccessType::PerfectlyOverlapping(pos) => pos,
211+
let AccessType::PerfectlyOverlapping(pos) = access_type else {
213212
// If there is nothing here yet, that means there wasn't an atomic write yet so
214213
// we can't return anything outdated.
215-
_ => return interp_ok(None),
214+
return interp_ok(None);
216215
};
217216
let store_buffer = Ref::map(self.store_buffers.borrow(), |buffer| &buffer[pos]);
218217
interp_ok(Some(store_buffer))

src/eval.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,7 @@ where
543543
{
544544
// Parse argv[0]. Slashes aren't escaped. Literal double quotes are not allowed.
545545
let mut cmd = {
546-
let arg0 = if let Some(arg0) = args.next() {
547-
arg0
548-
} else {
546+
let Some(arg0) = args.next() else {
549547
return vec![0];
550548
};
551549
let arg0 = arg0.as_ref();

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646
rustc::potential_query_instability,
4747
rustc::untranslatable_diagnostic,
4848
)]
49-
#![warn(rust_2018_idioms, unqualified_local_imports, clippy::as_conversions)]
49+
#![warn(
50+
rust_2018_idioms,
51+
unqualified_local_imports,
52+
clippy::as_conversions,
53+
clippy::manual_let_else
54+
)]
5055
// Needed for rustdoc from bootstrap (with `-Znormalize-docs`).
5156
#![recursion_limit = "256"]
5257

src/shims/backtrace.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
9292
let (alloc_id, offset, _prov) = this.ptr_get_alloc_id(ptr, 0)?;
9393

9494
// This has to be an actual global fn ptr, not a dlsym function.
95-
let fn_instance = if let Some(GlobalAlloc::Function { instance, .. }) =
96-
this.tcx.try_get_global_alloc(alloc_id)
97-
{
98-
instance
99-
} else {
95+
let Some(GlobalAlloc::Function { instance, .. }) = this.tcx.try_get_global_alloc(alloc_id)
96+
else {
10097
throw_ub_format!("expected static function pointer, found {:?}", ptr);
10198
};
10299

103100
let lo =
104101
this.tcx.sess.source_map().lookup_char_pos(BytePos(offset.bytes().try_into().unwrap()));
105102

106-
let name = fn_instance.to_string();
103+
let name = instance.to_string();
107104
let filename = lo.file.name.prefer_remapped_unconditionally().to_string();
108105

109-
interp_ok((fn_instance, lo, name, filename))
106+
interp_ok((instance, lo, name, filename))
110107
}
111108

112109
fn handle_miri_resolve_frame(

src/shims/native_lib/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
459459
) -> InterpResult<'tcx, bool> {
460460
let this = self.eval_context_mut();
461461
// Get the pointer to the function in the shared object file if it exists.
462-
let code_ptr = match this.get_func_ptr_explicitly_from_lib(link_name) {
463-
Some(ptr) => ptr,
464-
None => {
465-
// Shared object file does not export this function -- try the shims next.
466-
return interp_ok(false);
467-
}
462+
let Some(code_ptr) = this.get_func_ptr_explicitly_from_lib(link_name) else {
463+
// Shared object file does not export this function -- try the shims next.
464+
return interp_ok(false);
468465
};
469466

470467
// Do we have ptrace?

src/shims/time.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
337337
let duration = this.deref_pointer_as(duration, this.libc_ty_layout("timespec"))?;
338338
let _rem = this.read_pointer(rem)?; // Signal handlers are not supported, so rem will never be written to.
339339

340-
let duration = match this.read_timespec(&duration)? {
341-
Some(duration) => duration,
342-
None => {
343-
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
344-
}
340+
let Some(duration) = this.read_timespec(&duration)? else {
341+
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
345342
};
346343

347344
this.block_thread(
@@ -378,11 +375,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
378375
throw_unsup_format!("clock_nanosleep: only CLOCK_MONOTONIC is supported");
379376
}
380377

381-
let duration = match this.read_timespec(&timespec)? {
382-
Some(duration) => duration,
383-
None => {
384-
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
385-
}
378+
let Some(duration) = this.read_timespec(&timespec)? else {
379+
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
386380
};
387381

388382
let timeout_anchor = if flags == 0 {

src/shims/unix/freebsd/sync.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
101101
// `uaddr2` points to a `struct _umtx_time`.
102102
let umtx_time_place = this.ptr_to_mplace(uaddr2, umtx_time_layout);
103103

104-
let umtx_time = match this.read_umtx_time(&umtx_time_place)? {
105-
Some(ut) => ut,
106-
None => {
107-
return this
108-
.set_last_error_and_return(LibcError("EINVAL"), dest);
109-
}
104+
let Some(umtx_time) = this.read_umtx_time(&umtx_time_place)? else {
105+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
110106
};
111107

112108
let anchor = if umtx_time.abs_time {
@@ -122,12 +118,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
122118

123119
// `uaddr2` points to a `struct timespec`.
124120
let timespec = this.ptr_to_mplace(uaddr2, timespec_layout);
125-
let duration = match this.read_timespec(&timespec)? {
126-
Some(duration) => duration,
127-
None => {
128-
return this
129-
.set_last_error_and_return(LibcError("EINVAL"), dest);
130-
}
121+
let Some(duration) = this.read_timespec(&timespec)? else {
122+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
131123
};
132124

133125
// FreeBSD does not seem to document which clock is used when the timeout
@@ -220,10 +212,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
220212

221213
let timespec_place = this.project_field(ut, FieldIdx::from_u32(0))?;
222214
// Inner `timespec` must still be valid.
223-
let duration = match this.read_timespec(&timespec_place)? {
224-
Some(dur) => dur,
225-
None => return interp_ok(None),
226-
};
215+
let Some(duration) = this.read_timespec(&timespec_place)? else { return interp_ok(None) };
227216

228217
let flags_place = this.project_field(ut, FieldIdx::from_u32(1))?;
229218
let flags = this.read_scalar(&flags_place)?.to_u32()?;

src/shims/unix/linux_like/sync.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ pub fn futex<'tcx>(
7171
let timeout = if ecx.ptr_is_null(timeout.ptr())? {
7272
None
7373
} else {
74-
let duration = match ecx.read_timespec(&timeout)? {
75-
Some(duration) => duration,
76-
None => {
77-
return ecx.set_last_error_and_return(LibcError("EINVAL"), dest);
78-
}
74+
let Some(duration) = ecx.read_timespec(&timeout)? else {
75+
return ecx.set_last_error_and_return(LibcError("EINVAL"), dest);
7976
};
8077
let timeout_clock = if op & futex_realtime == futex_realtime {
8178
ecx.check_no_isolation(

0 commit comments

Comments
 (0)