Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c9407f8

Browse files
committed
Auto merge of rust-lang#2091 - dtolnay-contrib:clippy, r=oli-obk
Resolve some clippy lints, ignore the rest `cargo clippy` finishes cleanly after this. I stuck to only what I think are the least objectionable lints: cleaning up useless identity conversions that do `from`/`try_from`/`into` going from T-&gt;T, extraneous `&` on expressions that are already a reference, unused lifetime parameters, and similar. Below in the \<details\> is the complete remaining output of `cargo clippy` with the `allow` attribute removed. I think all the lints left are fine to keep ignoring. <details> <summary><code>$ cargo clippy -- -Dclippy::all</code></summary> ```console error: this `else { if .. }` block can be collapsed --> src/data_race.rs:559:16 | 559 | } else { | ________________^ 560 | | if lt { &rhs } else { &old } 561 | | }; | |_________^ help: collapse nested if block: `if lt { &rhs } else { &old }` | = note: `-D clippy::collapsible-else-if` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if error: this `if` statement can be collapsed --> src/range_map.rs:166:17 | 166 | / if successful_merge_count > 0 { 167 | | if done || self.v[end_idx].data != self.v[equal_since_idx].data { 168 | | // Everything in `equal_since..end` was equal. Make them just one element covering 169 | | // the entire range. ... | 187 | | } 188 | | } | |_________________^ | = note: `-D clippy::collapsible-if` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 166 ~ if successful_merge_count > 0 && (done || self.v[end_idx].data != self.v[equal_since_idx].data) { 167 + // Everything in `equal_since..end` was equal. Make them just one element covering 168 + // the entire range. 169 + let removed_elems = end_idx - equal_since_idx - 1; // number of elements that we would remove 170 + if removed_elems > 0 { 171 + // Adjust the range of the first element to cover all of them. ... error: this `else { if .. }` block can be collapsed --> src/shims/foreign_items.rs:114:16 | 114 | } else { | ________________^ 115 | | if new_size == 0 { 116 | | this.deallocate_ptr(old_ptr, None, kind.into())?; 117 | | Ok(Pointer::null()) ... | 127 | | } 128 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if help: collapse nested if block | 114 ~ } else if new_size == 0 { 115 + this.deallocate_ptr(old_ptr, None, kind.into())?; 116 + Ok(Pointer::null()) 117 + } else { 118 + let new_ptr = this.reallocate_ptr( 119 + old_ptr, ... error: this `else { if .. }` block can be collapsed --> src/shims/posix/sync.rs:459:20 | 459 | } else { | ____________________^ 460 | | if is_mutex_kind_default(this, kind)? 461 | | || is_mutex_kind_normal(this, kind)? 462 | | || kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")? ... | 472 | | } 473 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if help: collapse nested if block | 459 ~ } else if is_mutex_kind_default(this, kind)? 460 + || is_mutex_kind_normal(this, kind)? 461 + || kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")? 462 + { 463 + this.eval_libc_i32("EBUSY") 464 + } else if kind == this.eval_libc("PTHREAD_MUTEX_RECURSIVE")? { ... error: this `if` statement can be collapsed --> src/thread.rs:132:9 | 132 | / if self.state == ThreadState::Enabled { 133 | | if self.stack.is_empty() { 134 | | self.state = ThreadState::Terminated; 135 | | return true; 136 | | } 137 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 132 ~ if self.state == ThreadState::Enabled && self.stack.is_empty() { 133 + self.state = ThreadState::Terminated; 134 + return true; 135 + } | error: this `if` statement can be collapsed --> src/thread.rs:523:13 | 523 | / if thread.state == ThreadState::Enabled { 524 | | if !self.yield_active_thread || id != self.active_thread { 525 | | self.active_thread = id; 526 | | if let Some(data_race) = data_race { ... | 530 | | } 531 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 523 ~ if thread.state == ThreadState::Enabled && (!self.yield_active_thread || id != self.active_thread) { 524 + self.active_thread = id; 525 + if let Some(data_race) = data_race { 526 + data_race.thread_set_active(self.active_thread); 527 + } 528 + break; ... error: you should consider adding a `Default` implementation for `GlobalState` --> src/data_race.rs:1132:5 | 1132 | / pub fn new() -> Self { 1133 | | let mut global_state = GlobalState { 1134 | | multi_threaded: Cell::new(false), 1135 | | vector_clocks: RefCell::new(IndexVec::new()), ... | 1155 | | global_state 1156 | | } | |_____^ | = note: `-D clippy::new-without-default` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default help: try adding this | 1129 + impl Default for GlobalState { 1130 + fn default() -> Self { 1131 + Self::new() 1132 + } 1133 + } | error: useless use of `format!` --> src/diagnostics.rs:155:32 | 155 | (None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"pass the flag `-Zmiri-disable-isolation` to disable isolation;".to_string()` | = note: `-D clippy::useless-format` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:156:32 | 156 | ...e, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning"... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:161:32 | 161 | ...e, format!("this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental"... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:197:33 | 197 | ...e, format!("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support")... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:202:32 | 202 | ... (None, format!("this usually indicates that your program performed an invalid operation and caused Undefined Behavior")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"this usually indicates that your program performed an invalid operation and caused Undefined Behavior".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:203:32 | 203 | (None, format!("but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:207:32 | 207 | ... (None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: useless use of `format!` --> src/diagnostics.rs:208:32 | 208 | ...(None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/diagnostics.rs:247:5 | 247 | / match e.kind() { 248 | | UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) => { 249 | | eprintln!( 250 | | "Uninitialized read occurred at offsets 0x{:x}..0x{:x} into this allocation:", ... | 256 | | _ => {} 257 | | } | |_____^ | = note: `-D clippy::single-match` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try this | 247 ~ if let UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) = e.kind() { 248 + eprintln!( 249 + "Uninitialized read occurred at offsets 0x{:x}..0x{:x} into this allocation:", 250 + access.uninit_offset.bytes(), 251 + access.uninit_offset.bytes() + access.uninit_size.bytes(), 252 + ); ... error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true --> src/machine.rs:92:1 | 92 | impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::from-over-into` implied by `-D clippy::all` = help: consider to implement `From<machine::MiriMemoryKind>` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into error: manual implementation of `Option::map` --> src/machine.rs:570:22 | 570 | let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows { | ______________________^ 571 | | Some(Stacks::new_allocation(id, alloc.size(), stacked_borrows, kind)) 572 | | } else { 573 | | None 574 | | }; | |_________^ help: try this: `ecx.machine.stacked_borrows.as_ref().map(|stacked_borrows| Stacks::new_allocation(id, alloc.size(), stacked_borrows, kind))` | = note: `-D clippy::manual-map` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_map error: manual implementation of `Option::map` --> src/machine.rs:575:26 | 575 | let race_alloc = if let Some(data_race) = &ecx.machine.data_race { | __________________________^ 576 | | Some(data_race::AllocExtra::new_allocation(data_race, alloc.size(), kind)) 577 | | } else { 578 | | None 579 | | }; | |_________^ help: try this: `ecx.machine.data_race.as_ref().map(|data_race| data_race::AllocExtra::new_allocation(data_race, alloc.size(), kind))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_map error: variant name ends with the enum's name --> src/shims/intrinsics.rs:354:21 | 354 | MirOp(mir::UnOp), | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::enum-variant-names` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names error: variant name ends with the enum's name --> src/shims/intrinsics.rs:453:21 | 453 | MirOp(BinOp), | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names error: variant name ends with the enum's name --> src/shims/intrinsics.rs:454:21 | 454 | SaturatingOp(BinOp), | ^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names error: variant name ends with the enum's name --> src/shims/intrinsics.rs:580:21 | 580 | MirOp(BinOp), | ^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) --> src/shims/intrinsics.rs:1391:1 | 1391 | fn simd_element_to_bool<'tcx>(elem: ImmTy<'tcx, Tag>) -> InterpResult<'tcx, bool> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::needless-lifetimes` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes error: this `if` has identical blocks --> src/shims/posix/sync.rs:503:75 | 503 | } else if kind == this.eval_libc("PTHREAD_MUTEX_ERRORCHECK")? { | ___________________________________________________________________________^ 504 | | this.eval_libc_i32("EPERM") 505 | | } else if kind == this.eval_libc("PTHREAD_MUTEX_RECURSIVE")? { | |_____________^ | = note: `-D clippy::if-same-then-else` implied by `-D clippy::all` note: same as this --> src/shims/posix/sync.rs:505:74 | 505 | } else if kind == this.eval_libc("PTHREAD_MUTEX_RECURSIVE")? { | __________________________________________________________________________^ 506 | | this.eval_libc_i32("EPERM") 507 | | } else { | |_____________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else error: this `if` has identical blocks --> src/shims/posix/sync.rs:610:57 | 610 | if this.rwlock_reader_unlock(id, active_thread) { | _________________________________________________________^ 611 | | Ok(0) 612 | | } else if this.rwlock_writer_unlock(id, active_thread) { | |_________^ | note: same as this --> src/shims/posix/sync.rs:612:64 | 612 | } else if this.rwlock_writer_unlock(id, active_thread) { | ________________________________________________________________^ 613 | | Ok(0) 614 | | } else { | |_________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else error: useless use of `format!` --> src/stacked_borrows.rs:228:14 | 228 | url: format!( | ______________^ 229 | | "https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md" 230 | | ), | |_________^ help: consider using `.to_string()`: `"https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format error: field assignment outside of initializer for an instance created with Default::default() --> src/thread.rs:234:9 | 234 | main_thread.join_status = ThreadJoinStatus::Detached; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::field-reassign-with-default` implied by `-D clippy::all` note: consider initializing the variable with `Thread::<'_, '_> { join_status: ThreadJoinStatus::Detached, ..Default::default() }` and removing relevant reassignments --> src/thread.rs:232:9 | 232 | let mut main_thread = Thread::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default error: `if` chain can be rewritten with `match` --> src/vector_clock.rs:224:17 | 224 | / if l > r { 225 | | return false; 226 | | } else if l < r { 227 | | equal = false; 228 | | } | |_________________^ | = note: `-D clippy::comparison-chain` implied by `-D clippy::all` = help: consider rewriting the `if` chain to use `cmp` and `match` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain error: `if` chain can be rewritten with `match` --> src/vector_clock.rs:278:17 | 278 | / if l < r { 279 | | return false; 280 | | } else if l > r { 281 | | equal = false; 282 | | } | |_________________^ | = help: consider rewriting the `if` chain to use `cmp` and `match` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain error: manual `RangeInclusive::contains` implementation --> src/bin/miri.rs:473:37 | 473 | Ok(rate) if rate >= 0.0 && rate <= 1.0 => rate, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(0.0..=1.0).contains(&rate)` | = note: `-D clippy::manual-range-contains` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains ``` </details>
2 parents 0fce9f4 + 96036c6 commit c9407f8

18 files changed

+80
-70
lines changed

src/bin/miri.rs

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

34
extern crate rustc_data_structures;
45
extern crate rustc_driver;

src/data_race.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
562562

563563
this.allow_data_races_mut(|this| this.write_immediate(**new_val, &(*place).into()))?;
564564

565-
this.validate_atomic_rmw(&place, atomic)?;
565+
this.validate_atomic_rmw(place, atomic)?;
566566

567567
// Return the old value.
568568
Ok(old)
@@ -784,7 +784,7 @@ impl VClockAlloc {
784784
None
785785
}
786786
})
787-
.map(|idx| VectorIdx::new(idx))
787+
.map(VectorIdx::new)
788788
}
789789

