Skip to content
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

Improve diagnostics for incorrect double pointer type #102261

Closed
Rageking8 opened this issue Sep 25, 2022 · 1 comment · Fixed by #102284
Closed

Improve diagnostics for incorrect double pointer type #102261

Rageking8 opened this issue Sep 25, 2022 · 1 comment · Fixed by #102284
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rageking8
Copy link
Contributor

Given the following code: link

fn main() {
    let x: i32 = 5;
    let ptr: *const i32 = &x;
    let dptr: **const i32 = &ptr;
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected mut or const in raw pointer type
 --> src/main.rs:4:15
  |
4 |     let dptr: **const i32 = &ptr;
  |               ^ expected mut or const in raw pointer type
  |
  = help: use `*mut T` or `*const T` as appropriate

error: could not compile `playground` due to previous error

Ideally the output should suggest correct ways to specify a double pointer type (e.g. *const *const T)(May be able to extend for more levels of indirection if wanted), instead of a generic single pointer suggestion, which may not be what the user wants.

@Rageking8 Rageking8 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 25, 2022
@compiler-errors
Copy link
Member

I think this message is fine as it. I guess it could be slightly more specific -- saying "expected const or mut keyword in raw pointer type"

@compiler-errors compiler-errors self-assigned this Sep 25, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 27, 2022
…w-ptr, r=davidtwco

Structured suggestion for missing `mut`/`const` in raw pointer

Fixes rust-lang#102261
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 27, 2022
…w-ptr, r=davidtwco

Structured suggestion for missing `mut`/`const` in raw pointer

Fixes rust-lang#102261
@bors bors closed this as completed in 8b635cb Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants