Open
Description
Recently we landed a change which squashes all lints tied to foreign macros, but this can thwart lints like unreachable_pub
in unusual fashions. The unreachable_pub
lint can't be fixed unless all its warnings are fixed, which means the following examples fails to compile after being fixed:
// bar.rs
#![crate_type = "lib"]
#[macro_export]
macro_rules! a {
(pub static ref $name:ident : $t:ty = $val:expr) => (
pub struct $name { _wut: () }
pub static $name: $t = $val;
)
}
and then
// foo.rs
#![crate_type = "lib"]
#![feature(rust_2018_preview)]
#![warn(rust_2018_idioms)]
#[macro_use]
#[allow(macro_use_extern_crate)]
extern crate bar;
mod m1 {
pub struct Foo;
}
mod lookup {
use crate::m1::Foo;
a!(pub static ref F: Foo = Foo);
}
pub fn f() {
drop(&lookup::F);
}
compiled with:
$ rustc +nightly bar.rs
$ rustc +nightly foo.rs -L .
warning: unreachable `pub` item
--> foo.rs:10:5
|
10 | pub struct Foo;
| ---^^^^^^^^^^^^
| |
| help: consider restricting its visibility: `crate`
|
note: lint level defined here
--> foo.rs:3:9
|
3 | #![warn(rust_2018_idioms)]
| ^^^^^^^^^^^^^^^^
= note: #[warn(unreachable_pub)] implied by #[warn(rust_2018_idioms)]
= help: or consider exporting it for use by other crates
but the corrected code doesn't compile!
This is a reuced example where a!
is lazy_static!
, but I believe the issue here is that the lints behind the lazy_static!
invocation are being ignored which means that Foo
is actually fully public (because F
is) and the lint is no longer applicable as a result.
cc @Manishearth, @oli-obk
Metadata
Metadata
Assignees
Labels
Area: The 2018 editionArea: Lints (warnings about flaws in source code) such as unused_mut.Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Lint: unreachable_pubRelevant to the compiler team, which will review and decide on the PR/issue.