From 2ca7f3b45df176295d276ce50f7f32845c7f614d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Apr 2022 15:40:28 -0700 Subject: [PATCH] Resolve clippy::needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/data_race.rs:565:34 | 565 | this.validate_atomic_rmw(&place, atomic)?; | ^^^^^^ help: change this to: `place` | = note: `-D clippy::needless-borrow` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/data_race.rs:1413:27 | 1413 | clocks.clock.join(&lock); | ^^^^^ help: change this to: `lock` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/helpers.rs:326:51 | 326 | .size_and_align_of_mplace(&place)? | ^^^^^^ help: change this to: `place` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/helpers.rs:365:17 | 365 | &self.ecx | ^^^^^^^^^ help: change this to: `self.ecx` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/helpers.rs:634:47 | 634 | let seconds_place = this.mplace_field(&tp, 0)?; | ^^^ help: change this to: `tp` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/helpers.rs:637:51 | 637 | let nanoseconds_place = this.mplace_field(&tp, 1)?; | ^^^ help: change this to: `tp` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/machine.rs:547:73 | 547 | let link_name = match ecx.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) { | ^^^^^^ help: change this to: `attrs` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/machine.rs:576:56 | 576 | Some(data_race::AllocExtra::new_allocation(&data_race, alloc.size(), kind)) | ^^^^^^^^^^ help: change this to: `data_race` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/foreign_items.rs:241:43 | 241 | .first_attr_value_str_by_name(&attrs, sym::link_name) | ^^^^^^ help: change this to: `attrs` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/intrinsics.rs:778:61 | 778 | .read_immediate(&this.operand_index(&index, i)?.into())? | ^^^^^^ help: change this to: `index` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/intrinsics.rs:1195:44 | 1195 | this.write_immediate(*old, &dest)?; // old value is returned | ^^^^^ help: change this to: `dest` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/intrinsics.rs:1200:44 | 1200 | this.write_immediate(*old, &dest)?; // old value is returned | ^^^^^ help: change this to: `dest` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:54:12 | 54 | Ok(&self) | ^^^^^ help: change this to: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:654:49 | 654 | let io_result = maybe_sync_file(&file, *writable, File::sync_all); | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:746:52 | 746 | file_descriptor.write(communicate, &bytes)?.map(|c| i64::try_from(c).unwrap()); | ^^^^^^ help: change this to: `bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:1494:45 | 1494 | let io_result = maybe_sync_file(&file, *writable, File::sync_all); | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:1516:45 | 1516 | let io_result = maybe_sync_file(&file, *writable, File::sync_data); | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/posix/fs.rs:1561:45 | 1561 | let io_result = maybe_sync_file(&file, *writable, File::sync_data); | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/env.rs:232:65 | 232 | let var_ptr = alloc_env_var_as_c_str(&name, &value, &mut this)?; | ^^^^^^^^^ help: change this to: `this` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/env.rs:277:68 | 277 | let var_ptr = alloc_env_var_as_wide_str(&name, &value, &mut this)?; | ^^^^^^^^^ help: change this to: `this` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/env.rs:328:37 | 328 | let buf = this.read_pointer(&buf_op)?; | ^^^^^^^ help: change this to: `buf_op` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow error: this expression creates a reference which is immediately dereferenced by the compiler --> src/shims/env.rs:329:37 | 329 | let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?; | ^^^^^^^^ help: change this to: `size_op` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow --- src/data_race.rs | 4 ++-- src/helpers.rs | 8 ++++---- src/lib.rs | 1 - src/machine.rs | 4 ++-- src/shims/env.rs | 12 ++++++------ src/shims/foreign_items.rs | 2 +- src/shims/intrinsics.rs | 6 +++--- src/shims/posix/fs.rs | 12 ++++++------ 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index 7625763a3bb4..b2bd29c5cb19 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -562,7 +562,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { this.allow_data_races_mut(|this| this.write_immediate(**new_val, &(*place).into()))?; - this.validate_atomic_rmw(&place, atomic)?; + this.validate_atomic_rmw(place, atomic)?; // Return the old value. Ok(old) @@ -1410,7 +1410,7 @@ impl GlobalState { /// incremented. pub fn validate_lock_acquire(&self, lock: &VClock, thread: ThreadId) { let (_, mut clocks) = self.load_thread_state_mut(thread); - clocks.clock.join(&lock); + clocks.clock.join(lock); } /// Release a lock handle, express that this happens-before diff --git a/src/helpers.rs b/src/helpers.rs index 10dbd373786a..1d84b3fdf16e 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx trace!("unsafe_cell_action on {:?}", place.ptr); // We need a size to go on. let unsafe_cell_size = this - .size_and_align_of_mplace(&place)? + .size_and_align_of_mplace(place)? .map(|(size, _)| size) // for extern types, just cover what we can .unwrap_or_else(|| place.layout.size); @@ -362,7 +362,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx #[inline(always)] fn ecx(&self) -> &MiriEvalContext<'mir, 'tcx> { - &self.ecx + self.ecx } // Hook to detect `UnsafeCell`. @@ -631,10 +631,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx /// `EINVAL` in this case. fn read_timespec(&mut self, tp: &MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx, Option> { let this = self.eval_context_mut(); - let seconds_place = this.mplace_field(&tp, 0)?; + let seconds_place = this.mplace_field(tp, 0)?; let seconds_scalar = this.read_scalar(&seconds_place.into())?; let seconds = seconds_scalar.to_machine_isize(this)?; - let nanoseconds_place = this.mplace_field(&tp, 1)?; + let nanoseconds_place = this.mplace_field(tp, 1)?; let nanoseconds_scalar = this.read_scalar(&nanoseconds_place.into())?; let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?; diff --git a/src/lib.rs b/src/lib.rs index 5d2faac57d83..598d9cc96ae6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ clippy::from_over_into, clippy::if_same_then_else, clippy::manual_map, - clippy::needless_borrow, clippy::needless_lifetimes, clippy::needless_question_mark, clippy::needless_return, diff --git a/src/machine.rs b/src/machine.rs index c0f833f17610..0a8a229c8aa2 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -544,7 +544,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { def_id: DefId, ) -> InterpResult<'tcx, Pointer> { let attrs = ecx.tcx.get_attrs(def_id); - let link_name = match ecx.tcx.sess.first_attr_value_str_by_name(&attrs, sym::link_name) { + let link_name = match ecx.tcx.sess.first_attr_value_str_by_name(attrs, sym::link_name) { Some(name) => name, None => ecx.tcx.item_name(def_id), }; @@ -573,7 +573,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { None }; let race_alloc = if let Some(data_race) = &ecx.machine.data_race { - Some(data_race::AllocExtra::new_allocation(&data_race, alloc.size(), kind)) + Some(data_race::AllocExtra::new_allocation(data_race, alloc.size(), kind)) } else { None }; diff --git a/src/shims/env.rs b/src/shims/env.rs index 3b1b1f011e3e..915decc28725 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -210,7 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx name_op: &OpTy<'tcx, Tag>, value_op: &OpTy<'tcx, Tag>, ) -> InterpResult<'tcx, i32> { - let mut this = self.eval_context_mut(); + let this = self.eval_context_mut(); let target_os = &this.tcx.sess.target.os; assert!( target_os == "linux" || target_os == "macos", @@ -229,7 +229,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } } if let Some((name, value)) = new { - let var_ptr = alloc_env_var_as_c_str(&name, &value, &mut this)?; + let var_ptr = alloc_env_var_as_c_str(&name, &value, this)?; if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) { this.deallocate_ptr(var, None, MiriMemoryKind::Runtime.into())?; } @@ -249,7 +249,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx name_op: &OpTy<'tcx, Tag>, // LPCWSTR value_op: &OpTy<'tcx, Tag>, // LPCWSTR ) -> InterpResult<'tcx, i32> { - let mut this = self.eval_context_mut(); + let this = self.eval_context_mut(); this.assert_target_os("windows", "SetEnvironmentVariableW"); let name_ptr = this.read_pointer(name_op)?; @@ -274,7 +274,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Ok(1) // return non-zero on success } else { let value = this.read_os_str_from_wide_str(value_ptr)?; - let var_ptr = alloc_env_var_as_wide_str(&name, &value, &mut this)?; + let var_ptr = alloc_env_var_as_wide_str(&name, &value, this)?; if let Some(var) = this.machine.env_vars.map.insert(name, var_ptr) { this.deallocate_ptr(var, None, MiriMemoryKind::Runtime.into())?; } @@ -325,8 +325,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx "`getcwd` is only available for the UNIX target family" ); - let buf = this.read_pointer(&buf_op)?; - let size = this.read_scalar(&size_op)?.to_machine_usize(&*this.tcx)?; + let buf = this.read_pointer(buf_op)?; + let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?; if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op { this.reject_in_isolation("`getcwd`", reject_with)?; diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index ef88c550ecb2..9256013fb157 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -238,7 +238,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let link_name = this .tcx .sess - .first_attr_value_str_by_name(&attrs, sym::link_name) + .first_attr_value_str_by_name(attrs, sym::link_name) .unwrap_or_else(|| this.tcx.item_name(def_id)); let tcx = this.tcx.tcx; diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 1b69be5153b0..06537b5d333b 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -775,7 +775,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx for i in 0..dest_len { let src_index: u64 = this - .read_immediate(&this.operand_index(&index, i)?.into())? + .read_immediate(&this.operand_index(index, i)?.into())? .to_scalar()? .to_u32()? .into(); @@ -1192,12 +1192,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx match atomic_op { AtomicOp::Min => { let old = this.atomic_min_max_scalar(&place, rhs, true, atomic)?; - this.write_immediate(*old, &dest)?; // old value is returned + this.write_immediate(*old, dest)?; // old value is returned Ok(()) } AtomicOp::Max => { let old = this.atomic_min_max_scalar(&place, rhs, false, atomic)?; - this.write_immediate(*old, &dest)?; // old value is returned + this.write_immediate(*old, dest)?; // old value is returned Ok(()) } AtomicOp::MirOp(op, neg) => { diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index 93ca3c80198b..7957edf5c65e 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -51,7 +51,7 @@ trait FileDescriptor: std::fmt::Debug { impl FileDescriptor for FileHandle { fn as_file_handle<'tcx>(&self) -> InterpResult<'tcx, &FileHandle> { - Ok(&self) + Ok(self) } fn read<'tcx>( @@ -651,7 +651,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { // FIXME: Support fullfsync for all FDs let FileHandle { file, writable } = file_descriptor.as_file_handle()?; - let io_result = maybe_sync_file(&file, *writable, File::sync_all); + let io_result = maybe_sync_file(file, *writable, File::sync_all); this.try_unwrap_io_result(io_result) } else { this.handle_not_found() @@ -743,7 +743,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { let bytes = this.read_bytes_ptr(buf, Size::from_bytes(count))?; let result = - file_descriptor.write(communicate, &bytes)?.map(|c| i64::try_from(c).unwrap()); + file_descriptor.write(communicate, bytes)?.map(|c| i64::try_from(c).unwrap()); this.try_unwrap_io_result(result) } else { this.handle_not_found() @@ -1491,7 +1491,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { // FIXME: Support fsync for all FDs let FileHandle { file, writable } = file_descriptor.as_file_handle()?; - let io_result = maybe_sync_file(&file, *writable, File::sync_all); + let io_result = maybe_sync_file(file, *writable, File::sync_all); this.try_unwrap_io_result(io_result) } else { this.handle_not_found() @@ -1513,7 +1513,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { // FIXME: Support fdatasync for all FDs let FileHandle { file, writable } = file_descriptor.as_file_handle()?; - let io_result = maybe_sync_file(&file, *writable, File::sync_data); + let io_result = maybe_sync_file(file, *writable, File::sync_data); this.try_unwrap_io_result(io_result) } else { this.handle_not_found() @@ -1558,7 +1558,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) { // FIXME: Support sync_data_range for all FDs let FileHandle { file, writable } = file_descriptor.as_file_handle()?; - let io_result = maybe_sync_file(&file, *writable, File::sync_data); + let io_result = maybe_sync_file(file, *writable, File::sync_data); this.try_unwrap_io_result(io_result) } else { this.handle_not_found()