790790
/// Report a data-race found in the program.
@@ -1410,7 +1410,7 @@ impl GlobalState {
14101410
/// incremented.
14111411
pub fn validate_lock_acquire(&self, lock: &VClock, thread: ThreadId) {
14121412
let (_, mut clocks) = self.load_thread_state_mut(thread);
1413-
clocks.clock.join(&lock);
1413+
clocks.clock.join(lock);
14141414
}
14151415

14161416
/// Release a lock handle, express that this happens-before

src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn report_msg<'mir, 'tcx>(
296296
// Show help messages.
297297
if !helps.is_empty() {
298298
// Add visual separator before backtrace.
299-
helps.last_mut().unwrap().1.push_str("\n");
299+
helps.last_mut().unwrap().1.push('\n');
300300
for (span_data, help) in helps {
301301
if let Some(span_data) = span_data {
302302
err.span_help(span_data.span(), &help);

src/helpers.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ const UNIX_IO_ERROR_TABLE: &[(std::io::ErrorKind, &str)] = {
4343
};
4444

4545
/// Gets an instance for a path.
46-
fn try_resolve_did<'mir, 'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
46+
fn try_resolve_did<'tcx>(tcx: TyCtxt<'tcx>, path: &[&str]) -> Option<DefId> {
4747
tcx.crates(()).iter().find(|&&krate| tcx.crate_name(krate).as_str() == path[0]).and_then(
4848
|krate| {
4949
let krate = DefId { krate: *krate, index: CRATE_DEF_INDEX };
5050
let mut items = tcx.module_children(krate);
5151
let mut path_it = path.iter().skip(1).peekable();
5252

5353
while let Some(segment) = path_it.next() {
54-
for item in mem::replace(&mut items, Default::default()).iter() {
54+
for item in mem::take(&mut items).iter() {
5555
if item.ident.name.as_str() == *segment {
5656
if path_it.peek().is_none() {
5757
return Some(item.res.def_id());
@@ -83,7 +83,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8383
let cid = GlobalId { instance, promoted: None };
8484
let const_val = this.eval_to_allocation(cid)?;
8585
let const_val = this.read_scalar(&const_val.into())?;
86-
return Ok(const_val.check_init()?);
86+
const_val.check_init()
8787
}
8888

8989
/// Helper function to get a `libc` constant as a `Scalar`.
@@ -196,7 +196,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
196196
/// Get the `Place` for a local
197197
fn local_place(&mut self, local: mir::Local) -> InterpResult<'tcx, PlaceTy<'tcx, Tag>> {
198198
let this = self.eval_context_mut();
199-
let place = mir::Place { local: local, projection: List::empty() };
199+
let place = mir::Place { local, projection: List::empty() };
200200
this.eval_place(place)
201201
}
202202

@@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
323323
trace!("unsafe_cell_action on {:?}", place.ptr);
324324
// We need a size to go on.
325325
let unsafe_cell_size = this
326-
.size_and_align_of_mplace(&place)?
326+
.size_and_align_of_mplace(place)?
327327
.map(|(size, _)| size)
328328
// for extern types, just cover what we can
329329
.unwrap_or_else(|| place.layout.size);
@@ -362,7 +362,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
362362

363363
#[inline(always)]
364364
fn ecx(&self) -> &MiriEvalContext<'mir, 'tcx> {
365-
&self.ecx
365+
self.ecx
366366
}
367367

368368
// Hook to detect `UnsafeCell`.
@@ -631,10 +631,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
631631
/// `EINVAL` in this case.
632632
fn read_timespec(&mut self, tp: &MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx, Option<Duration>> {
633633
let this = self.eval_context_mut();
634-
let seconds_place = this.mplace_field(&tp, 0)?;
634+
let seconds_place = this.mplace_field(tp, 0)?;
635635
let seconds_scalar = this.read_scalar(&seconds_place.into())?;
636636
let seconds = seconds_scalar.to_machine_isize(this)?;
637-
let nanoseconds_place = this.mplace_field(&tp, 1)?;
637+
let nanoseconds_place = this.mplace_field(tp, 1)?;
638638
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place.into())?;
639639
let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?;
640640

@@ -664,18 +664,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
664664
loop {
665665
// FIXME: We are re-getting the allocation each time around the loop.
666666
// Would be nice if we could somehow "extend" an existing AllocRange.
667-
let alloc =
668-
this.get_ptr_alloc(ptr.offset(len, this)?.into(), size1, Align::ONE)?.unwrap(); // not a ZST, so we will get a result
667+
let alloc = this.get_ptr_alloc(ptr.offset(len, this)?, size1, Align::ONE)?.unwrap(); // not a ZST, so we will get a result
669668
let byte = alloc.read_scalar(alloc_range(Size::ZERO, size1))?.to_u8()?;
670669
if byte == 0 {
671670
break;
672671
} else {
673-
len = len + size1;
672+
len += size1;
674673
}
675674
}
676675

677676
// Step 2: get the bytes.
678-
this.read_bytes_ptr(ptr.into(), len)
677+
this.read_bytes_ptr(ptr, len)
679678
}
680679

681680
fn read_wide_str(&self, mut ptr: Pointer<Option<Tag>>) -> InterpResult<'tcx, Vec<u16>> {
@@ -687,7 +686,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
687686
loop {
688687
// FIXME: We are re-getting the allocation each time around the loop.
689688
// Would be nice if we could somehow "extend" an existing AllocRange.
690-
let alloc = this.get_ptr_alloc(ptr.into(), size2, align2)?.unwrap(); // not a ZST, so we will get a result
689+
let alloc = this.get_ptr_alloc(ptr, size2, align2)?.unwrap(); // not a ZST, so we will get a result
691690
let wchar = alloc.read_scalar(alloc_range(Size::ZERO, size2))?.to_u16()?;
692691
if wchar == 0 {
693692
break;
@@ -731,7 +730,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
731730
// message is slightly different here to make automated analysis easier
732731
let error_msg = format!("unsupported Miri functionality: {}", error_msg.as_ref());
733732
this.start_panic(error_msg.as_ref(), StackPopUnwind::Skip)?;
734-
return Ok(());
733+
Ok(())
735734
} else {
736735
throw_unsup_format!("{}", error_msg.as_ref());
737736
}
@@ -802,7 +801,7 @@ pub fn get_local_crates(tcx: &TyCtxt<'_>) -> Vec<CrateNum> {
802801
// Convert the local crate names from the passed-in config into CrateNums so that they can
803802
// be looked up quickly during execution
804803
let local_crate_names = std::env::var("MIRI_LOCAL_CRATES")
805-
.map(|crates| crates.split(",").map(|krate| krate.to_string()).collect::<Vec<_>>())
804+
.map(|crates| crates.split(',').map(|krate| krate.to_string()).collect::<Vec<_>>())
806805
.unwrap_or_default();
807806
let mut local_crates = Vec::new();
808807
for &crate_num in tcx.crates(()) {

src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77
#![feature(bool_to_option)]
88
#![feature(io_error_more)]
99
#![warn(rust_2018_idioms)]
10-
#![allow(clippy::cast_lossless)]
10+
#![allow(
11+
clippy::cast_lossless,
12+
clippy::collapsible_else_if,
13+
clippy::collapsible_if,
14+
clippy::comparison_chain,
15+
clippy::enum_variant_names,
16+
clippy::field_reassign_with_default,
17+
clippy::from_over_into,
18+
clippy::if_same_then_else,
19+
clippy::manual_map,
20+
clippy::needless_lifetimes,
21+
clippy::new_without_default,
22+
clippy::single_match,
23+
clippy::useless_format
24+
)]
1125

1226
extern crate rustc_apfloat;
1327
extern crate rustc_ast;

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
544544
def_id: DefId,
545545
) -> InterpResult<'tcx, Pointer<Tag>> {
546546
let attrs = ecx.tcx.get_attrs(def_id);
547-
let link_name = match ecx.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) {
547+
let link_name = match ecx.tcx.sess.first_attr_value_str_by_name(attrs, sym::link_name) {
548548
Some(name) => name,
549549
None => ecx.tcx.item_name(def_id),
550550
};
@@ -573,7 +573,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
573573
None
574574
};
575575
let race_alloc = if let Some(data_race) = &ecx.machine.data_race {
576-
Some(data_race::AllocExtra::new_allocation(&data_race, alloc.size(), kind))
576+
Some(data_race::AllocExtra::new_allocation(data_race, alloc.size(), kind))
577577
} else {
578578
None
579579
};

src/range_map.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<T> RangeMap<T> {
6363
/// through interior mutability.
6464
///
6565
/// The iterator also provides the offset of the given element.
66-
pub fn iter<'a>(&'a self, offset: Size, len: Size) -> impl Iterator<Item = (Size, &'a T)> + 'a {
66+
pub fn iter(&self, offset: Size, len: Size) -> impl Iterator<Item = (Size, &T)> {
6767
let offset = offset.bytes();
6868
let len = len.bytes();
6969
// Compute a slice starting with the elements we care about.
@@ -83,7 +83,7 @@ impl<T> RangeMap<T> {
8383
.map(|elem| (Size::from_bytes(elem.range.start), &elem.data))
8484
}
8585

86-
pub fn iter_mut_all<'a>(&'a mut self) -> impl Iterator<Item = &'a mut T> + 'a {
86+
pub fn iter_mut_all(&mut self) -> impl Iterator<Item = &mut T> {
8787
self.v.iter_mut().map(|elem| &mut elem.data)
8888
}
8989

@@ -110,7 +110,7 @@ impl<T> RangeMap<T> {
110110
// Copy the data, and insert second element.
111111
let second = Elem { range: second_range, data: elem.data.clone() };
112112
self.v.insert(index + 1, second);
113-
return true;
113+
true
114114
}
115115

116116
/// Provides mutable iteration over everything in the given range. As a side-effect,
@@ -119,11 +119,7 @@ impl<T> RangeMap<T> {
119119
/// Moreover, this will opportunistically merge neighbouring equal blocks.
120120
///
121121
/// The iterator also provides the offset of the given element.
122-
pub fn iter_mut<'a>(
123-
&'a mut self,
124-
offset: Size,
125-
len: Size,
126-
) -> impl Iterator<Item = (Size, &'a mut T)> + 'a
122+
pub fn iter_mut(&mut self, offset: Size, len: Size) -> impl Iterator<Item = (Size, &mut T)>
127123
where
128124
T: Clone + PartialEq,
129125
{

src/shims/env.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl<'tcx> EnvVars<'tcx> {
5050
if ecx.machine.communicate() || !config.forwarded_env_vars.is_empty() {
5151
for (name, value) in env::vars_os() {
5252
let forward = match ecx.machine.communicate() {
53-
true => !excluded_env_vars.iter().any(|v| v.as_str() == &name),
54-
false => config.forwarded_env_vars.iter().any(|v| v.as_str() == &name),
53+
true => !excluded_env_vars.iter().any(|v| **v == name),
54+
false => config.forwarded_env_vars.iter().any(|v| **v == name),
5555
};
5656
if forward {
5757
let var_ptr = match target_os {
@@ -64,7 +64,7 @@ impl<'tcx> EnvVars<'tcx> {
6464
unsupported
6565
),
6666
};
67-
ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr);
67+
ecx.machine.env_vars.map.insert(name, var_ptr);
6868
}
6969
}
7070
}
@@ -210,7 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
210210
name_op: &OpTy<'tcx, Tag>,
211211
value_op: &OpTy<'tcx, Tag>,
212212
) -> InterpResult<'tcx, i32> {
213-
let mut this = self.eval_context_mut();
213+
let this = self.eval_context_mut();
214214
let target_os = &this.tcx.sess.target.os;
215215
assert!(
216216
target_os == "linux" || target_os == "macos",
@@ -229,7 +229,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
229229
}
230230
}
231231
if let Some((name, value)) = new {
232-
let var_ptr = alloc_env_var_as_c_str(&name, &value, &mut this)?;
232+
let var_ptr = alloc_env_var_as_c_str(&name, &value, this)?;
233233
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
234234
this.deallocate_ptr(var, None, MiriMemoryKind::Runtime.into())?;
235235
}
@@ -249,7 +249,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
249249
name_op: &OpTy<'tcx, Tag>, // LPCWSTR
250250
value_op: &OpTy<'tcx, Tag>, // LPCWSTR
251251
) -> InterpResult<'tcx, i32> {
252-
let mut this = self.eval_context_mut();
252+
let this = self.eval_context_mut();
253253
this.assert_target_os("windows", "SetEnvironmentVariableW");
254254

255255
let name_ptr = this.read_pointer(name_op)?;
@@ -274,7 +274,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274274
Ok(1) // return non-zero on success
275275
} else {
276276
let value = this.read_os_str_from_wide_str(value_ptr)?;
277-
let var_ptr = alloc_env_var_as_wide_str(&name, &value, &mut this)?;
277+
let var_ptr = alloc_env_var_as_wide_str(&name, &value, this)?;
278278
if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) {
279279
this.deallocate_ptr(var, None, MiriMemoryKind::Runtime.into())?;
280280
}
@@ -325,8 +325,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
325325
"`getcwd` is only available for the UNIX target family"
326326
);
327327

328-
let buf = this.read_pointer(&buf_op)?;
329-
let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?;
328+
let buf = this.read_pointer(buf_op)?;
329+
let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?;
330330

331331
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
332332
this.reject_in_isolation("`getcwd`", reject_with)?;

src/shims/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
238238
let link_name = this
239239
.tcx
240240
.sess
241-
.first_attr_value_str_by_name(&attrs, sym::link_name)
241+
.first_attr_value_str_by_name(attrs, sym::link_name)
242242
.unwrap_or_else(|| this.tcx.item_name(def_id));
243243
let tcx = this.tcx.tcx;
244244

src/shims/intrinsics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
775775

776776
for i in 0..dest_len {
777777
let src_index: u64 = this
778-
.read_immediate(&this.operand_index(&index, i)?.into())?
778+
.read_immediate(&this.operand_index(index, i)?)?
779779
.to_scalar()?
780780
.to_u32()?
781781
.into();
@@ -1192,12 +1192,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
11921192
match atomic_op {
11931193
AtomicOp::Min => {
11941194
let old = this.atomic_min_max_scalar(&place, rhs, true, atomic)?;
1195-
this.write_immediate(*old, &dest)?; // old value is returned
1195+
this.write_immediate(*old, dest)?; // old value is returned
11961196
Ok(())
11971197
}
11981198
AtomicOp::Max => {
11991199
let old = this.atomic_min_max_scalar(&place, rhs, false, atomic)?;
1200-
this.write_immediate(*old, &dest)?; // old value is returned
1200+
this.write_immediate(*old, dest)?; // old value is returned
12011201
Ok(())
12021202
}
12031203
AtomicOp::MirOp(op, neg) => {

src/shims/os_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7878
Ok(OsString::from_wide(&u16_vec[..]))
7979
}
8080
#[cfg(not(windows))]
81-
pub fn u16vec_to_osstring<'tcx, 'a>(u16_vec: Vec<u16>) -> InterpResult<'tcx, OsString> {
81+
pub fn u16vec_to_osstring<'tcx>(u16_vec: Vec<u16>) -> InterpResult<'tcx, OsString> {
8282
let s = String::from_utf16(&u16_vec[..])
8383
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-16 string", u16_vec))?;
8484
Ok(s.into())

src/shims/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5959

6060
// Jump to the unwind block to begin unwinding.
6161
this.unwind_to_block(unwind)?;
62-
return Ok(());
62+
Ok(())
6363
}
6464

6565
/// Handles the `try` intrinsic, the underlying implementation of `std::panicking::try`.
@@ -112,7 +112,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
112112
Some(CatchUnwindData { catch_fn, data, dest: *dest, ret });
113113
}
114114

115-
return Ok(());
115+
Ok(())
116116
}
117117

118118
fn handle_stack_pop(

0 commit comments

Comments
 (0)