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
This commit is contained in:
David Tolnay 2022-04-29 15:40:28 -07:00
parent 16c2400737
commit 2ca7f3b45d
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
8 changed files with 24 additions and 25 deletions

View file

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

View file

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

View file

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

View file

@ -544,7 +544,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
def_id: DefId,
) -> InterpResult<'tcx, Pointer<Tag>> {
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
};

View file

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

View file

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

View file

@ -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) => {

View file

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