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

Confusing error message when coercing an array reference to a pointer of the wrong type #138836

Open
yshui opened this issue Mar 22, 2025 · 1 comment
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

@yshui
Copy link
Contributor

yshui commented Mar 22, 2025

Code

fn main() {
    let a: [u8; 3] = [1,2,3];
    let b = &a;
    let c = b as *const [u32; 3];
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:4:13
  |
4 |     let c = b as *const [u32; 3];
  |             ^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `[u32; 3]`

Desired output

error[E0308]: mismatched types
 --> src/main.rs:4:13
  |
4 |     let c = b as *const [u32; 3];
  |             ^^^^^^^^^^^^^^^^^^^^ expected `[u8; 3]`, found `[u32; 3]`

// Alternatively: expected `u8`, found `u32`

Rationale and extra context

Current error message seems to suggest I am trying to convert a &u8 to *const [u32; 3] when I am actually trying to convert a &[u8; 3].

Other cases

Rust Version

1.87.0-nightly

(2025-03-21 be73c1f4617c97bce81b)

Anything else?

No response

@yshui yshui 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 Mar 22, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

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

No branches or pull requests

2 participants