Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions