Skip to content

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

Closed
@MCJOHN974

Description

@MCJOHN974

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions