Support casting boxes to dyn*
This commit is contained in:
parent
02cd79afb8
commit
43499da753
2 changed files with 22 additions and 0 deletions
|
@ -14,6 +14,7 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
|
||||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
|
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
|
||||||
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
|
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
|
||||||
use rustc_span::source_map::{Span, DUMMY_SP};
|
use rustc_span::source_map::{Span, DUMMY_SP};
|
||||||
|
use rustc_target::abi::Size;
|
||||||
|
|
||||||
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
#[instrument(level = "trace", skip(self, bx))]
|
#[instrument(level = "trace", skip(self, bx))]
|
||||||
|
@ -285,6 +286,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
bug!("Only valid to do a DynStar cast into a DynStar type")
|
bug!("Only valid to do a DynStar cast into a DynStar type")
|
||||||
};
|
};
|
||||||
let vtable = get_vtable(bx.cx(), source.ty(self.mir, bx.tcx()), trait_ref);
|
let vtable = get_vtable(bx.cx(), source.ty(self.mir, bx.tcx()), trait_ref);
|
||||||
|
let data = match operand.layout.pointee_info_at(bx.cx(), Size::ZERO) {
|
||||||
|
Some(_) => bx.ptrtoint(data, bx.cx().type_isize()),
|
||||||
|
None => data,
|
||||||
|
};
|
||||||
OperandValue::Pair(data, vtable)
|
OperandValue::Pair(data, vtable)
|
||||||
}
|
}
|
||||||
mir::CastKind::Pointer(
|
mir::CastKind::Pointer(
|
||||||
|
|
17
src/test/ui/dyn-star/box.rs
Normal file
17
src/test/ui/dyn-star/box.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// run-pass
|
||||||
|
// compile-flags: -C opt-level=0
|
||||||
|
|
||||||
|
#![feature(dyn_star)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
fn make_dyn_star() -> dyn* Display {
|
||||||
|
Box::new(42) as dyn* Display
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = make_dyn_star();
|
||||||
|
|
||||||
|
println!("{x}");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue