Skip to content

unused_braces suggestion also removes attributes #141549

Closed
@Urgau

Description

@Urgau

Code

use std::cmp::Ordering;

fn ptr_cmp<T: ?Sized>(p1: *const T, p2: *const T) -> Ordering {
    { #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2) }
}

Current output

warning: unnecessary braces around block return value
 --> src/main.rs:4:5
  |
4 |     { #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2) }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^           ^^
  |
  = note: `#[warn(unused_braces)]` on by default
help: remove these braces
  |
4 -     { #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2) }
4 +     p1.cmp(&p2)
  |

Desired output

warning: unnecessary braces around block return value
 --> src/main.rs:4:5
  |
4 |     { #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2) }
  |     ^^                                                         ^^
  |
  = note: `#[warn(unused_braces)]` on by default
help: remove these braces
  |
4 -     { #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2) }
4 +     #[expect(ambiguous_wide_pointer_comparisons)] p1.cmp(&p2)
  |

Rationale and extra context

Removing the attributes can change the meaning of the code.

Rust Version

rustc 1.88.0-beta.1 (be8721b77 2025-05-09)
binary: rustc
commit-hash: be8721b77bafe41f05bd77cda681a1610f44d7cd
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.88.0-beta.1
LLVM version: 20.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions