Skip to content

E0606 could be auto-applicable in some cases #106903

Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

fn main() {
    let x = &0u8;
    let y: u32 = x as u32;
}

Current output

error[E0606]: casting `&u8` as `u32` is invalid
 --> src/lib.rs:3:18
  |
3 |     let y: u32 = x as u32;
  |                  -^^^^^^^
  |                  |
  |                  cannot cast `&u8` as `u32`
  |                  help: dereference the expression: `*x`

Desired output

No response

Rationale and extra context

The x as u32 => *x transformation is trivial here, we should be able to do this with cargo fix --broken-code imo. All remaining suggestions can already be applied so rustc can fix this code into let y: u32 = (*x).into();

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions