|
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; |
@@ -1058,3 +1060,35 @@ pub(crate) struct EiiMacroExpectedMaxOneArgument { |
1058 | 1060 | pub span: Span, |
1059 | 1061 | pub name: String, |
1060 | 1062 | } |
| 1063 | + |
| 1064 | +pub(crate) struct NamedArgumentUsedPositionally { |
| 1065 | + pub position_sp_to_replace: Option<Span>, |
| 1066 | + pub position_sp_for_msg: Option<Span>, |
| 1067 | + pub named_arg_sp: Span, |
| 1068 | + pub named_arg_name: Symbol, |
| 1069 | + pub is_formatting_arg: bool, |
| 1070 | +} |
| 1071 | + |
| 1072 | +impl<'a> LintDiagnostic<'a, ()> for NamedArgumentUsedPositionally { |
| 1073 | + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { |
| 1074 | + diag.primary_message(fluent::builtin_macros_named_argument_used_positionally); |
| 1075 | + diag.span_label(self.named_arg_sp, fluent::builtin_macros_label_named_arg); |
| 1076 | + if let Some(span) = self.position_sp_for_msg { |
| 1077 | + diag.span_label(span, fluent::builtin_macros_label_position_arg); |
| 1078 | + } |
| 1079 | + diag.arg("named_arg_name", self.named_arg_name); |
| 1080 | + |
| 1081 | + if let Some(positional_arg_to_replace) = self.position_sp_to_replace { |
| 1082 | + let mut name = self.named_arg_name.to_string(); |
| 1083 | + if self.is_formatting_arg { |
| 1084 | + name.push('$') |
| 1085 | + }; |
| 1086 | + diag.span_suggestion_verbose( |
| 1087 | + positional_arg_to_replace, |
| 1088 | + fluent::builtin_macros_suggestion, |
| 1089 | + name, |
| 1090 | + Applicability::MaybeIncorrect, |
| 1091 | + ); |
| 1092 | + } |
| 1093 | + } |
| 1094 | +} |
0 commit comments