Skip to content

Lint for #[must_use] on a function that always returns a #[must_use] type #71405

@scottmcm

Description

@scottmcm

I saw someone do this on a try_from today, so I figured I'd make an issue.

Repro:

#[must_use]
pub fn foo() -> Result<(), ()> { Ok(()) }

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c03ca4925a9ac4ce9fdda4d2165e6892

The #[must_use] on the function there is unnecessary because it always returns Result, which is itself #[must_use]. So we might consider linting about that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions