Skip to content

Deref coercions and &-to-* coercions don't compose #32122

Closed
@carlpaten

Description

@carlpaten

Minimal repro:

use std::ops::Deref;

struct A (u8);

impl Deref for A {
    type Target = u8;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn main() {
    let a = A(0);

    //compiles
    let b: &u8 = &a;
    let c: *const u8 = b;

    //error
    let d: *const u8 = &a;
}

Compile error:

coerce.rs:15:24: 15:26 error: mismatched types:
 expected `*const u8`,
    found `&A`
(expected u8,
    found struct `A`) [E0308]
coerce.rs:15     let c: *const u8 = &a;
                                    ^~
coerce.rs:15:24: 15:26 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-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