about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-27 18:43:05 -0800
committerGitHub <noreply@github.com>2024-12-27 18:43:05 -0800
commit0a09252866e87a1531584bb3066dbd7d51078408 (patch)
tree93e3a7b864d3651cad3eee99fc851a10ae6dd1a9 /tests
parent3fc0f08b8988e8864effd2ccaa6187df524e892e (diff)
parent26bb4e64645d3f3e0ed0b2921738e56888f96fd1 (diff)
downloadrust-0a09252866e87a1531584bb3066dbd7d51078408.tar.gz
rust-0a09252866e87a1531584bb3066dbd7d51078408.zip
Rollup merge of #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();
}
```
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-fulldeps/pprust-parenthesis-insertion.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
index dc45731dce7..2b41020d307 100644
--- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
+++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs
@@ -77,6 +77,9 @@ static EXPRS: &[&str] = &[
     // These mean different things.
     "if let _ = true && false {}",
     "if let _ = (true && false) {}",
+    // Parentheses to call a named field, but not an unnamed field.
+    "(self.fun)()",
+    "self.0()",
     // Conditions end at the first curly brace, so struct expressions need to be
     // parenthesized. Except in a match guard, where conditions end at arrow.
     "if let _ = (Struct {}) {}",