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

fmt bug for tuple type access #127198

Closed
He1pa opened this issue Jul 1, 2024 · 2 comments
Closed

fmt bug for tuple type access #127198

He1pa opened this issue Jul 1, 2024 · 2 comments
Labels
A-rustfmt Area: Rustfmt

Comments

@He1pa
Copy link
Contributor

He1pa commented Jul 1, 2024

I tried this code:

fn main() {
    type Foo = ((i32, i32), i32);
    let a: Foo = ((1, 1), 1);
    let b = a.0.0;
}

And i used fmt(both rust analyzer and cargo fmt)

I expected to see this happen:

fn main() {
    type Foo = ((i32, i32), i32);
    let a: Foo = ((1, 1), 1);
    let b = a.0.0;
}

Instead, this happened:

fn main() {
    type Foo = ((i32, i32), i32);
    let a: Foo = ((1, 1), 1);
    let b = a.0 .0;
}

In a.0 .0,There's an extra space here.

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (3a85a5cfe 2023-11-20)
binary: rustc
commit-hash: 3a85a5cfe7884f94e3cb29a606913d7989ad9b48
commit-date: 2023-11-20
host: aarch64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.5
Backtrace

<backtrace>

@He1pa He1pa added the C-bug Category: This is a bug. label Jul 1, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 1, 2024
@y21
Copy link
Member

y21 commented Jul 1, 2024

The extra space used to be necessary in older versions of Rust where tuple.0.0 was a syntax error, and (to my knowledge) rustfmt generally won't change formatting later on, at least with the default version = "One".

If you set version = "Two" in your rustfmt.toml file, it should format this without the extra space as you expect.

See rust-lang/rustfmt#4355 (comment) for more context

@workingjubilee
Copy link
Member

Duplicate with rust-lang/rustfmt#4779

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2024
@saethlin saethlin added A-rustfmt Area: Rustfmt and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustfmt Area: Rustfmt
Projects
None yet
Development

No branches or pull requests

5 participants