@@ -110,7 +110,8 @@ use crate::mbe::{KleeneToken, TokenTree};
110110use rustc_ast:: token:: { Delimiter , IdentIsRaw , Token , TokenKind } ;
111111use rustc_ast:: { NodeId , DUMMY_NODE_ID } ;
112112use rustc_data_structures:: fx:: FxHashMap ;
113- use rustc_errors:: { DiagMessage , MultiSpan } ;
113+ use rustc_errors:: MultiSpan ;
114+ use rustc_lint_defs:: BuiltinLintDiag ;
114115use rustc_session:: lint:: builtin:: { META_VARIABLE_MISUSE , MISSING_FRAGMENT_SPECIFIER } ;
115116use rustc_session:: parse:: ParseSess ;
116117use rustc_span:: symbol:: kw;
@@ -252,7 +253,7 @@ fn check_binders(
252253 // 1. The meta-variable is already bound in the current LHS: This is an error.
253254 let mut span = MultiSpan :: from_span ( span) ;
254255 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 ) ;
256257 } else if get_binder_info ( macros, binders, name) . is_none ( ) {
257258 // 2. The meta-variable is free: This is a binder.
258259 binders. insert ( name, BinderInfo { span, ops : ops. into ( ) } ) ;
@@ -267,11 +268,11 @@ fn check_binders(
267268 // FIXME: Report this as a hard error eventually and remove equivalent errors from
268269 // `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
269270 // as a hard error and then once as a buffered lint.
270- psess. buffer_lint (
271+ psess. buffer_lint_with_diagnostic (
271272 MISSING_FRAGMENT_SPECIFIER ,
272273 span,
273274 node_id,
274- "missing fragment specifier" ,
275+ BuiltinLintDiag :: MissingFragmentSpecifier ,
275276 ) ;
276277 }
277278 if !macros. is_empty ( ) {
@@ -595,7 +596,7 @@ fn check_ops_is_prefix(
595596 return ;
596597 }
597598 }
598- buffer_lint ( psess, span. into ( ) , node_id, format ! ( "unknown macro variable `{ name}`" ) ) ;
599+ buffer_lint ( psess, span. into ( ) , node_id, BuiltinLintDiag :: UnknownMacroVariable ( name) ) ;
599600}
600601
601602/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -628,30 +629,23 @@ fn ops_is_prefix(
628629 if i >= occurrence_ops. len ( ) {
629630 let mut span = MultiSpan :: from_span ( span) ;
630631 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) ) ;
633633 return ;
634634 }
635635 let occurrence = & occurrence_ops[ i] ;
636636 if occurrence. op != binder. op {
637637 let mut span = MultiSpan :: from_span ( span) ;
638638 span. push_span_label ( binder. span , "expected repetition" ) ;
639639 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 ) ;
642641 return ;
643642 }
644643 }
645644}
646645
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 ) {
653647 // Macros loaded from other crates have dummy node ids.
654648 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 ) ;
656650 }
657651}
0 commit comments