diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-07-20 22:45:52 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-07-20 22:45:52 +0200 |
| commit | b6e05476809a6bc58da03cf546c6a4d9ec58d8f2 (patch) | |
| tree | 76f7cbdda4ad1e73ba67b3c67ac03afa528ee03c | |
| parent | d63e9257b9ff43506a4f697f552beb76963408a1 (diff) | |
| download | rust-b6e05476809a6bc58da03cf546c6a4d9ec58d8f2.tar.gz rust-b6e05476809a6bc58da03cf546c6a4d9ec58d8f2.zip | |
Allow individual lints to opt into being reported in external macros
| -rw-r--r-- | src/librustc/lint/builtin.rs | 6 | ||||
| -rw-r--r-- | src/librustc/lint/mod.rs | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index a46b3120622..430e06ecbdf 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -77,7 +77,8 @@ declare_lint! { declare_lint! { pub UNREACHABLE_CODE, Warn, - "detects unreachable code paths" + "detects unreachable code paths", + report_in_external_macro } declare_lint! { @@ -216,7 +217,8 @@ declare_lint! { declare_lint! { pub DEPRECATED, Warn, - "detects use of deprecated items" + "detects use of deprecated items", + report_in_external_macro } declare_lint! { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 8efce297a91..6fa6c31c742 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -80,6 +80,9 @@ pub struct Lint { /// Starting at the given edition, default to the given lint level. If this is `None`, then use /// `default_level`. pub edition_lint_opts: Option<(Edition, Level)>, + + /// Whether this lint is reported even inside expansions of external macros + pub report_in_external_macro: bool, } impl Lint { @@ -100,11 +103,18 @@ impl Lint { #[macro_export] macro_rules! declare_lint { ($vis: vis $NAME: ident, $Level: ident, $desc: expr) => ( + declare_lint!{$vis $NAME, $Level, $desc, false} + ); + ($vis: vis $NAME: ident, $Level: ident, $desc: expr, report_in_external_macro) => ( + declare_lint!{$vis $NAME, $Level, $desc, true} + ); + ($vis: vis $NAME: ident, $Level: ident, $desc: expr, $external: expr) => ( $vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { name: stringify!($NAME), default_level: $crate::lint::$Level, desc: $desc, edition_lint_opts: None, + report_in_external_macro: $external, }; ); ($vis: vis $NAME: ident, $Level: ident, $desc: expr, @@ -115,6 +125,7 @@ macro_rules! declare_lint { default_level: $crate::lint::$Level, desc: $desc, edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)), + report_in_external_macro: false, }; ); } @@ -583,8 +594,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session, // items to take care of (delete the macro invocation). As a result we have // a few lints we whitelist here for allowing a lint even though it's in a // foreign macro invocation. - } else if lint_id != LintId::of(builtin::UNREACHABLE_CODE) && - lint_id != LintId::of(builtin::DEPRECATED) { + } else if !lint.report_in_external_macro { if err.span.primary_spans().iter().any(|s| in_external_macro(sess, *s)) { err.cancel(); } |
