Skip to content

Separate unsized_locals into "sound" and "unsound" (i.e. incorrectly implemented) parts #71694

Closed
@pnkfelix

Description

@pnkfelix

Spawned off of #71416

Here is the example from that issue's description:

This is a variant of #68304 that was not fixed by #71170:

#![feature(unsized_locals)]

use std::any::Any;

#[repr(align(256))]
#[allow(dead_code)]
struct A {
    v: u8
}

impl A {
    fn f(&self) -> *const A {
        assert_eq!(self as *const A as usize % 256, 0);
        self
    }
}

fn mk() -> Box<dyn Any> {
    Box::new(A { v: 4 })
}

fn main() {
    let x = *mk();
    let dwncst = x.downcast_ref::<A>().unwrap();
    let addr = dwncst.f();
    assert_eq!(addr as usize % 256, 0);
}

What we want is to factor unsized_locals into two features (either giving both fresh names or just allocating one fresh name, it doesn't matter all that much), where one of the two named features would only enable support for cases that we have actually implemented (correctly).

  • Specifically, we do not currently handle alignment of dyn Value because we would need to query that alignment dynamically and adjust the stack address accordingly (and allowing for such adjustment by allocating size + (align 1) ... which actually I guess would have to be done via alloca if we cannot put an upper-bound on align ... anyway I digress...)

Anyway, this issue is just about creating the new feature name(s), and splitting the current unsized_locals support accordingly, so that crates (specifically the internals of libstd) can opt into supporting just the construct that we know we have actually implemented properly.

Metadata

Metadata

Assignees

Labels

F-unsized_locals`#![feature(unsized_locals)]`P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions