Skip to content

dead_code lint should not report items within an already reported struct/enum/module #31188

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

Closed
dhardy opened this issue Jan 25, 2016 · 2 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@dhardy
Copy link
Contributor

dhardy commented Jan 25, 2016

For example, a library with this code:

mod internal {
    pub struct A;
    impl A {
        pub fn hello() -> &'static str {
            &"hello"
        }
    }
}

results in these warnings when compiled:

dhardy@localhost:~/small/rust/unused_warnings$ cargo build
Compiling unused_warnings v0.1.0 (file:///home/dhardy/small/rust/unused_warnings)
src/lib.rs:2:5: 2:18 warning: struct is never used: `A`, #[warn(dead_code)] on by default
src/lib.rs:2     pub struct A;
                 ^~~~~~~~~~~~~
src/lib.rs:4:9: 6:10 warning: method is never used: `hello`, #[warn(dead_code)] on by default
src/lib.rs:4         pub fn hello() -> &'static str {
src/lib.rs:5             &"hello"
src/lib.rs:6         }

Reporting both struct A and method hello in this case is noisy and likely misleading (e.g. add the following line to the code):

pub use internal::A;

In my opinion, items within an already-reported item should not be reported (in this case, only A should be reported as unused).

@steveklabnik steveklabnik added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 26, 2016
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 24, 2017
@djc
Copy link
Contributor

djc commented Aug 28, 2018

This seems like a duplicate of #39531.

@dhardy
Copy link
Contributor Author

dhardy commented Aug 28, 2018

Yes, seems to be, despite being older. Still, the discussion is over there so this one might as well be closed.

@dhardy dhardy closed this as completed Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

4 participants