-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-opt-inliningArea: MIR inliningArea: MIR inliningC-bugCategory: This is a bug.Category: This is a bug.F-unsized_fn_params`#![feature(unsized_fn_params)]``#![feature(unsized_fn_params)]`requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
Inlining introduces unsized temporaries. This is problematic since unsized temporaries fail to uphold alignment requirements as described in #71416. For example:
#![feature(unsized_fn_params)]
use std::any::Any;
use std::hint::black_box;
#[repr(align(1024))]
#[allow(dead_code)]
struct A(u8);
impl A {
fn f(&self) {
assert_eq!(0, black_box(self as *const A as usize) % 1024);
}
}
#[inline(always)]
pub fn f(a: dyn Any) {
a.downcast_ref::<A>().unwrap().f()
}
pub fn main() {
let a = Box::new(A(0)) as Box<dyn Any>;
f(*a);
}
$ rustc d.rs -O -Zinline-mir=off && ./d
$ rustc d.rs -O && ./d
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `0`,
right: `992`', d.rs:11:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-mir-opt-inliningArea: MIR inliningArea: MIR inliningC-bugCategory: This is a bug.Category: This is a bug.F-unsized_fn_params`#![feature(unsized_fn_params)]``#![feature(unsized_fn_params)]`requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.