@@ -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
8588impl Lint {
@@ -100,11 +103,18 @@ impl Lint {
100103#[ macro_export]
101104macro_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