rust-lang/rust-clippy

Two suggestions for more DRY code

Open

#1,674 创建于 2017年4月14日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Rust (10,406 star) (1,391 fork)batch import
A-lintL-styleT-middlegood first issue

描述

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

贡献者指南

Two suggestions for more DRY code · rust-lang/rust-clippy#1674 | Good First Issue