Change:
Cargo does not seem to be detecting the {} outside brackets and provides an incredibly strange fix instead. No response the file is from here: You will need serdejson crate. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
it's worth noting that is a valid rust expression, it evaluates to the empty tuple. this is perfectly valid code: minimal repro:
huh, didn't know that. good to know ig
I think it is worth special casing this in diagnostics though, if someone wanted to print a unit type (for some reason?) they probably should use the value or just embed it directly in the format string. An empty expression as the first argument of a format macro is almost certainly a mistake.
claim
The PR that closed this doesn't seem to actually apply the wanted fix, this should be reopened.
Hello, thank you very much for the suggestion. My idea is to find a slightly more general solution instead of special treatment for rare cases. If you think it should be modified as , I completely agree with reopening the issue. :relaxed:

Discussion:
Applicability::MaybeIncorrect, ); } else { <del> let sugg_fmt = match args.explicit_args().len() { 0 => "{}".to_string(), count => { format!("{}{{}}", "{} ".repeat(count)) </del> <ins> // `{}` or `()` let should_suggest = |kind: &ExprKind| -> bool { match kind { ExprKind::Block(b, None) if b.stmts.is_empty() => true, ExprKind::Tup(v) if v.is_empty() => true, _ => false, </ins> } }; <ins> let mut sugg_fmt = String::new(); for kind in std::iter::once(&efmt.kind) .chain(args.explicit_args().into_iter().map(|a| &a.expr.kind)) { sugg_fmt.push_str(if should_suggest(kind) { "{:?} " } else { "{} " }); } sugg_fmt = sugg_fmt.trim_end().to_string(); </ins> err.span_suggestion( unexpanded_fmt_span.shrink_to_lo(), "you might be missing a string literal to format with",

<ins> //@ run-rustfix fn main() { let s = "123"; println!("{:?} {} {}", {}, "sss", s); //~^ ERROR format argument must be a string literal println!("{:?}", {}); //~^ ERROR format argument must be a string literal println!("{} {} {} {:?}", s, "sss", s, {}); //~^ ERROR format argument must be a string literal println!("{:?} {} {:?}", (), s, {}); //~^ ERROR format argument must be a string literal } </ins>

<ins> //@ run-rustfix fn main() { let s = "123"; println!({}, "sss", s); //~^ ERROR format argument must be a string literal println!({}); //~^ ERROR format argument must be a string literal println!(s, "sss", s, {}); //~^ ERROR format argument must be a string literal println!((), s, {}); //~^ ERROR format argument must be a string literal } </ins>

<ins> error: format argument must be a string literal --> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:5:14 | LL |     println!({}, "sss", s); |              ^^ | help: you might be missing a string literal to format with | LL |     println!("{:?} {} {}", {}, "sss", s); |              +++++++++++++ error: format argument must be a string literal --> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:7:14 | LL |     println!({}); |              ^^ | help: you might be missing a string literal to format with | LL |     println!("{:?}", {}); |              +++++++ error: format argument must be a string literal --> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:9:14 | LL |     println!(s, "sss", s, {}); |              ^ | help: you might be missing a string literal to format with | LL |     println!("{} {} {} {:?}", s, "sss", s, {}); |              ++++++++++++++++ error: format argument must be a string literal --> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:11:14 | LL |     println!((), s, {}); |              ^^ | help: you might be missing a string literal to format with | LL |     println!("{:?} {} {:?}", (), s, {}); |              +++++++++++++++ error: aborting due to 4 previous errors </ins>