rust-lang / rust-lang/rust-clippy

Unused type angle brackets, and/or unnecessary angle brackets

Open
#16,576 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

It would be nice if clippy could detect whether such type notations are not necessary, and the code would compile without them:

fn test<T: Neg>(x: T) -> T {
    <T as Neg>::neg(x)
}

This would result in the following fixed code:

fn test<T: Neg>(x: T) -> T {
    T::neg(x)
}

However, the vision here is that this could also detect "partial refactoring" options like the below, which would also fix to the same output:

fn test<T: Neg>(x: T) -> T {
    <T>::neg(x)
}
Advantage
  • Can help reduce code size and make code more understandable (for example, the resulting T::neg(x) could potentially be modified by other lints into x.neg() or -x in the case of operator methods).
  • Can help make refactoring easier by letting the linter remove <> if you just search-and-replace as Trait> with >, rather than needing to use a regular expression.
Drawbacks
  • The amount of type information needed for this is probably quite complicated, at least in the case of removing the as Trait portion.
  • This is a pretty niche change that would probably require a lot of work.
Example

(your issue template is unable to determine that I already included examples)

Comparison with existing lints

Loads of "unnecessary X" lints exist in clippy, and so, this would fit right in.

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Begin by studying Clippy's existing unnecessary-X lints and the type information needed for the Rust examples; done means detecting both forms of unnecessary angle brackets and providing the described fixed code.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.