Skip to content

unused_braces suggestion also removes attributes #141549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Urgau opened this issue May 25, 2025 · 0 comments · Fixed by #141550
Closed

unused_braces suggestion also removes attributes #141549

Urgau opened this issue May 25, 2025 · 0 comments · Fixed by #141550
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Urgau
Copy link
Member

Urgau commented May 25, 2025

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
@Urgau Urgau added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue May 26, 2025
…ukang

Fix `unused_braces` lint suggestion when encountering attributes

This PR fixes the `unused_braces` lint suggestion when encountering attributes by not removing them in the suggestion.

Fixes rust-lang#141549
rust-timer added a commit that referenced this issue May 26, 2025
Rollup merge of #141550 - Urgau:unused_braces-attrs, r=chenyukang

Fix `unused_braces` lint suggestion when encountering attributes

This PR fixes the `unused_braces` lint suggestion when encountering attributes by not removing them in the suggestion.

Fixes #141549
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 27, 2025
Fix `unused_braces` lint suggestion when encountering attributes

This PR fixes the `unused_braces` lint suggestion when encountering attributes by not removing them in the suggestion.

Fixes rust-lang/rust#141549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant