rustbot · GitHub

@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

Apr 16, 2025

fmease

@Kivooeo

@Kivooeo

mejrs

@Kivooeo

@Kivooeo

@Kivooeo

@Urgau Urgau mentioned this pull request

Apr 17, 2025

Merged

WaffleLapkin

WaffleLapkin

@Kivooeo

WaffleLapkin

@rustbot rustbot added S-waiting-on-author

Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Apr 20, 2025

@Kivooeo

WaffleLapkin

@Kivooeo

@Kivooeo

@Kivooeo

@Kivooeo

@Kivooeo

WaffleLapkin

@bors bors added the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

Apr 22, 2025

Merged

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 22, 2025

bors added a commit to rust-lang-ci/rust that referenced this pull request

Apr 22, 2025

@bors

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Apr 23, 2025
Rollup merge of rust-lang#139921 - Kivooeo:master, r=WaffleLapkin
improve diagnostic for raw pointer field access with ->
This PR enhances the error messages emitted by the Rust compiler when users attempt to use the `->` operator for field access on raw pointers or when dereferencing is needed. The changes aim to provide clearer guidance, by suggesting the correct use of the `.` operator and explicit dereferencing.
**Before:**
```
help: `xs` is a raw pointer; try dereferencing it
   |
LL |         (*xs)->count += 1;
   |         ++  +
```
**Now:**
```
help: use `.` on a dereferenced raw pointer instead
   |
LL -         xs->count += 1;
LL +         (*xs).count += 1;
   |
```
I added extra clarification in the message. Since this error occurs in the parser, we can't be certain that the type is a raw pointer. That's why the message includes only a small note in brackets. (In contrast, the message above is emitted in HIR, where we *can* check whether it's a raw pointer.)
**Before:**
```
  --> main.rs:11:11
   |
11 |         xs->count += 1;
   |           ^^
   |
   = help: the . operator will dereference the value if needed
```
**After:**
```
--> main.rs:11:11
   |
11 |         xs->count += 1;
   |           ^^
   |
   = help: the `.` operator will automatically dereference the value, except if the value is a raw pointer
```

Read the original on github.com ↗