Skip to content

Commit 2ca7f3b

Browse files
committed
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
1 parent 16c2400 commit 2ca7f3b

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

src/data_race.rs

Lines changed: 2 additions & 2 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)
@@ -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/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
clippy::from_over_into,
1919
clippy::if_same_then_else,
2020
clippy::manual_map,
21-
clippy::needless_borrow,
2221
clippy::needless_lifetimes,
2322
clippy::needless_question_mark,
2423
clippy::needless_return,

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/shims/env.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)?.into())?
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/posix/fs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait FileDescriptor: std::fmt::Debug {
5151

5252
impl FileDescriptor for FileHandle {
5353
fn as_file_handle<'tcx>(&self) -> InterpResult<'tcx, &FileHandle> {
54-
Ok(&self)
54+
Ok(self)
5555
}
5656

5757
fn read<'tcx>(
@@ -651,7 +651,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
651651
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
652652
// FIXME: Support fullfsync for all FDs
653653
let FileHandle { file, writable } = file_descriptor.as_file_handle()?;
654-
let io_result = maybe_sync_file(&file, *writable, File::sync_all);
654+
let io_result = maybe_sync_file(file, *writable, File::sync_all);
655655
this.try_unwrap_io_result(io_result)
656656
} else {
657657
this.handle_not_found()
@@ -743,7 +743,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
743743
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
744744
let bytes = this.read_bytes_ptr(buf, Size::from_bytes(count))?;
745745
let result =
746-
file_descriptor.write(communicate, &bytes)?.map(|c| i64::try_from(c).unwrap());
746+
file_descriptor.write(communicate, bytes)?.map(|c| i64::try_from(c).unwrap());
747747
this.try_unwrap_io_result(result)
748748
} else {
749749
this.handle_not_found()
@@ -1491,7 +1491,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
14911491
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
14921492
// FIXME: Support fsync for all FDs
14931493
let FileHandle { file, writable } = file_descriptor.as_file_handle()?;
1494-
let io_result = maybe_sync_file(&file, *writable, File::sync_all);
1494+
let io_result = maybe_sync_file(file, *writable, File::sync_all);
14951495
this.try_unwrap_io_result(io_result)
14961496
} else {
14971497
this.handle_not_found()
@@ -1513,7 +1513,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
15131513
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
15141514
// FIXME: Support fdatasync for all FDs
15151515
let FileHandle { file, writable } = file_descriptor.as_file_handle()?;
1516-
let io_result = maybe_sync_file(&file, *writable, File::sync_data);
1516+
let io_result = maybe_sync_file(file, *writable, File::sync_data);
15171517
this.try_unwrap_io_result(io_result)
15181518
} else {
15191519
this.handle_not_found()
@@ -1558,7 +1558,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
15581558
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
15591559
// FIXME: Support sync_data_range for all FDs
15601560
let FileHandle { file, writable } = file_descriptor.as_file_handle()?;
1561-
let io_result = maybe_sync_file(&file, *writable, File::sync_data);
1561+
let io_result = maybe_sync_file(file, *writable, File::sync_data);
15621562
this.try_unwrap_io_result(io_result)
15631563
} else {
15641564
this.handle_not_found()

0 commit comments

Comments
 (0)