From 37967d9f40b723667f06855eb53bd9ba49586813 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 11 Apr 2023 19:20:58 +0900 Subject: [PATCH 01/15] unused_parens now fires on cast fix broken test refactor: replace bool params with single enum param bless add more test case fix lint implementation correct test case bless bless fix in test case fix in library add test case unused_parens now fires on cast --- compiler/rustc_lint/src/unused.rs | 66 ++++++- library/alloc/src/sync.rs | 2 +- library/core/src/num/dec2flt/number.rs | 2 +- library/core/src/num/dec2flt/parse.rs | 2 +- library/core/src/num/dec2flt/slow.rs | 2 +- library/std/src/io/buffered/bufreader.rs | 4 +- library/std/src/sys/unix/os.rs | 2 +- tests/ui/const-ptr/allowed_slices.rs | 6 +- tests/ui/consts/issue-27890.rs | 2 +- tests/ui/lint/unused_parens_cast.rs | 101 +++++++++++ tests/ui/lint/unused_parens_cast.stderr | 163 ++++++++++++++++++ ...ethod-not-found-generic-arg-elision.stderr | 2 + .../ui/mismatched_types/issue-36053-2.stderr | 1 + .../saturating-float-casts-impl.rs | 18 +- tests/ui/traits/region-pointer-simple.rs | 2 +- tests/ui/typeck/issue-31173.stderr | 1 + 16 files changed, 346 insertions(+), 30 deletions(-) create mode 100644 tests/ui/lint/unused_parens_cast.rs create mode 100644 tests/ui/lint/unused_parens_cast.stderr diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 9861610612fb0..f4531c4d6c118 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -572,6 +572,7 @@ enum UnusedDelimsCtx { AnonConst, MatchArmExpr, IndexExpr, + CastExpr, } impl From for &'static str { @@ -592,10 +593,18 @@ impl From for &'static str { UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression", UnusedDelimsCtx::MatchArmExpr => "match arm expression", UnusedDelimsCtx::IndexExpr => "index expression", + UnusedDelimsCtx::CastExpr => "cast expression", } } } +#[derive(Copy, Clone, Eq, PartialEq)] +enum UnusedDelimCtxFollowedTokenKind { + Block, + Else, + Cast, +} + /// Used by both `UnusedParens` and `UnusedBraces` to prevent code duplication. trait UnusedDelimLint { const DELIM_STR: &'static str; @@ -629,9 +638,14 @@ trait UnusedDelimLint { fn is_expr_delims_necessary( inner: &ast::Expr, - followed_by_block: bool, - followed_by_else: bool, + followed_token: Option, ) -> bool { + let followed_by_block = + matches!(followed_token, Some(UnusedDelimCtxFollowedTokenKind::Block)); + let followed_by_else = + matches!(followed_token, Some(UnusedDelimCtxFollowedTokenKind::Else)); + let followed_by_cast = + matches!(followed_token, Some(UnusedDelimCtxFollowedTokenKind::Cast)); if followed_by_else { match inner.kind { ast::ExprKind::Binary(op, ..) if op.node.lazy() => return true, @@ -640,6 +654,20 @@ trait UnusedDelimLint { } } + if followed_by_cast { + match inner.kind { + // `as` has higher precedence than any binary operator + ast::ExprKind::Binary(..) + // #88519 + | ast::ExprKind::Block(..) + | ast::ExprKind::Match(..) + | ast::ExprKind::If(..) + // #51185 + | ast::ExprKind::Closure(..) => return true, + _ => {} + } + } + // Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`. { let mut innermost = inner; @@ -964,9 +992,18 @@ impl UnusedDelimLint for UnusedParens { ) { match value.kind { ast::ExprKind::Paren(ref inner) => { - let followed_by_else = ctx == UnusedDelimsCtx::AssignedValueLetElse; - if !Self::is_expr_delims_necessary(inner, followed_by_block, followed_by_else) - && value.attrs.is_empty() + if !Self::is_expr_delims_necessary( + inner, + if followed_by_block { + Some(UnusedDelimCtxFollowedTokenKind::Block) + } else if ctx == UnusedDelimsCtx::AssignedValueLetElse { + Some(UnusedDelimCtxFollowedTokenKind::Else) + } else if ctx == UnusedDelimsCtx::CastExpr { + Some(UnusedDelimCtxFollowedTokenKind::Cast) + } else { + None + }, + ) && value.attrs.is_empty() && !value.span.from_expansion() && (ctx != UnusedDelimsCtx::LetScrutineeExpr || !matches!(inner.kind, ast::ExprKind::Binary( @@ -989,6 +1026,15 @@ impl UnusedDelimLint for UnusedParens { false, ); } + ast::ExprKind::Cast(ref expr, _) => self.check_unused_delims_expr( + cx, + expr, + UnusedDelimsCtx::CastExpr, + followed_by_block, + None, + None, + ), + _ => {} } } @@ -1248,10 +1294,12 @@ impl UnusedDelimLint for UnusedBraces { // FIXME(const_generics): handle paths when #67075 is fixed. if let [stmt] = inner.stmts.as_slice() { if let ast::StmtKind::Expr(ref expr) = stmt.kind { - if !Self::is_expr_delims_necessary(expr, followed_by_block, false) - && (ctx != UnusedDelimsCtx::AnonConst - || (matches!(expr.kind, ast::ExprKind::Lit(_)) - && !expr.span.from_expansion())) + if !Self::is_expr_delims_necessary( + expr, + followed_by_block.then_some(UnusedDelimCtxFollowedTokenKind::Block), + ) && (ctx != UnusedDelimsCtx::AnonConst + || (matches!(expr.kind, ast::ExprKind::Lit(_)) + && !expr.span.from_expansion())) && !cx.sess().source_map().is_multiline(value.span) && value.attrs.is_empty() && !value.span.from_expansion() diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index d2c87cf705c61..5d5de88d3009f 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -55,7 +55,7 @@ mod tests; /// This is a global invariant, and also applies when using a compare-exchange loop. /// /// See comment in `Arc::clone`. -const MAX_REFCOUNT: usize = (isize::MAX) as usize; +const MAX_REFCOUNT: usize = isize::MAX as usize; /// The error in case either counter reaches above `MAX_REFCOUNT`, and we can `panic` safely. const INTERNAL_OVERFLOW_ERROR: &str = "Arc counter overflow"; diff --git a/library/core/src/num/dec2flt/number.rs b/library/core/src/num/dec2flt/number.rs index 8589e2bbd4fac..4ac0113be4bfa 100644 --- a/library/core/src/num/dec2flt/number.rs +++ b/library/core/src/num/dec2flt/number.rs @@ -63,7 +63,7 @@ impl Number { // normal fast path let value = F::from_u64(self.mantissa); if self.exponent < 0 { - value / F::pow10_fast_path((-self.exponent) as _) + value / F::pow10_fast_path(-self.exponent as _) } else { value * F::pow10_fast_path(self.exponent as _) } diff --git a/library/core/src/num/dec2flt/parse.rs b/library/core/src/num/dec2flt/parse.rs index b0a23835c5bd4..44838e3974b88 100644 --- a/library/core/src/num/dec2flt/parse.rs +++ b/library/core/src/num/dec2flt/parse.rs @@ -22,7 +22,7 @@ fn parse_8digits(mut v: u64) -> u64 { v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits let v1 = (v & MASK).wrapping_mul(MUL1); let v2 = ((v >> 16) & MASK).wrapping_mul(MUL2); - ((v1.wrapping_add(v2) >> 32) as u32) as u64 + (v1.wrapping_add(v2) >> 32) as u32 as u64 } /// Parse digits until a non-digit character is found. diff --git a/library/core/src/num/dec2flt/slow.rs b/library/core/src/num/dec2flt/slow.rs index bf1044033e69e..aa27878fd66d9 100644 --- a/library/core/src/num/dec2flt/slow.rs +++ b/library/core/src/num/dec2flt/slow.rs @@ -64,7 +64,7 @@ pub(crate) fn parse_long_mantissa(s: &[u8]) -> BiasedFp { _ => 1, } } else { - get_shift((-d.decimal_point) as _) + get_shift(-d.decimal_point as _) }; d.left_shift(shift); if d.decimal_point > Decimal::DECIMAL_POINT_RANGE { diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index a66e6ccf67312..6868bb943acff 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -244,8 +244,8 @@ impl BufReader { pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { let pos = self.buf.pos() as u64; if offset < 0 { - if let Some(_) = pos.checked_sub((-offset) as u64) { - self.buf.unconsume((-offset) as usize); + if let Some(_) = pos.checked_sub(-offset as u64) { + self.buf.unconsume(-offset as usize); return Ok(()); } } else if let Some(new_pos) = pos.checked_add(offset as u64) { diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 8edfd33130442..7f5dbc2acc2f8 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -73,7 +73,7 @@ extern "C" { /// Returns the platform-specific value of errno #[cfg(not(any(target_os = "dragonfly", target_os = "vxworks")))] pub fn errno() -> i32 { - unsafe { (*errno_location()) as i32 } + unsafe { *errno_location() as i32 } } /// Sets the platform-specific value of errno diff --git a/tests/ui/const-ptr/allowed_slices.rs b/tests/ui/const-ptr/allowed_slices.rs index 3f19cd4d8046d..1e55a5fa48c00 100644 --- a/tests/ui/const-ptr/allowed_slices.rs +++ b/tests/ui/const-ptr/allowed_slices.rs @@ -20,13 +20,13 @@ pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 1) }; pub static S3: &[MaybeUninit<&u32>] = unsafe { from_raw_parts(&D1, 1) }; // Reinterpreting data is fine, as long as layouts match -pub static S4: &[u8] = unsafe { from_raw_parts((&D0) as *const _ as _, 3) }; +pub static S4: &[u8] = unsafe { from_raw_parts(&D0 as *const _ as _, 3) }; // This is only valid because D1 has uninitialized bytes, if it was an initialized pointer, // that would reinterpret pointers as integers which is UB in CTFE. -pub static S5: &[MaybeUninit] = unsafe { from_raw_parts((&D1) as *const _ as _, 2) }; +pub static S5: &[MaybeUninit] = unsafe { from_raw_parts(&D1 as *const _ as _, 2) }; // Even though u32 and [bool; 4] have different layouts, D0 has a value that // is valid as [bool; 4], so this is not UB (it's basically a transmute) -pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; +pub static S6: &[bool] = unsafe { from_raw_parts(&D0 as *const _ as _, 4) }; // Structs are considered single allocated objects, // as long as you don't reinterpret padding as initialized diff --git a/tests/ui/consts/issue-27890.rs b/tests/ui/consts/issue-27890.rs index 9f85473380f82..133f151192a63 100644 --- a/tests/ui/consts/issue-27890.rs +++ b/tests/ui/consts/issue-27890.rs @@ -1,5 +1,5 @@ // run-pass -static PLUS_ONE: &'static (dyn Fn(i32) -> i32 + Sync) = (&|x: i32| { x + 1 }) +static PLUS_ONE: &'static (dyn Fn(i32) -> i32 + Sync) = &(|x: i32| { x + 1 }) as &'static (dyn Fn(i32) -> i32 + Sync); fn main() { diff --git a/tests/ui/lint/unused_parens_cast.rs b/tests/ui/lint/unused_parens_cast.rs new file mode 100644 index 0000000000000..fec677c4b9d66 --- /dev/null +++ b/tests/ui/lint/unused_parens_cast.rs @@ -0,0 +1,101 @@ +// check-pass + +#![warn(unused_parens)] + +struct Foo(f32); + +impl Foo { + pub fn f32(self) -> f32 { + 64.0f32 + } +} + +fn bar() -> f32 { + 3.0f32 +} + +mod inner { + pub mod yet_inner { + pub mod most_inner { + pub static VERY_LONG_PATH: f32 = 99.0f32; + } + } +} + +fn basic_test() { + // should fire + let one = 1.0f32; + let _ = (one) as f64; + //~^ WARN unnecessary parentheses around cast expression + let _ = (inner::yet_inner::most_inner::VERY_LONG_PATH) as f64; + //~^ WARN unnecessary parentheses around cast expression + let _ = (Foo(1.0f32).0) as f64; + //~^ WARN unnecessary parentheses around cast expression + let _ = (Foo(1.0f32).f32()) as f64; + //~^ WARN unnecessary parentheses around cast expression + let _ = (bar()) as f64; + //~^ WARN unnecessary parentheses around cast expression + let baz = [4.0f32]; + let _ = (baz[0]) as f64; + //~^ WARN unnecessary parentheses around cast expression + let _ = (-1.0f32) as f64; + //~^ WARN unnecessary parentheses around cast expression + let x = Box::new(-1.0f32); + let _ = (*x) as f64; + //~^ WARN unnecessary parentheses around cast expression + // cast is left-assoc + let _ = (true as u8) as u16; + //~^ WARN unnecessary parentheses around cast expression + // should not fire + let _ = (1.0f32 * 2.0f32) as f64; + let _ = (1.0f32 / 2.0f32) as f64; + let _ = (1.0f32 % 2.0f32) as f64; + let _ = (1.0f32 + 2.0f32) as f64; + let _ = (1.0f32 - 2.0f32) as f64; + let _ = (42 << 1) as i64; + let _ = (42 >> 1) as i64; + let _ = (42 & 0x1F) as f64; + let _ = (42 ^ 0x1F) as f64; + let _ = (42 | 0x1F) as f64; + let _ = (1.0f32 == 2.0f32) as u8; + let _ = (1.0f32 != 2.0f32) as u8; + let _ = (1.0f32 < 2.0f32) as u8; + let _ = (1.0f32 > 2.0f32) as u8; + let _ = (1.0f32 <= 2.0f32) as u8; + let _ = (1.0f32 >= 2.0f32) as u8; + let _ = (true && false) as u8; + let _ = (true || false) as u8; + // skipped range: `as`-cast does not allow non-primitive cast + // also skipped compound operator +} + +fn issue_88519() { + let _ = ({ 1 }) as i64; + let _ = (match 0 { x => x }) as i64; + let _ = (if true { 16 } else { 42 }) as i64; +} + +fn issue_51185() -> impl Into fn(&'a ())> { + // removing parens will change semantics, and make compile does not pass + (|_| {}) as for<'a> fn(&'a ()) +} + +fn issue_clippy_10557() { + let x = 0f32; + let y = 0f32; + let width = 100f32; + let height = 100f32; + + new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); + //~^ WARN unnecessary parentheses around cast expression + //~^^ WARN unnecessary parentheses around cast expression + //~^^^ WARN unnecessary parentheses around cast expression + //~^^^^ WARN unnecessary parentheses around cast expression +} + +fn new_rect(x: f64, y: f64, width: f64, height: f64) { + +} + +fn main() { +} diff --git a/tests/ui/lint/unused_parens_cast.stderr b/tests/ui/lint/unused_parens_cast.stderr new file mode 100644 index 0000000000000..6a078a9e499aa --- /dev/null +++ b/tests/ui/lint/unused_parens_cast.stderr @@ -0,0 +1,163 @@ +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:28:13 + | +LL | let _ = (one) as f64; + | ^ ^ + | +note: the lint level is defined here + --> $DIR/unused_parens_cast.rs:3:9 + | +LL | #![warn(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let _ = (one) as f64; +LL + let _ = one as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:30:13 + | +LL | let _ = (inner::yet_inner::most_inner::VERY_LONG_PATH) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (inner::yet_inner::most_inner::VERY_LONG_PATH) as f64; +LL + let _ = inner::yet_inner::most_inner::VERY_LONG_PATH as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:32:13 + | +LL | let _ = (Foo(1.0f32).0) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (Foo(1.0f32).0) as f64; +LL + let _ = Foo(1.0f32).0 as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:34:13 + | +LL | let _ = (Foo(1.0f32).f32()) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (Foo(1.0f32).f32()) as f64; +LL + let _ = Foo(1.0f32).f32() as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:36:13 + | +LL | let _ = (bar()) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (bar()) as f64; +LL + let _ = bar() as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:39:13 + | +LL | let _ = (baz[0]) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (baz[0]) as f64; +LL + let _ = baz[0] as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:41:13 + | +LL | let _ = (-1.0f32) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (-1.0f32) as f64; +LL + let _ = -1.0f32 as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:44:13 + | +LL | let _ = (*x) as f64; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (*x) as f64; +LL + let _ = *x as f64; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:47:13 + | +LL | let _ = (true as u8) as u16; + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = (true as u8) as u16; +LL + let _ = true as u8 as u16; + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:89:14 + | +LL | new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); + | ^ ^ + | +help: remove these parentheses + | +LL - new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); +LL + new_rect(x as f64, (y) as f64, (width) as f64, (height) as f64); + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:89:26 + | +LL | new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); + | ^ ^ + | +help: remove these parentheses + | +LL - new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); +LL + new_rect((x) as f64, y as f64, (width) as f64, (height) as f64); + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:89:38 + | +LL | new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); + | ^ ^ + | +help: remove these parentheses + | +LL - new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); +LL + new_rect((x) as f64, (y) as f64, width as f64, (height) as f64); + | + +warning: unnecessary parentheses around cast expression + --> $DIR/unused_parens_cast.rs:89:54 + | +LL | new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); + | ^ ^ + | +help: remove these parentheses + | +LL - new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); +LL + new_rect((x) as f64, (y) as f64, (width) as f64, height as f64); + | + +warning: 13 warnings emitted + diff --git a/tests/ui/methods/method-not-found-generic-arg-elision.stderr b/tests/ui/methods/method-not-found-generic-arg-elision.stderr index b97688d3868b8..faedb70ff99cf 100644 --- a/tests/ui/methods/method-not-found-generic-arg-elision.stderr +++ b/tests/ui/methods/method-not-found-generic-arg-elision.stderr @@ -24,6 +24,8 @@ error[E0599]: no method named `extend` found for struct `Map` in the current sco | LL | v.iter().map(Box::new(|x| x * x) as Box i32>).extend(std::iter::once(100)); | ^^^^^^ method not found in `Map, Box i32>>` + | + = note: the full type name has been written to '$TEST_BUILD_DIR/methods/method-not-found-generic-arg-elision/method-not-found-generic-arg-elision.long-type-11847890071882761621.txt' error[E0599]: no method named `method` found for struct `Wrapper` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:90:13 diff --git a/tests/ui/mismatched_types/issue-36053-2.stderr b/tests/ui/mismatched_types/issue-36053-2.stderr index a6764a1dc6d31..e6c8371d00e8e 100644 --- a/tests/ui/mismatched_types/issue-36053-2.stderr +++ b/tests/ui/mismatched_types/issue-36053-2.stderr @@ -27,6 +27,7 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); | = note: doesn't satisfy `_: Iterator` | + = note: the full type name has been written to '$TEST_BUILD_DIR/mismatched_types/issue-36053-2/issue-36053-2.long-type-2523243994590504090.txt' = note: the following trait bounds were not satisfied: `<[closure@$DIR/issue-36053-2.rs:7:39: 7:48] as FnOnce<(&&str,)>>::Output = bool` which is required by `Filter>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>: Iterator` diff --git a/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs b/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs index 088b2fcdd144d..2a7ae93bd67d6 100644 --- a/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs +++ b/tests/ui/numbers-arithmetic/saturating-float-casts-impl.rs @@ -226,7 +226,7 @@ fn casts() { assert_eq::(f32::INFINITY as i32, i32::MAX); assert_eq::(f32::NEG_INFINITY as i32, i32::MIN); assert_eq::(f32::NAN as i32, 0); - assert_eq::((-f32::NAN) as i32, 0); + assert_eq::(-f32::NAN as i32, 0); // f32 -> u32 test_both_cast::(0.0, 0); @@ -255,7 +255,7 @@ fn casts() { assert_eq::(f32::INFINITY as u32, u32::MAX); assert_eq::(f32::NEG_INFINITY as u32, 0); assert_eq::(f32::NAN as u32, 0); - assert_eq::((-f32::NAN) as u32, 0); + assert_eq::(-f32::NAN as u32, 0); // f32 -> i64 test_both_cast::(4294967296.0, 4294967296); @@ -313,7 +313,7 @@ fn casts() { assert_eq::(f64::INFINITY as i64, i64::MAX); assert_eq::(f64::NEG_INFINITY as i64, i64::MIN); assert_eq::(f64::NAN as i64, 0); - assert_eq::((-f64::NAN) as i64, 0); + assert_eq::(-f64::NAN as i64, 0); // f64 -> u64 test_both_cast::(0.0, 0); @@ -333,7 +333,7 @@ fn casts() { assert_eq::(f64::INFINITY as u64, u64::MAX); assert_eq::(f64::NEG_INFINITY as u64, 0); assert_eq::(f64::NAN as u64, 0); - assert_eq::((-f64::NAN) as u64, 0); + assert_eq::(-f64::NAN as u64, 0); // FIXME emscripten does not support i128 #[cfg(not(target_os = "emscripten"))] @@ -350,12 +350,12 @@ fn casts() { // int -> f32 assert_eq::(127i8 as f32, 127.0); assert_eq::(2147483647i32 as f32, 2147483648.0); - assert_eq::((-2147483648i32) as f32, -2147483648.0); + assert_eq::(-2147483648i32 as f32, -2147483648.0); assert_eq::(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06)); assert_eq::(16777217i32 as f32, 16777216.0); - assert_eq::((-16777217i32) as f32, -16777216.0); + assert_eq::(-16777217i32 as f32, -16777216.0); assert_eq::(16777219i32 as f32, 16777220.0); - assert_eq::((-16777219i32) as f32, -16777220.0); + assert_eq::(-16777219i32 as f32, -16777220.0); assert_eq::( 0x7fffff4000000001i64 as f32, /*0x1.fffffep+62*/ f32::from_bits(0x5effffff), @@ -416,7 +416,7 @@ fn casts() { /*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000), ); assert_eq::( - /*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64, + /*-0x1.fffffep+127*/ -f32::from_bits(0x7f7fffff) as f64, /*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000), ); assert_eq::( @@ -435,7 +435,7 @@ fn casts() { assert_eq::(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits()); assert_eq::(5.0f64 as f32, 5.0f32); assert_eq::(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0); - assert_eq::(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0); + assert_eq::(/*-0x0.0000000000001p-1022*/ -f64::from_bits(0x1) as f32, -0.0); assert_eq::( /*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32, /*0x1p-149*/ f32::from_bits(0x800000), diff --git a/tests/ui/traits/region-pointer-simple.rs b/tests/ui/traits/region-pointer-simple.rs index 0456ca931156e..ca7187abdcd54 100644 --- a/tests/ui/traits/region-pointer-simple.rs +++ b/tests/ui/traits/region-pointer-simple.rs @@ -16,6 +16,6 @@ impl Foo for A { pub fn main() { let a = A { x: 3 }; - let b = (&a) as &dyn Foo; + let b = &a as &dyn Foo; assert_eq!(b.f(), 3); } diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr index b622122f33ea7..6477dccff5a94 100644 --- a/tests/ui/typeck/issue-31173.stderr +++ b/tests/ui/typeck/issue-31173.stderr @@ -42,6 +42,7 @@ LL | | .collect(); | = note: doesn't satisfy `_: Iterator` | + = note: the full type name has been written to '$TEST_BUILD_DIR/typeck/issue-31173/issue-31173.long-type-1298596514340768542.txt' = note: the following trait bounds were not satisfied: `, [closure@$DIR/issue-31173.rs:7:21: 7:25]> as Iterator>::Item = &_` which is required by `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` From 0eae976cf046adbcb5014ec26d414baebf2c038f Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 12:35:19 +0900 Subject: [PATCH 02/15] manual bless --- tests/ui/methods/method-not-found-generic-arg-elision.stderr | 2 -- tests/ui/typeck/issue-31173.stderr | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/ui/methods/method-not-found-generic-arg-elision.stderr b/tests/ui/methods/method-not-found-generic-arg-elision.stderr index faedb70ff99cf..b97688d3868b8 100644 --- a/tests/ui/methods/method-not-found-generic-arg-elision.stderr +++ b/tests/ui/methods/method-not-found-generic-arg-elision.stderr @@ -24,8 +24,6 @@ error[E0599]: no method named `extend` found for struct `Map` in the current sco | LL | v.iter().map(Box::new(|x| x * x) as Box i32>).extend(std::iter::once(100)); | ^^^^^^ method not found in `Map, Box i32>>` - | - = note: the full type name has been written to '$TEST_BUILD_DIR/methods/method-not-found-generic-arg-elision/method-not-found-generic-arg-elision.long-type-11847890071882761621.txt' error[E0599]: no method named `method` found for struct `Wrapper` in the current scope --> $DIR/method-not-found-generic-arg-elision.rs:90:13 diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr index 6477dccff5a94..2ed0705ee9085 100644 --- a/tests/ui/typeck/issue-31173.stderr +++ b/tests/ui/typeck/issue-31173.stderr @@ -34,7 +34,7 @@ LL | | .cloned() LL | | .collect(); | | -^^^^^^^ method cannot be called due to unsatisfied trait bounds | |_________| - | + | --> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL | = note: doesn't satisfy `<_ as Iterator>::Item = &_` @@ -42,7 +42,6 @@ LL | | .collect(); | = note: doesn't satisfy `_: Iterator` | - = note: the full type name has been written to '$TEST_BUILD_DIR/typeck/issue-31173/issue-31173.long-type-1298596514340768542.txt' = note: the following trait bounds were not satisfied: `, [closure@$DIR/issue-31173.rs:7:21: 7:25]> as Iterator>::Item = &_` which is required by `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` From 74888eb35207897998cd5204948fc7eceacfa28f Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 16:04:10 +0900 Subject: [PATCH 03/15] set is_kw to false --- compiler/rustc_lint/src/unused.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index f4531c4d6c118..8e1d6fc09b33b 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1033,6 +1033,7 @@ impl UnusedDelimLint for UnusedParens { followed_by_block, None, None, + false, ), _ => {} From f7b38fbd5f9af8ba124b38833553d503b51911cd Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 16:27:06 +0900 Subject: [PATCH 04/15] manual bless again --- tests/ui/mismatched_types/issue-36053-2.stderr | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ui/mismatched_types/issue-36053-2.stderr b/tests/ui/mismatched_types/issue-36053-2.stderr index e6c8371d00e8e..a6764a1dc6d31 100644 --- a/tests/ui/mismatched_types/issue-36053-2.stderr +++ b/tests/ui/mismatched_types/issue-36053-2.stderr @@ -27,7 +27,6 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); | = note: doesn't satisfy `_: Iterator` | - = note: the full type name has been written to '$TEST_BUILD_DIR/mismatched_types/issue-36053-2/issue-36053-2.long-type-2523243994590504090.txt' = note: the following trait bounds were not satisfied: `<[closure@$DIR/issue-36053-2.rs:7:39: 7:48] as FnOnce<(&&str,)>>::Output = bool` which is required by `Filter>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>: Iterator` From 09491bd79beae825462d01e527fb402f780f04a6 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 16:47:22 +0900 Subject: [PATCH 05/15] manual bless once again --- tests/ui/typeck/issue-31173.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr index 2ed0705ee9085..b622122f33ea7 100644 --- a/tests/ui/typeck/issue-31173.stderr +++ b/tests/ui/typeck/issue-31173.stderr @@ -34,7 +34,7 @@ LL | | .cloned() LL | | .collect(); | | -^^^^^^^ method cannot be called due to unsatisfied trait bounds | |_________| - | + | --> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL | = note: doesn't satisfy `<_ as Iterator>::Item = &_` From c4f690c4f4e4f4ff23f81cedfa8e84925b1afa1d Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 19:10:27 +0900 Subject: [PATCH 06/15] fix lint on test --- library/std/src/thread/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/thread/tests.rs b/library/std/src/thread/tests.rs index b65e2572cc5e4..09190693c21f9 100644 --- a/library/std/src/thread/tests.rs +++ b/library/std/src/thread/tests.rs @@ -159,10 +159,10 @@ where let (tx, rx) = channel(); let x: Box<_> = Box::new(1); - let x_in_parent = (&*x) as *const i32 as usize; + let x_in_parent = &*x as *const i32 as usize; spawnfn(Box::new(move || { - let x_in_child = (&*x) as *const i32 as usize; + let x_in_child = &*x as *const i32 as usize; tx.send(x_in_child).unwrap(); })); From 04f6320a8098e36ddd9fe0b664c52711ed09b055 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Mon, 19 Jun 2023 19:56:53 +0900 Subject: [PATCH 07/15] miri: fix lint on test --- src/tools/miri/tests/pass/float.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/miri/tests/pass/float.rs b/src/tools/miri/tests/pass/float.rs index fee5ca44ffb34..56ccd2e779e1e 100644 --- a/src/tools/miri/tests/pass/float.rs +++ b/src/tools/miri/tests/pass/float.rs @@ -198,7 +198,7 @@ fn casts() { assert_eq::(f32::INFINITY as i32, i32::MAX); assert_eq::(f32::NEG_INFINITY as i32, i32::MIN); assert_eq::(f32::NAN as i32, 0); - assert_eq::((-f32::NAN) as i32, 0); + assert_eq::(-f32::NAN as i32, 0); // f32 -> u32 test_both_cast::(0.0, 0); @@ -223,7 +223,7 @@ fn casts() { assert_eq::(f32::INFINITY as u32, u32::MAX); assert_eq::(f32::NEG_INFINITY as u32, 0); assert_eq::(f32::NAN as u32, 0); - assert_eq::((-f32::NAN) as u32, 0); + assert_eq::(-f32::NAN as u32, 0); // f32 -> i64 test_both_cast::(4294967296.0, 4294967296); @@ -281,7 +281,7 @@ fn casts() { assert_eq::(f64::INFINITY as i64, i64::MAX); assert_eq::(f64::NEG_INFINITY as i64, i64::MIN); assert_eq::(f64::NAN as i64, 0); - assert_eq::((-f64::NAN) as i64, 0); + assert_eq::(-f64::NAN as i64, 0); // f64 -> u64 test_both_cast::(0.0, 0); @@ -300,7 +300,7 @@ fn casts() { assert_eq::(f64::INFINITY as u64, u64::MAX); assert_eq::(f64::NEG_INFINITY as u64, 0); assert_eq::(f64::NAN as u64, 0); - assert_eq::((-f64::NAN) as u64, 0); + assert_eq::(-f64::NAN as u64, 0); // f64 -> i128 assert_eq::(f64::MAX as i128, i128::MAX); @@ -313,12 +313,12 @@ fn casts() { // int -> f32 assert_eq::(127i8 as f32, 127.0); assert_eq::(2147483647i32 as f32, 2147483648.0); - assert_eq::((-2147483648i32) as f32, -2147483648.0); + assert_eq::(-2147483648i32 as f32, -2147483648.0); assert_eq::(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06)); assert_eq::(16777217i32 as f32, 16777216.0); - assert_eq::((-16777217i32) as f32, -16777216.0); + assert_eq::(-16777217i32 as f32, -16777216.0); assert_eq::(16777219i32 as f32, 16777220.0); - assert_eq::((-16777219i32) as f32, -16777220.0); + assert_eq::(-16777219i32 as f32, -16777220.0); assert_eq::( 0x7fffff4000000001i64 as f32, /*0x1.fffffep+62*/ f32::from_bits(0x5effffff), @@ -370,7 +370,7 @@ fn casts() { /*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000), ); assert_eq::( - /*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64, + /*-0x1.fffffep+127*/ -f32::from_bits(0x7f7fffff) as f64, /*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000), ); assert_eq::( @@ -389,7 +389,7 @@ fn casts() { assert_eq::(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits()); assert_eq::(5.0f64 as f32, 5.0f32); assert_eq::(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0); - assert_eq::(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0); + assert_eq::(/*-0x0.0000000000001p-1022*/ -f64::from_bits(0x1) as f32, -0.0); assert_eq::( /*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32, /*0x1p-149*/ f32::from_bits(0x800000), From 52157b8298cc89aab4b6a818fad876fbf1ec8d60 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 12:22:14 +0900 Subject: [PATCH 08/15] allow unary minus --- tests/ui/lint/unused_parens_cast.rs | 2 +- tests/ui/lint/unused_parens_cast.stderr | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/ui/lint/unused_parens_cast.rs b/tests/ui/lint/unused_parens_cast.rs index fec677c4b9d66..6df893bc802f9 100644 --- a/tests/ui/lint/unused_parens_cast.rs +++ b/tests/ui/lint/unused_parens_cast.rs @@ -38,8 +38,8 @@ fn basic_test() { let baz = [4.0f32]; let _ = (baz[0]) as f64; //~^ WARN unnecessary parentheses around cast expression + // following is technically unnecessary, but is allowed because it may confusing. let _ = (-1.0f32) as f64; - //~^ WARN unnecessary parentheses around cast expression let x = Box::new(-1.0f32); let _ = (*x) as f64; //~^ WARN unnecessary parentheses around cast expression diff --git a/tests/ui/lint/unused_parens_cast.stderr b/tests/ui/lint/unused_parens_cast.stderr index 6a078a9e499aa..58dc8d307cf95 100644 --- a/tests/ui/lint/unused_parens_cast.stderr +++ b/tests/ui/lint/unused_parens_cast.stderr @@ -75,18 +75,6 @@ LL - let _ = (baz[0]) as f64; LL + let _ = baz[0] as f64; | -warning: unnecessary parentheses around cast expression - --> $DIR/unused_parens_cast.rs:41:13 - | -LL | let _ = (-1.0f32) as f64; - | ^ ^ - | -help: remove these parentheses - | -LL - let _ = (-1.0f32) as f64; -LL + let _ = -1.0f32 as f64; - | - warning: unnecessary parentheses around cast expression --> $DIR/unused_parens_cast.rs:44:13 | From a420b899c5536907d641598cab12efad97766284 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 13:26:50 +0900 Subject: [PATCH 09/15] except unary minus --- compiler/rustc_lint/src/unused.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 8e1d6fc09b33b..f72e8ffcb1b4f 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1026,15 +1026,21 @@ impl UnusedDelimLint for UnusedParens { false, ); } - ast::ExprKind::Cast(ref expr, _) => self.check_unused_delims_expr( - cx, - expr, - UnusedDelimsCtx::CastExpr, - followed_by_block, - None, - None, - false, - ), + ast::ExprKind::Cast(ref expr, _) => match expr.kind { + // linting against `(-expr) as T` and suggest replace it with + // `expr as T` may become confusing. If we would lint them, + // it would be handled by some external mechanism. + ast::ExprKind::Unary(ast::UnOp::Neg, _) => {} + _ => self.check_unused_delims_expr( + cx, + expr, + UnusedDelimsCtx::CastExpr, + followed_by_block, + None, + None, + false, + ); + } _ => {} } From 8190f235d2c26f0bc6a3c3470d862657bc6b5008 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 13:34:59 +0900 Subject: [PATCH 10/15] format --- compiler/rustc_lint/src/unused.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index f72e8ffcb1b4f..adeebfab4665b 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1039,7 +1039,7 @@ impl UnusedDelimLint for UnusedParens { None, None, false, - ); + ), } _ => {} From 2c99f06e74438d5de8efa600f15aaa1987cb843c Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 13:46:03 +0900 Subject: [PATCH 11/15] ./x.py fmt --- compiler/rustc_lint/src/unused.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index adeebfab4665b..9b50b4528126e 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1040,7 +1040,7 @@ impl UnusedDelimLint for UnusedParens { None, false, ), - } + }, _ => {} } From 76d49fe9d8db593169edfc9e9a54a5ebc52bb66b Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 16:32:37 +0900 Subject: [PATCH 12/15] except unary minus --- compiler/rustc_lint/src/unused.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 9b50b4528126e..d2c8cde021053 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -663,7 +663,12 @@ trait UnusedDelimLint { | ast::ExprKind::Match(..) | ast::ExprKind::If(..) // #51185 - | ast::ExprKind::Closure(..) => return true, + | ast::ExprKind::Closure(..) + // This pattern is technically unnecessary, because unary-minus has higher + // precedence than cast. However, casts followed by it may be confusing + // snippet to code readers. If we want to revisit this, this case shall be + // handled by some external approach. + | ast::ExprKind::Unary(ast::UnOp::Neg, ..) => return true, _ => {} } } @@ -1027,10 +1032,6 @@ impl UnusedDelimLint for UnusedParens { ); } ast::ExprKind::Cast(ref expr, _) => match expr.kind { - // linting against `(-expr) as T` and suggest replace it with - // `expr as T` may become confusing. If we would lint them, - // it would be handled by some external mechanism. - ast::ExprKind::Unary(ast::UnOp::Neg, _) => {} _ => self.check_unused_delims_expr( cx, expr, From 1f3218bca0d4395145a6a8c08d8ab85321694e3a Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 17:02:20 +0900 Subject: [PATCH 13/15] fix stderr --- tests/ui/lint/unused_parens_cast.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/lint/unused_parens_cast.stderr b/tests/ui/lint/unused_parens_cast.stderr index 58dc8d307cf95..a0a2ba52e9638 100644 --- a/tests/ui/lint/unused_parens_cast.stderr +++ b/tests/ui/lint/unused_parens_cast.stderr @@ -147,5 +147,5 @@ LL - new_rect((x) as f64, (y) as f64, (width) as f64, (height) as f64); LL + new_rect((x) as f64, (y) as f64, (width) as f64, height as f64); | -warning: 13 warnings emitted +warning: 12 warnings emitted From 10702e10c41876695486fbe995cf71033e01fc5d Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 18:28:06 +0900 Subject: [PATCH 14/15] miri: avoid triggering lint on test --- src/tools/miri/tests/pass/tree-borrows/reserved.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/miri/tests/pass/tree-borrows/reserved.rs b/src/tools/miri/tests/pass/tree-borrows/reserved.rs index d8a8c27568d4d..9e33eecafb0f5 100644 --- a/src/tools/miri/tests/pass/tree-borrows/reserved.rs +++ b/src/tools/miri/tests/pass/tree-borrows/reserved.rs @@ -91,7 +91,7 @@ unsafe fn int_protected_read() { name!(base); let x = &mut *(base as *mut u8); name!(x); - let y = (&mut *base) as *mut u8; + let y = &mut *base as *mut u8; name!(y); read_second(x, y); // Foreign Read for callee:x print_state!(alloc_id); @@ -106,7 +106,7 @@ unsafe fn int_unprotected_read() { let alloc_id = alloc_id!(base); let x = &mut *(base as *mut u8); name!(x); - let y = (&mut *base) as *mut u8; + let y = &mut *base as *mut u8; name!(y); let _val = *y; // Foreign Read for x print_state!(alloc_id); @@ -120,7 +120,7 @@ unsafe fn int_unprotected_write() { let alloc_id = alloc_id!(base); let x = &mut *(base as *mut u8); name!(x); - let y = (&mut *base) as *mut u8; + let y = &mut *base as *mut u8; name!(y); *y = 1; // Foreign Write for x print_state!(alloc_id); From 4f3ff0cc4881dbc9190b88567a4dfffca04596f9 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Tue, 20 Jun 2023 18:59:24 +0900 Subject: [PATCH 15/15] miri: avoid triggering lint on test --- src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs | 4 ++-- .../tests/fail/tree-borrows/reserved/int-protected-write.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs b/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs index b2ec23bda02c5..25179198388bd 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/illegal_dealloc1.rs @@ -4,8 +4,8 @@ use std::alloc::{alloc, dealloc, Layout}; fn main() { unsafe { let x = alloc(Layout::from_size_align_unchecked(1, 1)); - let ptr1 = (&mut *x) as *mut u8; - let ptr2 = (&mut *ptr1) as *mut u8; + let ptr1 = &mut *x as *mut u8; + let ptr2 = &mut *ptr1 as *mut u8; // Invalidate ptr2 by writing to ptr1. ptr1.write(0); // Deallocate through ptr2. diff --git a/src/tools/miri/tests/fail/tree-borrows/reserved/int-protected-write.rs b/src/tools/miri/tests/fail/tree-borrows/reserved/int-protected-write.rs index 3a1205a84f726..1a285552321f2 100644 --- a/src/tools/miri/tests/fail/tree-borrows/reserved/int-protected-write.rs +++ b/src/tools/miri/tests/fail/tree-borrows/reserved/int-protected-write.rs @@ -12,7 +12,7 @@ fn main() { name!(n); let x = &mut *(n as *mut _); name!(x); - let y = (&mut *n) as *mut _; + let y = &mut *n as *mut _; name!(y); write_second(x, y); unsafe fn write_second(x: &mut u8, y: *mut u8) {