Skip to content

ctfe validation on unaligned references does not mention expected / provided alignment #58617

Closed
@gnzlbg

Description

@gnzlbg

This code (playground):

fn main() {
    unsafe {
        use std::mem::transmute;
        let a = 0_u8;
        let b = &a as *const u8 as *const u64;
        //let _c: &u64 = transmute(b);
        let _d = *b;
    }
}

errors under miri with

tried to access memory with alignment 1, but alignment 8 is required

This snippet, however (playground):

fn main() {
    unsafe {
        use std::mem::transmute;
        let a = 0_u8;
        let b = &a as *const u8 as *const u64;
        let _c: &u64 = transmute(b);
        //let _d = *b;
    }
}

errors with

type validation failed: encountered unaligned reference

It would be great if this error about the validity of references would also state that "alignment 1, but alignment 8 is required" or similar.

cc @oli-obk @RalfJung

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions