reference icon indicating copy to clipboard operation
reference copied to clipboard

Expand on lints with macro spans.

Open ehuss opened this issue 6 years ago • 1 comments

Lints behave a little strange with macros, particularly from external crates. This should probably be captured somewhere, probably the diagnostics page for allow/warn/deny/forbid.

For example, lints generated on items created by an extern macro do not fire. Calling the following will not trigger a (deny by default) lint:

#[macro_export]
macro_rules! thing {
    () => {
        #[no_mangle]
        pub const FOO: i32 = 5;
    }
}

See also https://github.com/rust-lang/rust/issues/58502 where the ident comes from the local crate, but does not pick up the global lint level of the extern crate.

So I imagine there are a variety of things to consider (the location of a span, the lint level of the local and extern crates, etc.). I don't know where to begin distilling how things work. Perhaps it is not as complex as it appears. I also get the impression that it depends on exactly which lint it is, since some are done at different phases.

ehuss avatar Mar 16 '19 19:03 ehuss

The intent is to report a lint if it can be addressed by the person encountering it, and not report it if the code comes from third party and cannot be fixed. So, the characteristic span needs to be chosen accordingly (cc https://github.com/rust-lang/rust/issues/50122 which is a related issue).

but does not pick up the global lint level of the extern crate.

Lint level of the external crate is never picked, we don't have this kind of hygiene. allow/warn/deny/forbid attributes only work as a tree applied to expanded local crate.

petrochenkov avatar Mar 16 '19 19:03 petrochenkov