From d35c82f79f343fa0d0c0c352e9f43a74c2b6513e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Apr 2022 15:59:42 -0700 Subject: [PATCH] Resolve clippy::useless_conversion error: useless conversion to the same type: `rustc_const_eval::interpret::Pointer>` --> src/helpers.rs:668:36 | 668 | this.get_ptr_alloc(ptr.offset(len, this)?.into(), size1, Align::ONE)?.unwrap(); // not a ZST, so we will get a result | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `ptr.offset(len, this)?` | = note: `-D clippy::useless-conversion` implied by `-D clippy::all` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `rustc_const_eval::interpret::Pointer>` --> src/helpers.rs:678:29 | 678 | this.read_bytes_ptr(ptr.into(), len) | ^^^^^^^^^^ help: consider removing `.into()`: `ptr` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `rustc_const_eval::interpret::Pointer>` --> src/helpers.rs:690:44 | 690 | let alloc = this.get_ptr_alloc(ptr.into(), size2, align2)?.unwrap(); // not a ZST, so we will get a result | ^^^^^^^^^^ help: consider removing `.into()`: `ptr` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `rustc_const_eval::interpret::OpTy` --> src/shims/intrinsics.rs:778:42 | 778 | .read_immediate(&this.operand_index(index, i)?.into())? | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `this.operand_index(index, i)?` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `u32` --> src/shims/posix/fs.rs:1171:26 | 1171 | builder.mode(mode.into()); | ^^^^^^^^^^^ help: consider removing `.into()`: `mode` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `std::ffi::OsString` --> src/shims/env.rs:67:53 | 67 | ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing `OsString::from()`: `name` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `rustc_const_eval::interpret::Scalar` --> src/shims/tls.rs:102:44 | 102 | Ok(value.unwrap_or_else(|| Scalar::null_ptr(cx).into())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `Scalar::null_ptr(cx)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion error: useless conversion to the same type: `u32` --> src/thread.rs:73:26 | 73 | Scalar::from_u32(u32::try_from(self.0).unwrap()) | ^^^^^^^^^^^^^^^^^^^^^ | = help: consider removing `u32::try_from()` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion --- src/helpers.rs | 7 +++---- src/lib.rs | 1 - src/shims/env.rs | 2 +- src/shims/intrinsics.rs | 2 +- src/shims/posix/fs.rs | 2 +- src/shims/tls.rs | 2 +- src/thread.rs | 2 +- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 34156c54b43..107a2551995 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -664,8 +664,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx loop { // FIXME: We are re-getting the allocation each time around the loop. // Would be nice if we could somehow "extend" an existing AllocRange. - let alloc = - this.get_ptr_alloc(ptr.offset(len, this)?.into(), size1, Align::ONE)?.unwrap(); // not a ZST, so we will get a result + let alloc = this.get_ptr_alloc(ptr.offset(len, this)?, size1, Align::ONE)?.unwrap(); // not a ZST, so we will get a result let byte = alloc.read_scalar(alloc_range(Size::ZERO, size1))?.to_u8()?; if byte == 0 { break; @@ -675,7 +674,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } // Step 2: get the bytes. - this.read_bytes_ptr(ptr.into(), len) + this.read_bytes_ptr(ptr, len) } fn read_wide_str(&self, mut ptr: Pointer>) -> InterpResult<'tcx, Vec> { @@ -687,7 +686,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx loop { // FIXME: We are re-getting the allocation each time around the loop. // Would be nice if we could somehow "extend" an existing AllocRange. - let alloc = this.get_ptr_alloc(ptr.into(), size2, align2)?.unwrap(); // not a ZST, so we will get a result + let alloc = this.get_ptr_alloc(ptr, size2, align2)?.unwrap(); // not a ZST, so we will get a result let wchar = alloc.read_scalar(alloc_range(Size::ZERO, size2))?.to_u16()?; if wchar == 0 { break; diff --git a/src/lib.rs b/src/lib.rs index 8e21294fd8d..0699dfba4b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ clippy::needless_lifetimes, clippy::new_without_default, clippy::single_match, - clippy::useless_conversion, clippy::useless_format )] diff --git a/src/shims/env.rs b/src/shims/env.rs index 34a716f08ab..ae9b8c75145 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -64,7 +64,7 @@ impl<'tcx> EnvVars<'tcx> { unsupported ), }; - ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr); + ecx.machine.env_vars.map.insert(name, var_ptr); } } } diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index 06537b5d333..b2c31f1c140 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)?)? .to_scalar()? .to_u32()? .into(); diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index f224a1461f9..a63b2ad80c2 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -1168,7 +1168,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx #[cfg(unix)] { use std::os::unix::fs::DirBuilderExt; - builder.mode(mode.into()); + builder.mode(mode); } let result = builder.create(path).map(|_| 0i32); diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 31a3e12b41b..3de739a8d04 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -99,7 +99,7 @@ impl<'tcx> TlsData<'tcx> { Some(TlsEntry { data, .. }) => { let value = data.get(&thread_id).copied(); trace!("TLS key {} for thread {:?} loaded: {:?}", key, thread_id, value); - Ok(value.unwrap_or_else(|| Scalar::null_ptr(cx).into())) + Ok(value.unwrap_or_else(|| Scalar::null_ptr(cx))) } None => throw_ub_format!("loading from a non-existing TLS key: {}", key), } diff --git a/src/thread.rs b/src/thread.rs index 031463f8ea7..8edd6672a74 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -70,7 +70,7 @@ impl From for ThreadId { impl ThreadId { pub fn to_u32_scalar(&self) -> Scalar { - Scalar::from_u32(u32::try_from(self.0).unwrap()) + Scalar::from_u32(self.0) } }