Rollup merge of #87441 - ibraheemdev:i-86865, r=cjgillot
Emit suggestion when passing byte literal to format macro Closes #86865
This commit is contained in:
commit
358a018292
5 changed files with 61 additions and 15 deletions
|
@ -510,7 +510,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
match expr_to_spanned_string(ecx, template_expr, msg) {
|
||||
Ok(template_part) => template_part,
|
||||
Err(err) => {
|
||||
if let Some(mut err) = err {
|
||||
if let Some((mut err, _)) = err {
|
||||
err.emit();
|
||||
}
|
||||
return None;
|
||||
|
|
|
@ -964,17 +964,19 @@ pub fn expand_preparsed_format_args(
|
|||
}
|
||||
Ok(fmt) => fmt,
|
||||
Err(err) => {
|
||||
if let Some(mut err) = err {
|
||||
if let Some((mut err, suggested)) = err {
|
||||
let sugg_fmt = match args.len() {
|
||||
0 => "{}".to_string(),
|
||||
_ => format!("{}{{}}", "{} ".repeat(args.len())),
|
||||
};
|
||||
err.span_suggestion(
|
||||
fmt_sp.shrink_to_lo(),
|
||||
"you might be missing a string literal to format with",
|
||||
format!("\"{}\", ", sugg_fmt),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if !suggested {
|
||||
err.span_suggestion(
|
||||
fmt_sp.shrink_to_lo(),
|
||||
"you might be missing a string literal to format with",
|
||||
format!("\"{}\", ", sugg_fmt),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
return DummyResult::raw_expr(sp, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue