rust-lang / rust-lang/rust-clippy

lint idea: `useless_default_generic_parameters`

Open
#14,848 12 comments 3 reactions 1 assignee View on GitHub

@vogelbirb is already working on this.

Since Jun 4, 2025.

A-lint G-Rust-for-Linux good first issue
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Given a type with a generic argument that has a default:

type Result<T = ()> = core::result::Result<T, MyError>;

Usage of this type when specifying the default should not use generics:

fn foo() -> Result<()> { Ok(()) }
//                ^^^^ unnecessary generic, `()` already is the default
//                hint: use `Result` instead.
Advantage
  • Removes duplication of the default value
  • Reduces visual clutter
  • Reminds people that the type has a default value
Drawbacks
  • when a library adds a default value, one gets this warning when updating
  • macros might trigger this involuntarily
Example
type Result<T = ()> = core::result::Result<T, MyError>;

fn foo() -> Result<()> {
    Ok(())
}

Could be written as:

type Result<T = ()> = core::result::Result<T, MyError>;

fn foo() -> Result {
    Ok(())
}

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.