Skip to content

#[must_use] on a trait method impl does nothing. #14202

Closed
@theemathas

Description

@theemathas

What it does

The lint should warn if #[must_use] is applied to a function in an impl Trait for Type { .... } block, and suggest applying it to the trait definition instead.

Advantage

As per the reference, #[must_use] in the impl Trait for Type block does absolutely nothing, and is therefore almost surely a mistake. On the other hand, #[must_use] in the trait definition applies to all implementations of the trait.

Drawbacks

No response

Example

trait Foo {
    fn bar(self) -> i32;
}
impl Foo for () {
    #[must_use]
    fn bar(self) -> i32 {
        1
    }
}

Could be written as:

trait Foo {
    #[must_use]
    fn bar(self) -> i32;
}
impl Foo for () {
    fn bar(self) -> i32 {
        1
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions