108
108
use rustc_ast:: token:: { Delimiter , IdentIsRaw , Token , TokenKind } ;
109
109
use rustc_ast:: { DUMMY_NODE_ID , NodeId } ;
110
110
use rustc_data_structures:: fx:: FxHashMap ;
111
- use rustc_errors:: MultiSpan ;
112
- use rustc_lint_defs:: BuiltinLintDiag ;
111
+ use rustc_errors:: DecorateDiagCompat ;
113
112
use rustc_session:: lint:: builtin:: META_VARIABLE_MISUSE ;
114
113
use rustc_session:: parse:: ParseSess ;
115
114
use rustc_span:: { ErrorGuaranteed , MacroRulesNormalizedIdent , Span , kw} ;
@@ -245,9 +244,12 @@ fn check_binders(
245
244
// There are 3 possibilities:
246
245
if let Some ( prev_info) = binders. get ( & name) {
247
246
// 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
+ ) ;
251
253
} else if get_binder_info ( macros, binders, name) . is_none ( ) {
252
254
// 2. The meta-variable is free: This is a binder.
253
255
binders. insert ( name, BinderInfo { span, ops : ops. into ( ) } ) ;
@@ -579,7 +581,7 @@ fn check_ops_is_prefix(
579
581
return ;
580
582
}
581
583
}
582
- buffer_lint ( psess, span. into ( ) , node_id, BuiltinLintDiag :: UnknownMacroVariable ( name) ) ;
584
+ buffer_lint ( psess, span, node_id, errors :: UnknownMacroVariable { name } ) ;
583
585
}
584
586
585
587
/// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -604,29 +606,42 @@ fn ops_is_prefix(
604
606
psess : & ParseSess ,
605
607
node_id : NodeId ,
606
608
span : Span ,
607
- name : MacroRulesNormalizedIdent ,
609
+ ident : MacroRulesNormalizedIdent ,
608
610
binder_ops : & [ KleeneToken ] ,
609
611
occurrence_ops : & [ KleeneToken ] ,
610
612
) {
611
613
for ( i, binder) in binder_ops. iter ( ) . enumerate ( ) {
612
614
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
+ ) ;
616
621
return ;
617
622
}
618
623
let occurrence = & occurrence_ops[ i] ;
619
624
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
+ ) ;
624
634
return ;
625
635
}
626
636
}
627
637
}
628
638
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
+ ) {
630
645
// Macros loaded from other crates have dummy node ids.
631
646
if node_id != DUMMY_NODE_ID {
632
647
psess. buffer_lint ( META_VARIABLE_MISUSE , span, node_id, diag) ;
0 commit comments