@@ -80,6 +80,9 @@ pub struct Lint {
80
80
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
81
81
/// `default_level`.
82
82
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 ,
83
86
}
84
87
85
88
impl Lint {
@@ -100,11 +103,18 @@ impl Lint {
100
103
#[ macro_export]
101
104
macro_rules! declare_lint {
102
105
( $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) => (
103
112
$vis static $NAME: & $crate:: lint:: Lint = & $crate:: lint:: Lint {
104
113
name: stringify!( $NAME) ,
105
114
default_level: $crate:: lint:: $Level,
106
115
desc: $desc,
107
116
edition_lint_opts: None ,
117
+ report_in_external_macro: $external,
108
118
} ;
109
119
) ;
110
120
( $vis: vis $NAME: ident, $Level: ident, $desc: expr,
@@ -115,6 +125,7 @@ macro_rules! declare_lint {
115
125
default_level: $crate:: lint:: $Level,
116
126
desc: $desc,
117
127
edition_lint_opts: Some ( ( $lint_edition, $crate:: lint:: Level :: $edition_level) ) ,
128
+ report_in_external_macro: false ,
118
129
} ;
119
130
) ;
120
131
}
@@ -583,8 +594,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
583
594
// items to take care of (delete the macro invocation). As a result we have
584
595
// a few lints we whitelist here for allowing a lint even though it's in a
585
596
// 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 {
588
598
if err. span . primary_spans ( ) . iter ( ) . any ( |s| in_external_macro ( sess, * s) ) {
589
599
err. cancel ( ) ;
590
600
}
0 commit comments