Skip to content

let _ = <access to unsafe field> currently type-checks #54003

Closed
@nikomatsakis

Description

@nikomatsakis

The following example passes the unsafe checker, but probably should not:

// #![feature(nll)]

union Foo {
    x: u32,
    y: u64
}

fn main() {
    let foo = Foo { x: 22 };
    let _ = foo.x;
}

The problem here is that let _ = foo.x is a no-op -- foo.x is a place expression, and the _ pattern just plain ignores it. This means that no MIR is generated. The unsafe checker runs on MIR.

But I think that we expect an error here nonetheless.

This is a regression that was introduced in the move to doing unsafe checking on MIR. I'm not sure the best way to fix: I tend to think we should do unsafe checking on HAIR, but that would be a fairly large effort. We could certainly generate a "dummy access" as we do with matches. (But we want to be careful about borrow checker interactions -- see #53114).

I'm nominating this for lang-team discussion — we do want an unsafe error here, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions