@@ -110,7 +110,8 @@ use crate::mbe::{KleeneToken, TokenTree};
110
110
use rustc_ast:: token:: { Delimiter , IdentIsRaw , Token , TokenKind } ;
111
111
use rustc_ast:: { NodeId , DUMMY_NODE_ID } ;
112
112
use rustc_data_structures:: fx:: FxHashMap ;
113
- use rustc_errors:: { DiagMessage , MultiSpan } ;
113
+ use rustc_errors:: MultiSpan ;
114
+ use rustc_lint_defs:: BuiltinLintDiag ;
114
115
use rustc_session:: lint:: builtin:: { META_VARIABLE_MISUSE , MISSING_FRAGMENT_SPECIFIER } ;
115
116
use rustc_session:: parse:: ParseSess ;
116
117
use rustc_span:: symbol:: kw;
@@ -252,7 +253,7 @@ fn check_binders(
252
253
// 1. The meta-variable is already bound in the current LHS: This is an error.
253
254
let mut span = MultiSpan :: from_span ( span) ;
254
255
span. push_span_label ( prev_info. span , "previous declaration" ) ;
255
- buffer_lint ( psess, span, node_id, "duplicate matcher binding" ) ;
256
+ buffer_lint ( psess, span, node_id, BuiltinLintDiag :: DuplicateMatcherBinding ) ;
256
257
} else if get_binder_info ( macros, binders, name) . is_none ( ) {
257
258
// 2. The meta-variable is free: This is a binder.
258
259
binders. insert ( name, BinderInfo { span, ops : ops. into ( ) } ) ;
@@ -267,11 +268,11 @@ fn check_binders(
267
268
// FIXME: Report this as a hard error eventually and remove equivalent errors from
268
269
// `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
269
270
// as a hard error and then once as a buffered lint.
270
- psess. buffer_lint (
271
+ psess. buffer_lint_with_diagnostic (
271
272
MISSING_FRAGMENT_SPECIFIER ,
272
273
span,
273
274
node_id,
274
- "missing fragment specifier" ,
275
+ BuiltinLintDiag :: MissingFragmentSpecifier ,
275
276
) ;
276
277
}
277
278
if !macros. is_empty ( ) {
@@ -595,7 +596,7 @@ fn check_ops_is_prefix(
595
596
return ;
596
597
}
597
598
}
598
- buffer_lint ( psess, span. into ( ) , node_id, format ! ( "unknown macro variable `{ name}`" ) ) ;
599
+ buffer_lint ( psess, span. into ( ) , node_id, BuiltinLintDiag :: UnknownMacroVariable ( name) ) ;
599
600
}
600
601
601
602
/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -628,30 +629,23 @@ fn ops_is_prefix(
628
629
if i >= occurrence_ops. len ( ) {
629
630
let mut span = MultiSpan :: from_span ( span) ;
630
631
span. push_span_label ( binder. span , "expected repetition" ) ;
631
- let message = format ! ( "variable '{name}' is still repeating at this depth" ) ;
632
- buffer_lint ( psess, span, node_id, message) ;
632
+ buffer_lint ( psess, span, node_id, BuiltinLintDiag :: MetaVariableStillRepeating ( name) ) ;
633
633
return ;
634
634
}
635
635
let occurrence = & occurrence_ops[ i] ;
636
636
if occurrence. op != binder. op {
637
637
let mut span = MultiSpan :: from_span ( span) ;
638
638
span. push_span_label ( binder. span , "expected repetition" ) ;
639
639
span. push_span_label ( occurrence. span , "conflicting repetition" ) ;
640
- let message = "meta-variable repeats with different Kleene operator" ;
641
- buffer_lint ( psess, span, node_id, message) ;
640
+ buffer_lint ( psess, span, node_id, BuiltinLintDiag :: MetaVariableWrongOperator ) ;
642
641
return ;
643
642
}
644
643
}
645
644
}
646
645
647
- fn buffer_lint (
648
- psess : & ParseSess ,
649
- span : MultiSpan ,
650
- node_id : NodeId ,
651
- message : impl Into < DiagMessage > ,
652
- ) {
646
+ fn buffer_lint ( psess : & ParseSess , span : MultiSpan , node_id : NodeId , diag : BuiltinLintDiag ) {
653
647
// Macros loaded from other crates have dummy node ids.
654
648
if node_id != DUMMY_NODE_ID {
655
- psess. buffer_lint ( META_VARIABLE_MISUSE , span, node_id, message ) ;
649
+ psess. buffer_lint_with_diagnostic ( META_VARIABLE_MISUSE , span, node_id, diag ) ;
656
650
}
657
651
}
0 commit comments