Skip to content

#[must_use] on associated function definition when trait declaration does not have it should still trigger warning when calling function concretely #48486

Open
@Havvy

Description

@Havvy

I expect the following code (Playpen) to emit a warning on the last line of main that the result of s.the_must_use_fn() must be used.

fn main () {
    let s = Struct;
    s.the_must_use_fn();
}

trait Trait {
    fn the_must_use_fn(&self) -> String;
}

struct Struct;

impl Trait for Struct {
    #[must_use]
    fn the_must_use_fn(&self) -> String { "".to_string() }
}

Ref #43302 as the tracking issue for this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions