rust-lang/rust-clippy

Two suggestions for more DRY code

Open

#1.674 geöffnet am 14. Apr. 2017

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (1.391 Forks)batch import
A-lintL-styleT-middlegood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 22h) (113 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide