reformatting creates new (incorrectly) formatted code
Closed this issue · 4 comments
conradludgate commented
Given
use std::io;
pub fn foo(version_and_command: u8) -> io::Result<()> {
match version_and_command {
0 => {}
_ => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"invalid proxy protocol command 0x{:02X}. expected local (0x20) or proxy (0x21)",
version_and_command
),
))
}
}
Ok(())
}
Running rustfmt produces a correctly formatted
use std::io;
pub fn foo(version_and_command: u8) -> io::Result<()> {
match version_and_command {
0 => {}
_ => return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"invalid proxy protocol command 0x{:02X}. expected local (0x20) or proxy (0x21)",
version_and_command
),
)),
}
Ok(())
}
But running it again produces
use std::io;
pub fn foo(version_and_command: u8) -> io::Result<()> {
match version_and_command {
0 => {}
_ => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"invalid proxy protocol command 0x{:02X}. expected local (0x20) or proxy (0x21)",
version_and_command
),
))
}
}
Ok(())
}
ytmimi commented
@conradludgate what version of rustfmt are you using?
tristan957 commented
ytmimi commented
Thanks, If you've got access to a nightly version of rustfmt you can configure version=Two
or style_edition=2024
.
This is how the code is reformatted when using the updated option:
use std::io;
pub fn foo(version_and_command: u8) -> io::Result<()> {
match version_and_command {
0 => {}
_ => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"invalid proxy protocol command 0x{:02X}. expected local (0x20) or proxy (0x21)",
version_and_command
),
));
}
}
Ok(())
}
conradludgate commented
@conradludgate what version of rustfmt are you using?
This was from both stable and latest nightly toolchains. I'm away from my desk right now so I can't find the exact rustfmt version