Skip to content

Unnecessary curve brackets in suggestion generated by [unnecessary_cast] lint #14640

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
MCJOHN974 opened this issue Apr 17, 2025 · 1 comment · Fixed by #14643
Closed

Unnecessary curve brackets in suggestion generated by [unnecessary_cast] lint #14640

MCJOHN974 opened this issue Apr 17, 2025 · 1 comment · Fixed by #14643
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@MCJOHN974
Copy link

MCJOHN974 commented Apr 17, 2025

Summary

Suggestion generated by this lint have unnecessary curve brackets. It also auto apply this brackets with --fix flag.

Reproducer

I tried this code:

use std::vec::Vec;

fn main() {
    let x = 5usize;
    let vec: Vec<u64> = vec![1, 2, 3, 4, 5];
    assert_eq!(vec.len(), x as usize);
}

I expected to see this happen when I run cargo clippy:

warning: casting to the same type is unnecessary (`usize` -> `usize`)
 --> src/main.rs:6:27
  |
6 |     assert_eq!(vec.len(), x as usize);
  |                           ^^^^^^^^^^ help: try: `x`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
  = note: `#[warn(clippy::unnecessary_cast)]` on by default

Instead, this happened:

warning: casting to the same type is unnecessary (`usize` -> `usize`)
 --> src/main.rs:6:27
  |
6 |     assert_eq!(vec.len(), x as usize);
  |                           ^^^^^^^^^^ help: try: `{ x }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
  = note: `#[warn(clippy::unnecessary_cast)]` on by default

My rust version:

rustc -Vv
rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.5

Version


Additional Labels

No response

@MCJOHN974 MCJOHN974 added the C-bug Category: Clippy is not doing the correct thing label Apr 17, 2025
@profetia
Copy link
Contributor

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue Apr 26, 2025
Closes #14640

changelog: [`unnecessary_cast`] fix extra brackets in suggestions when
in macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants