|
1 | 1 | use rustc_errors::codes::*; |
2 | 2 | use rustc_errors::{ |
3 | | - Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans, |
4 | | - Subdiagnostic, |
| 3 | + Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, LintDiagnostic, |
| 4 | + MultiSpan, SingleLabelManySpans, Subdiagnostic, |
5 | 5 | }; |
6 | 6 | use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; |
7 | 7 | use rustc_span::{Ident, Span, Symbol}; |
8 | 8 |
|
| 9 | +use crate::fluent_generated as fluent; |
| 10 | + |
9 | 11 | #[derive(LintDiagnostic)] |
10 | 12 | #[diag(builtin_macros_avoid_intel_syntax)] |
11 | 13 | pub(crate) struct AvoidIntelSyntax; |
@@ -1010,3 +1012,35 @@ pub(crate) struct CfgSelectUnreachable { |
1010 | 1012 | #[label] |
1011 | 1013 | pub wildcard_span: Span, |
1012 | 1014 | } |
| 1015 | + |
| 1016 | +pub(crate) struct NamedArgumentUsedPositionally { |
| 1017 | + pub position_sp_to_replace: Option<Span>, |
| 1018 | + pub position_sp_for_msg: Option<Span>, |
| 1019 | + pub named_arg_sp: Span, |
| 1020 | + pub named_arg_name: Symbol, |
| 1021 | + pub is_formatting_arg: bool, |
| 1022 | +} |
| 1023 | + |
| 1024 | +impl<'a> LintDiagnostic<'a, ()> for NamedArgumentUsedPositionally { |
| 1025 | + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { |
| 1026 | + diag.primary_message(fluent::builtin_macros_named_argument_used_positionally); |
| 1027 | + diag.span_label(self.named_arg_sp, fluent::builtin_macros_label_named_arg); |
| 1028 | + if let Some(span) = self.position_sp_for_msg { |
| 1029 | + diag.span_label(span, fluent::builtin_macros_label_position_arg); |
| 1030 | + } |
| 1031 | + diag.arg("named_arg_name", self.named_arg_name); |
| 1032 | + |
| 1033 | + if let Some(positional_arg_to_replace) = self.position_sp_to_replace { |
| 1034 | + let mut name = self.named_arg_name.to_string(); |
| 1035 | + if self.is_formatting_arg { |
| 1036 | + name.push('$') |
| 1037 | + }; |
| 1038 | + diag.span_suggestion_verbose( |
| 1039 | + positional_arg_to_replace, |
| 1040 | + fluent::builtin_macros_suggestion, |
| 1041 | + name, |
| 1042 | + Applicability::MaybeIncorrect, |
| 1043 | + ); |
| 1044 | + } |
| 1045 | + } |
| 1046 | +} |
0 commit comments