Rollup merge of #134877 - DavisRayM:129966-format-string-help-message, r=estebank
add suggestion for wrongly ordered format parameters Add suggestion for wrongly ordered format parameters like `?#`. Supersedes #131004 Fix #129966
This commit is contained in:
commit
1ea1db5b08
7 changed files with 140 additions and 0 deletions
|
@ -197,6 +197,8 @@ builtin_macros_format_redundant_args = redundant {$n ->
|
|||
|
||||
builtin_macros_format_remove_raw_ident = remove the `r#`
|
||||
|
||||
builtin_macros_format_reorder_format_parameter = did you mean `{$replacement}`?
|
||||
|
||||
builtin_macros_format_requires_string = requires at least a format string argument
|
||||
|
||||
builtin_macros_format_string_invalid = invalid format string: {$desc}
|
||||
|
|
|
@ -618,6 +618,17 @@ pub(crate) enum InvalidFormatStringSuggestion {
|
|||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[suggestion(
|
||||
builtin_macros_format_reorder_format_parameter,
|
||||
code = "{replacement}",
|
||||
style = "verbose",
|
||||
applicability = "machine-applicable"
|
||||
)]
|
||||
ReorderFormatParameter {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
replacement: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -321,6 +321,13 @@ fn make_format_args(
|
|||
e.sugg_ = Some(errors::InvalidFormatStringSuggestion::RemoveRawIdent { span })
|
||||
}
|
||||
}
|
||||
parse::Suggestion::ReorderFormatParameter(span, replacement) => {
|
||||
let span = fmt_span.from_inner(InnerSpan::new(span.start, span.end));
|
||||
e.sugg_ = Some(errors::InvalidFormatStringSuggestion::ReorderFormatParameter {
|
||||
span,
|
||||
replacement,
|
||||
});
|
||||
}
|
||||
}
|
||||
let guar = ecx.dcx().emit_err(e);
|
||||
return ExpandResult::Ready(Err(guar));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue