@@ -21,7 +21,9 @@ use rustc_hir::def_id::{CrateNum, LocalDefId};
2121use rustc_middle:: middle:: stability;
2222use rustc_middle:: ty:: RegisteredTools ;
2323use rustc_middle:: ty:: TyCtxt ;
24- use rustc_session:: lint:: builtin:: { LEGACY_DERIVE_HELPERS , SOFT_UNSTABLE } ;
24+ use rustc_session:: lint:: builtin:: {
25+ LEGACY_DERIVE_HELPERS , SOFT_UNSTABLE , UNKNOWN_DIAGNOSTIC_ATTRIBUTE ,
26+ } ;
2527use rustc_session:: lint:: builtin:: { UNUSED_MACROS , UNUSED_MACRO_RULES } ;
2628use rustc_session:: lint:: BuiltinLintDiagnostics ;
2729use rustc_session:: parse:: feature_err;
@@ -137,10 +139,11 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
137139 }
138140 }
139141 }
140- // We implicitly add `rustfmt` and `clippy` to known tools,
142+ // We implicitly add `rustfmt`, `clippy`, `diagnostic ` to known tools,
141143 // but it's not an error to register them explicitly.
142144 let predefined_tools = [ sym:: clippy, sym:: rustfmt] ;
143145 registered_tools. extend ( predefined_tools. iter ( ) . cloned ( ) . map ( Ident :: with_dummy_span) ) ;
146+ registered_tools. insert ( Ident :: with_dummy_span ( sym:: diagnostic) ) ;
144147 registered_tools
145148}
146149
@@ -493,6 +496,27 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
493496 Err ( Determinacy :: Undetermined ) => return Err ( Indeterminate ) ,
494497 } ;
495498
499+ if kind == MacroKind :: Attr
500+ && !path. segments . is_empty ( )
501+ && path. segments [ 0 ] . ident . as_str ( ) == "diagnostic"
502+ {
503+ if path. segments . len ( ) != 2 {
504+ self . tcx
505+ . sess
506+ . span_err ( path. span , "Diagnostic attributes requires a path with 2 segments" ) ;
507+ self . tcx
508+ . sess
509+ . span_err ( path. span , "Diagnostic attributes requires a path with 2 segments" ) ;
510+ } else {
511+ self . tcx . sess . parse_sess . buffer_lint (
512+ UNKNOWN_DIAGNOSTIC_ATTRIBUTE ,
513+ path. segments [ 1 ] . span ( ) ,
514+ node_id,
515+ "Unknown diagnostic attribute" ,
516+ ) ;
517+ }
518+ }
519+
496520 // Report errors for the resolved macro.
497521 for segment in & path. segments {
498522 if let Some ( args) = & segment. args {
0 commit comments