rustfmt
rustfmt copied to clipboard
Rustfmt can generate invalid code when using `space_after_colon=false`
formatting the following code with space_after_colon=false will generate invalid code
struct SomeStruct {
some_field: ::some_crate::Thing,
}
since it removes the space between the field colon and the :: prefix on some_crate
i cant see this as very high priority because i dont know anyone who prefixes things with :: asides from maybe alloc or std, and space_after_colon=false isnt widely used, but this should probably be looked into
Thanks for the report! Confirming that I can reproduce this when using space_after_colon=false with rustfmt 1.8.0-nightly (054efddd0f 2025-02-07)
This is an issue anywhere that space_after_colon applies. For example:
Input:
const THING: ::some_crate::SomeType = ::some_crate::SomeType::default();
fn main() {
let x: ::some_crate::SomeType = ::some_crate::SomeType::default();
}
Output:
const THING:::some_crate::SomeType = ::some_crate::SomeType::default();
fn main() {
let x:::some_crate::SomeType = ::some_crate::SomeType::default();
}