1
Fork 0

add suggestion for wrongly ordered format parameters

This commit is contained in:
Davis Muro 2024-12-28 20:47:07 -08:00
parent 0b63477350
commit 62c3c9a5ae
No known key found for this signature in database
GPG key ID: E733EF073829DCA1
7 changed files with 140 additions and 0 deletions

View file

@ -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)]

View file

@ -316,6 +316,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));