Skip to content

Skip parenthesis around tuple struct field calls #134834

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

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 27, 2024

The pretty-printer previously did not distinguish between named vs unnamed fields when printing a function call containing a struct field. It would print the call as (self.fun)() for a named field which is correct, and (self.0)() for an unnamed field which is redundant.

This PR changes function calls of tuple struct fields to print without parens.

Before:

struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    (tuple.0)();
}

After:

struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    tuple.0();
}

@dtolnay dtolnay added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Dec 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2024
@compiler-errors
Copy link
Member

r? compiler-errors @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 27, 2024

📌 Commit 26bb4e6 has been approved by compiler-errors

It is now in the queue for this repository.

@rustbot rustbot assigned compiler-errors and unassigned cjgillot Dec 27, 2024
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2024
…rors

Skip parenthesis around tuple struct field calls

The pretty-printer previously did not distinguish between named vs unnamed fields when printing a function call containing a struct field. It would print the call as `(self.fun)()` for a named field which is correct, and `(self.0)()` for an unnamed field which is redundant.

This PR changes function calls of tuple struct fields to print without parens.

**Before:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    (tuple.0)();
}
```

**After:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    tuple.0();
}
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2024
Rollup of 4 pull requests

Successful merges:

 - rust-lang#134823 (Fix typos)
 - rust-lang#134827 (Some random region tweaks)
 - rust-lang#134833 (Skip parenthesis if `.` makes statement boundary unambiguous)
 - rust-lang#134834 (Skip parenthesis around tuple struct field calls)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0a09252 into rust-lang:master Dec 28, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2024
Rollup merge of rust-lang#134834 - dtolnay:unnamedcall, r=compiler-errors

Skip parenthesis around tuple struct field calls

The pretty-printer previously did not distinguish between named vs unnamed fields when printing a function call containing a struct field. It would print the call as `(self.fun)()` for a named field which is correct, and `(self.0)()` for an unnamed field which is redundant.

This PR changes function calls of tuple struct fields to print without parens.

**Before:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    (tuple.0)();
}
```

**After:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    tuple.0();
}
```
@rustbot rustbot added this to the 1.85.0 milestone Dec 28, 2024
@dtolnay dtolnay deleted the unnamedcall branch December 28, 2024 11:02
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
…rors

Skip parenthesis around tuple struct field calls

The pretty-printer previously did not distinguish between named vs unnamed fields when printing a function call containing a struct field. It would print the call as `(self.fun)()` for a named field which is correct, and `(self.0)()` for an unnamed field which is redundant.

This PR changes function calls of tuple struct fields to print without parens.

**Before:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    (tuple.0)();
}
```

**After:**

```rust
struct Tuple(fn());

fn main() {
    let tuple = Tuple(|| {});
    tuple.0();
}
```
poliorcetics pushed a commit to poliorcetics/rust that referenced this pull request Dec 28, 2024
Rollup of 4 pull requests

Successful merges:

 - rust-lang#134823 (Fix typos)
 - rust-lang#134827 (Some random region tweaks)
 - rust-lang#134833 (Skip parenthesis if `.` makes statement boundary unambiguous)
 - rust-lang#134834 (Skip parenthesis around tuple struct field calls)

r? `@ghost`
`@rustbot` modify labels: rollup
@dtolnay dtolnay removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants