]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_builtin_macros/src/format.rs
Rollup merge of #99593 - TaKO8Ki:suggest-removing-tuple-struct-field, r=compiler...
[rust.git] / compiler / rustc_builtin_macros / src / format.rs
index 4791151c7d3095e18205dd26986d5703642edf18..ce897abb766e5ffd9fd1da51e5f1e88fa930f938 100644 (file)
@@ -16,7 +16,7 @@
 
 use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
 use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, LintId};
-use rustc_parse_format::{Count, FormatSpec};
+use rustc_parse_format::Count;
 use std::borrow::Cow;
 use std::collections::hash_map::Entry;
 
@@ -485,7 +485,7 @@ fn report_invalid_references(&self, numbered_position_args: bool) {
             if let Some(span) = fmt.width_span {
                 let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
                 match fmt.width {
-                    parse::CountIsParam(pos) if pos > self.num_args() => {
+                    parse::CountIsParam(pos) if pos >= self.num_args() => {
                         e.span_label(
                             span,
                             &format!(
@@ -985,29 +985,26 @@ fn lint_named_arguments_used_positionally(
                 }
                 _ => {}
             };
-            match a.format {
-                FormatSpec { width: Count::CountIsName(s, _), .. }
-                | FormatSpec { precision: Count::CountIsName(s, _), .. } => {
-                    used_argument_names.insert(s);
-                }
-                _ => {}
-            };
+            if let Count::CountIsName(s, _) = a.format.width {
+                used_argument_names.insert(s);
+            }
+            if let Count::CountIsName(s, _) = a.format.precision {
+                used_argument_names.insert(s);
+            }
         }
     }
 
     for (symbol, (index, span)) in names {
         if !used_argument_names.contains(symbol.as_str()) {
             let msg = format!("named argument `{}` is not used by name", symbol.as_str());
-            let arg_span = cx.arg_spans[index];
+            let arg_span = cx.arg_spans.get(index).copied();
             cx.ecx.buffered_early_lint.push(BufferedEarlyLint {
                 span: MultiSpan::from_span(span),
                 msg: msg.clone(),
                 node_id: ast::CRATE_NODE_ID,
                 lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
                 diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally(
-                    arg_span,
-                    span,
-                    symbol.to_string(),
+                    arg_span, span, symbol,
                 ),
             });
         }