summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsized-locals/align.rs
blob: 01be8f3bb9c90b8b807db9270a618c7e075d8e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Test that unsized locals uphold alignment requirements.
// Regression test for #71416.
// run-pass
#![feature(unsized_locals)]
#![allow(incomplete_features)]
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);
}