rust-lang/rust-clippy

Two suggestions for more DRY code

Open

#1674 aperta il 14 apr 2017

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)Rust (1391 fork)batch import
A-lintL-styleT-middlegood first issue

Metriche repository

Star
 (10.406 star)
Metriche merge PR
 (Merge medio 19g 22h) (113 PR mergiate in 30 g)

Descrizione

Given this code:

struct Foo { cap: usize }
impl Foo {
    fn new() -> Foo { Foo { cap: 1 } }
    fn with_capacity(cap: usize) -> Foo {
        Foo { cap: cap }
    }
}
fn main() {}

In my opinion Clippy should suggest to replace four of those usages of "Foo" with "Self" and to remove one ": cap", making the code more DRY, the intended resulting code should be:

struct Foo { cap: usize }
impl Foo {
    fn new() -> Self { Self { cap: 1 } }
    fn with_capacity(cap: usize) -> Self {
        Self { cap }
    }
}
fn main() {}

Guida contributor