I was wondering if there was any situation where it would be required to make a field or method public inside of a private struct? I've been asking about this to some colleagues and we couldn't get any relevant example.
Take the following example as an illustration:
struct MyStruct {
pub field: i32, // this `pub` is useless?
}
impl MyStruct {
pub fn drop(self) {} // this `pub` is useless?
}
If pub is never actualy useful inside of a private type I would gladly implement a lint for clippy or even rustc (which could be desired as having pub marked on some methods may lead to think that over methods are hidden at some level).
Thank for your answers, it sounds weird that unreachable_pub isn't turned on by default.
However the later case does require pub in pub fn foo() {}, overwise I get:
error[E0603]: function `foo` is private
--> tt.rs:10:18
|
10 | pub use self::m::foo as m_foo;
| ^^^ private function
And this reexport makes m_foo callable from parent modules.
In this case I still don't understand how foo could be reached just by replacing pub by pub(crate) (which is only more restrictive, right?). Is this an issue with the lint?