Skip to content

Commit

Permalink
Rollup merge of #124200 - scrabsha:sasha/->, r=compiler-errors,fmease
Browse files Browse the repository at this point in the history
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](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e))

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)
  • Loading branch information
matthiaskrgr authored Apr 23, 2024
2 parents acccbf3 + 2dbaf8f commit e2e78c4
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit e2e78c4

Please sign in to comment.