Improvement to write! macro with wrong type for string literal argument #86865
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4c5ff2fc026afd1a666633cba4c31865
The current output is:
Ideally the output should look like:
So this is super trivial, but I just ran into this and I haven't used
write!
in a while so I sorta did a double take and it took me a second to figure out why it was suggesting what it was suggesting.I was just refactoring some code that had used a byte literal beforehand. Two things would help:
Telling me that I passed in a byte literal where a string literal was expected (or whatever else - right now it only says what's expected, not what was provided). IMO this alone would have been a big help and I would have spent 0 cycles thinking about what the problem could be.
Since this is, to a human, clearly a case where I intended the byte literal to be the format string, in an ideal world that would be pointed out to me. I realize that this is open to interpretation - is it "clearly" the case because it's a byte literal? Or a byte literal with {}? IDK! Food for thought.
The text was updated successfully, but these errors were encountered: