108108use rustc_ast:: token:: { Delimiter , IdentIsRaw , Token , TokenKind } ;
109109use rustc_ast:: { DUMMY_NODE_ID , NodeId } ;
110110use rustc_data_structures:: fx:: FxHashMap ;
111- use rustc_errors:: MultiSpan ;
112- use rustc_lint_defs:: BuiltinLintDiag ;
111+ use rustc_errors:: DecorateDiagCompat ;
113112use rustc_session:: lint:: builtin:: META_VARIABLE_MISUSE ;
114113use rustc_session:: parse:: ParseSess ;
115114use rustc_span:: { ErrorGuaranteed , MacroRulesNormalizedIdent , Span , kw} ;
@@ -245,9 +244,12 @@ fn check_binders(
245244 // There are 3 possibilities:
246245 if let Some ( prev_info) = binders. get ( & name) {
247246 // 1. The meta-variable is already bound in the current LHS: This is an error.
248- let mut span = MultiSpan :: from_span ( span) ;
249- span. push_span_label ( prev_info. span , "previous declaration" ) ;
250- buffer_lint ( psess, span, node_id, BuiltinLintDiag :: DuplicateMatcherBinding ) ;
247+ buffer_lint (
248+ psess,
249+ span,
250+ node_id,
251+ errors:: DuplicateMatcherBindingLint { span, prev : prev_info. span } ,
252+ ) ;
251253 } else if get_binder_info ( macros, binders, name) . is_none ( ) {
252254 // 2. The meta-variable is free: This is a binder.
253255 binders. insert ( name, BinderInfo { span, ops : ops. into ( ) } ) ;
@@ -579,7 +581,7 @@ fn check_ops_is_prefix(
579581 return ;
580582 }
581583 }
582- buffer_lint ( psess, span. into ( ) , node_id, BuiltinLintDiag :: UnknownMacroVariable ( name) ) ;
584+ buffer_lint ( psess, span, node_id, errors :: UnknownMacroVariable { name } ) ;
583585}
584586
585587/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -604,29 +606,42 @@ fn ops_is_prefix(
604606 psess : & ParseSess ,
605607 node_id : NodeId ,
606608 span : Span ,
607- name : MacroRulesNormalizedIdent ,
609+ ident : MacroRulesNormalizedIdent ,
608610 binder_ops : & [ KleeneToken ] ,
609611 occurrence_ops : & [ KleeneToken ] ,
610612) {
611613 for ( i, binder) in binder_ops. iter ( ) . enumerate ( ) {
612614 if i >= occurrence_ops. len ( ) {
613- let mut span = MultiSpan :: from_span ( span) ;
614- span. push_span_label ( binder. span , "expected repetition" ) ;
615- buffer_lint ( psess, span, node_id, BuiltinLintDiag :: MetaVariableStillRepeating ( name) ) ;
615+ buffer_lint (
616+ psess,
617+ span,
618+ node_id,
619+ errors:: MetaVarStillRepeatingLint { label : binder. span , ident } ,
620+ ) ;
616621 return ;
617622 }
618623 let occurrence = & occurrence_ops[ i] ;
619624 if occurrence. op != binder. op {
620- let mut span = MultiSpan :: from_span ( span) ;
621- span. push_span_label ( binder. span , "expected repetition" ) ;
622- span. push_span_label ( occurrence. span , "conflicting repetition" ) ;
623- buffer_lint ( psess, span, node_id, BuiltinLintDiag :: MetaVariableWrongOperator ) ;
625+ buffer_lint (
626+ psess,
627+ span,
628+ node_id,
629+ errors:: MetaVariableWrongOperator {
630+ binder : binder. span ,
631+ occurrence : occurrence. span ,
632+ } ,
633+ ) ;
624634 return ;
625635 }
626636 }
627637}
628638
629- fn buffer_lint ( psess : & ParseSess , span : MultiSpan , node_id : NodeId , diag : BuiltinLintDiag ) {
639+ fn buffer_lint (
640+ psess : & ParseSess ,
641+ span : Span ,
642+ node_id : NodeId ,
643+ diag : impl Into < DecorateDiagCompat > ,
644+ ) {
630645 // Macros loaded from other crates have dummy node ids.
631646 if node_id != DUMMY_NODE_ID {
632647 psess. buffer_lint ( META_VARIABLE_MISUSE , span, node_id, diag) ;
0 commit comments