Skip to content

Unused trait methods should create a compile-time warning. #50927

Closed
@cedws

Description

@cedws

Take this example code.

trait MyThing {
    fn do_stuff(&self) -> bool;
    fn do_other_stuff(&self) -> bool;
}

struct Other {}

impl MyThing for Other {
    fn do_stuff(&self) -> bool {
        true
    }

    fn do_other_stuff(&self) -> bool {
        true
    }
}

fn main() {
    let thing = Other {};

    thing.do_stuff();

    // NOTE: We never call `do_other_stuff`.
}

Even though we never call do_other_stuff, the compiler does not generate a warning that this trait method is unused. We've defined an implementation for it, but this doesn't mean that the method is used.

Apologies if this issue has already been raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-langRelevant to the language 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