-
Notifications
You must be signed in to change notification settings - Fork 936
Open
Description
We have a build.rs script that produces a source file and then runs "rustfmt" on it. We use a "rustfmt.toml" file with style_edition = "2021"
to try to get the same behavior as running cargo fmt
.
However, when building, we get this output:
impl BlockStorageAllocateBlockAsyncCallbackResult {
fn decode(src: u32) -> Result<Self, DecodeError> {
let result = match src {
1 => BlockStorageAllocateBlockAsyncCallbackResult::Ok,
2 => BlockStorageAllocateBlockAsyncCallbackResult::AlreadyExists,
3 => BlockStorageAllocateBlockAsyncCallbackResult::Error,
_ => return Err(DecodeError::new(format!(
"Decode BlockStorageAllocateBlockAsyncCallbackResult: Unsupported enum value: {}",
src
))),
};
Ok(result)
}
}
But then running cargo fmt
on the same workspace produces this output:
impl BlockStorageAllocateBlockAsyncCallbackResult {
fn decode(src: u32) -> Result<Self, DecodeError> {
let result = match src {
1 => BlockStorageAllocateBlockAsyncCallbackResult::Ok,
2 => BlockStorageAllocateBlockAsyncCallbackResult::AlreadyExists,
3 => BlockStorageAllocateBlockAsyncCallbackResult::Error,
_ => {
return Err(DecodeError::new(format!(
"Decode BlockStorageAllocateBlockAsyncCallbackResult: Unsupported enum value: {}",
src
)))
}
};
Ok(result)
}
}
Note the extra braces.
This seems to happen when running from a workspace containing the crate specifically. It is annoying as building will produce code that requires re-running "cargo fmt" (else it fails our PR pipeline)
Minimal reproducible example available here: https://github.com/mattdurak/sample_rustfmt_bug
Metadata
Metadata
Assignees
Labels
No labels