Skip to content

mattdurak/sample_rustfmt_bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BUG

Repro

Run

cargo build

Check my-crate/src/generated/sample.rs and see the following formatting:

#[allow(dead_code)]
#[allow(clippy::uninlined_format_args)]
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)
    }
}

Run

cargo fmt

Check my-crate/src/generated/sample.rs and see the following formatting:

#[allow(dead_code)]
#[allow(clippy::uninlined_format_args)]
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)
    }
}

The same output is produced when running rustfmt fmt_bug\my-crate\src\generated\sample.rs --verbose

But when doing this from build.rs in a workspace, it produces the first output above.

About

Show a rustfmt build.rs bug

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages