rust-lang/rust-clippy

lint idea: `useless_default_generic_parameters`

Aberta

#14.848 aberto em 19 de mai. de 2025

 (12 comentários) (3 reações) (1 responsável)Rust (1.391 forks)batch import
A-lintG-Rust-for-Linuxgood first issue

Métricas do repositório

Stars
 (10.406 estrelas)
Métricas de merge de PR
 (Mesclagem média 19d 22h) (113 fundiu PRs em 30d)

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(())
}

Guia do colaborador