Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt can generate invalid code when using space_after_colon=false #6470

Open
lever1209 opened this issue Feb 11, 2025 · 2 comments · May be fixed by #6475
Open

Rustfmt can generate invalid code when using space_after_colon=false #6470

lever1209 opened this issue Feb 11, 2025 · 2 comments · May be fixed by #6475
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@lever1209
Copy link

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

@ytmimi
Copy link
Contributor

ytmimi commented Feb 11, 2025

Thanks for the report! Confirming that I can reproduce this when using space_after_colon=false with rustfmt 1.8.0-nightly (054efdd 2025-02-07)

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Feb 11, 2025
@ytmimi
Copy link
Contributor

ytmimi commented Feb 11, 2025

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
2 participants