Closed
Description
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 allocatingsize + (align 1)
... which actually I guess would have to be done viaalloca
if we cannot put an upper-bound onalign
... 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.