Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cedws opened this issue May 20, 2018 · 3 comments
Closed

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

cedws opened this issue May 20, 2018 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@cedws
Copy link

cedws commented May 20, 2018

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.

@Mark-Simulacrum Mark-Simulacrum added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels May 28, 2018
@steveklabnik
Copy link
Member

triage: no change

@SebastianJL
Copy link
Contributor

Just ran into the same thing. Just curious there any plan to implement this?

@Enselic Enselic added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Sep 14, 2023
@mu001999
Copy link
Contributor

#118257 fixed this. We can get the output (play):

warning: method `do_other_stuff` is never used
 --> src/main.rs:3:8
  |
1 | trait MyThing {
  |       ------- method in this trait
2 |     fn do_stuff(&self) -> bool;
3 |     fn do_other_stuff(&self) -> bool;
  |        ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `playground` (bin "playground") generated 1 warning

This can be closed. @steveklabnik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants