Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assist: generate an is_empty method from a len method #7709

Closed
yoshuawuyts opened this issue Feb 17, 2021 · 1 comment
Closed

Assist: generate an is_empty method from a len method #7709

yoshuawuyts opened this issue Feb 17, 2021 · 1 comment
Labels
A-assists S-actionable Someone could pick this issue up and work on it right now

Comments

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Feb 17, 2021

Sibling issue: #7708

Clippy's "len without is_empty" lint warns if you have a len method but no is_empty method. An assist could make this trivial to generate. I'd be happy to implement this; feel free to assign me to it!

Examples

before

impl MyStruct {
    p|ub fn len(&self) -> usize {
        self.data.len()
    }
}

after

impl MyStruct {
    pub fn len(&self) -> usize {
        self.data.len()
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }
}
@flodiebold flodiebold added A-assists S-actionable Someone could pick this issue up and work on it right now labels Feb 20, 2021
@lnicola
Copy link
Member

lnicola commented Mar 15, 2021

Implemented in #8037.

@lnicola lnicola closed this as completed Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

3 participants