Compiler flag for applying help suggestions

I often run into issues where the compiler knows the solution, like the following:

error: format argument must be a string literal
2 |     println!(42);
  |              ^^
help: you might be missing a string literal to format with
2 |     println!("{}", 42);
  |              +++++

I think it would be very useful if the compiler provided a flag for the diff suggested to be applied on the file, so that it would be easier to test small modifications in rapid succession without needing to context switch for things that the compiler can figure out on its own.

The compiler does output structured changes when it is more confident about its suggestion, and you can apply those with cargo fix.

Maybe it could do that in this specific case, with an integer literal, but in general with something like println!(foo) it can't really be sure if foo was supposed to be a format string (which isn't supported) or something that could be formatted itself. The compiler doesn't have type information at this stage when it's doing macro expansion.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.