@@ -21,7 +21,9 @@ use rustc_hir::def_id::{CrateNum, LocalDefId};
21
21
use rustc_middle:: middle:: stability;
22
22
use rustc_middle:: ty:: RegisteredTools ;
23
23
use 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
+ } ;
25
27
use rustc_session:: lint:: builtin:: { UNUSED_MACROS , UNUSED_MACRO_RULES } ;
26
28
use rustc_session:: lint:: BuiltinLintDiagnostics ;
27
29
use rustc_session:: parse:: feature_err;
@@ -137,10 +139,11 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
137
139
}
138
140
}
139
141
}
140
- // We implicitly add `rustfmt` and `clippy` to known tools,
142
+ // We implicitly add `rustfmt`, `clippy`, `diagnostic ` to known tools,
141
143
// but it's not an error to register them explicitly.
142
144
let predefined_tools = [ sym:: clippy, sym:: rustfmt] ;
143
145
registered_tools. extend ( predefined_tools. iter ( ) . cloned ( ) . map ( Ident :: with_dummy_span) ) ;
146
+ registered_tools. insert ( Ident :: with_dummy_span ( sym:: diagnostic) ) ;
144
147
registered_tools
145
148
}
146
149
@@ -493,6 +496,27 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
493
496
Err ( Determinacy :: Undetermined ) => return Err ( Indeterminate ) ,
494
497
} ;
495
498
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
+
496
520
// Report errors for the resolved macro.
497
521
for segment in & path. segments {
498
522
if let Some ( args) = & segment. args {
0 commit comments