rust/tests/ui/parser/expr-rarrow-call.stderr
Sasha Pourcelot 98332c108b Improve handling of expr->field errors
The current message for "`->` used for field access" is the following:

```rust
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->`
 --> src/main.rs:2:6
  |
2 |     a->b;
  |      ^^ expected one of 8 possible tokens
```

(playground link[1])

This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is:

```
error: `->` used for field access or method call
 --> ./tiny_test.rs:2:6
  |
2 |     a->b;
  |      ^^ help: try using `.` instead
  |
  = help: the `.` operator will dereference the value if needed
```

(feel free to bikeshed it as much as necessary)

[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e

Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-22 17:47:35 +02:00

43 lines
1.1 KiB
Plaintext

error: `->` used for field access or method call
--> $DIR/expr-rarrow-call.rs:14:10
|
LL | named->foo;
| ^^ help: try using `.` instead
|
= help: the `.` operator will dereference the value if needed
error: `->` used for field access or method call
--> $DIR/expr-rarrow-call.rs:18:12
|
LL | unnamed->0;
| ^^ help: try using `.` instead
|
= help: the `.` operator will dereference the value if needed
error: `->` used for field access or method call
--> $DIR/expr-rarrow-call.rs:22:6
|
LL | t->0;
| ^^ help: try using `.` instead
|
= help: the `.` operator will dereference the value if needed
error: `->` used for field access or method call
--> $DIR/expr-rarrow-call.rs:23:6
|
LL | t->1;
| ^^ help: try using `.` instead
|
= help: the `.` operator will dereference the value if needed
error: `->` used for field access or method call
--> $DIR/expr-rarrow-call.rs:30:8
|
LL | foo->clone();
| ^^ help: try using `.` instead
|
= help: the `.` operator will dereference the value if needed
error: aborting due to 5 previous errors