|
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,7 @@ 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(psess, span, node_id, errors::DuplicateMatcherBindingLint { span, prev: prev_info.span}); |
251 | 248 | } else if get_binder_info(macros, binders, name).is_none() { |
252 | 249 | // 2. The meta-variable is free: This is a binder. |
253 | 250 | binders.insert(name, BinderInfo { span, ops: ops.into() }); |
@@ -579,7 +576,7 @@ fn check_ops_is_prefix( |
579 | 576 | return; |
580 | 577 | } |
581 | 578 | } |
582 | | - buffer_lint(psess, span.into(), node_id, BuiltinLintDiag::UnknownMacroVariable(name)); |
| 579 | + buffer_lint(psess, span, node_id, errors::UnknownMacroVariable { name }); |
583 | 580 | } |
584 | 581 |
|
585 | 582 | /// Returns whether `binder_ops` is a prefix of `occurrence_ops`. |
@@ -610,23 +607,21 @@ fn ops_is_prefix( |
610 | 607 | ) { |
611 | 608 | for (i, binder) in binder_ops.iter().enumerate() { |
612 | 609 | 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)); |
| 610 | + buffer_lint(psess, span, node_id, errors::MetaVariableStillRepeating { name, label: binder.span }); |
616 | 611 | return; |
617 | 612 | } |
618 | 613 | let occurrence = &occurrence_ops[i]; |
619 | 614 | 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); |
| 615 | + buffer_lint(psess, span, node_id, errors::MetaVariableWrongOperator { |
| 616 | + binder: binder.span, |
| 617 | + occurrence: occurrence.span, |
| 618 | + }); |
624 | 619 | return; |
625 | 620 | } |
626 | 621 | } |
627 | 622 | } |
628 | 623 |
|
629 | | -fn buffer_lint(psess: &ParseSess, span: MultiSpan, node_id: NodeId, diag: BuiltinLintDiag) { |
| 624 | +fn buffer_lint(psess: &ParseSess, span: Span, node_id: NodeId, diag: impl Into<DecorateDiagCompat>) { |
630 | 625 | // Macros loaded from other crates have dummy node ids. |
631 | 626 | if node_id != DUMMY_NODE_ID { |
632 | 627 | psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, diag); |
|
0 commit comments