Skip to content

Commit b6e0547

Browse files
committed
Allow individual lints to opt into being reported in external macros
1 parent d63e925 commit b6e0547

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/librustc/lint/builtin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ declare_lint! {
7777
declare_lint! {
7878
pub UNREACHABLE_CODE,
7979
Warn,
80-
"detects unreachable code paths"
80+
"detects unreachable code paths",
81+
report_in_external_macro
8182
}
8283

8384
declare_lint! {
@@ -216,7 +217,8 @@ declare_lint! {
216217
declare_lint! {
217218
pub DEPRECATED,
218219
Warn,
219-
"detects use of deprecated items"
220+
"detects use of deprecated items",
221+
report_in_external_macro
220222
}
221223

222224
declare_lint! {

src/librustc/lint/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ pub struct Lint {
8080
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
8181
/// `default_level`.
8282
pub edition_lint_opts: Option<(Edition, Level)>,
83+
84+
/// Whether this lint is reported even inside expansions of external macros
85+
pub report_in_external_macro: bool,
8386
}
8487

8588
impl Lint {
@@ -100,11 +103,18 @@ impl Lint {
100103
#[macro_export]
101104
macro_rules! declare_lint {
102105
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
106+
declare_lint!{$vis $NAME, $Level, $desc, false}
107+
);
108+
($vis: vis $NAME: ident, $Level: ident, $desc: expr, report_in_external_macro) => (
109+
declare_lint!{$vis $NAME, $Level, $desc, true}
110+
);
111+
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
103112
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
104113
name: stringify!($NAME),
105114
default_level: $crate::lint::$Level,
106115
desc: $desc,
107116
edition_lint_opts: None,
117+
report_in_external_macro: $external,
108118
};
109119
);
110120
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
@@ -115,6 +125,7 @@ macro_rules! declare_lint {
115125
default_level: $crate::lint::$Level,
116126
desc: $desc,
117127
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
128+
report_in_external_macro: false,
118129
};
119130
);
120131
}
@@ -583,8 +594,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
583594
// items to take care of (delete the macro invocation). As a result we have
584595
// a few lints we whitelist here for allowing a lint even though it's in a
585596
// foreign macro invocation.
586-
} else if lint_id != LintId::of(builtin::UNREACHABLE_CODE) &&
587-
lint_id != LintId::of(builtin::DEPRECATED) {
597+
} else if !lint.report_in_external_macro {
588598
if err.span.primary_spans().iter().any(|s| in_external_macro(sess, *s)) {
589599
err.cancel();
590600
}

0 commit comments

Comments
 (0)