Rename adjustment::PointerCast
and variants using it to PointerCoercion
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
This commit is contained in:
parent
fd68a6ded9
commit
2beabbbf6f
85 changed files with 214 additions and 185 deletions
|
@ -11,7 +11,7 @@ use rustc_middle::mir;
|
|||
use rustc_middle::mir::Operand;
|
||||
use rustc_middle::ty::cast::{CastTy, IntTy};
|
||||
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, adjustment::PointerCoercion, Instance, Ty, TyCtxt};
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::source_map::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{self, FIRST_VARIANT};
|
||||
|
@ -32,7 +32,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
cg_operand.val.store(bx, dest);
|
||||
}
|
||||
|
||||
mir::Rvalue::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref source, _) => {
|
||||
mir::Rvalue::Cast(
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::Unsize),
|
||||
ref source,
|
||||
_,
|
||||
) => {
|
||||
// The destination necessarily contains a fat pointer, so if
|
||||
// it's a scalar pair, it's a fat pointer or newtype thereof.
|
||||
if bx.cx().is_backend_scalar_pair(dest.layout) {
|
||||
|
@ -411,7 +415,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
let lladdr = bx.ptrtoint(llptr, llcast_ty);
|
||||
OperandValue::Immediate(lladdr)
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => {
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => {
|
||||
match *operand.layout.ty.kind() {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
let instance = ty::Instance::resolve_for_fn_ptr(
|
||||
|
@ -427,7 +431,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
_ => bug!("{} cannot be reified to a fn ptr", operand.layout.ty),
|
||||
}
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_)) => {
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)) => {
|
||||
match *operand.layout.ty.kind() {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let instance = Instance::resolve_closure(
|
||||
|
@ -443,11 +447,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
_ => bug!("{} cannot be cast to a fn ptr", operand.layout.ty),
|
||||
}
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::UnsafeFnPointer) => {
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer) => {
|
||||
// This is a no-op at the LLVM level.
|
||||
operand.val
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::Unsize) => {
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::Unsize) => {
|
||||
assert!(bx.cx().is_backend_scalar_pair(cast));
|
||||
let (lldata, llextra) = match operand.val {
|
||||
OperandValue::Pair(lldata, llextra) => {
|
||||
|
@ -470,7 +474,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
base::unsize_ptr(bx, lldata, operand.layout.ty, cast.ty, llextra);
|
||||
OperandValue::Pair(lldata, llextra)
|
||||
}
|
||||
mir::CastKind::Pointer(PointerCast::MutToConstPointer)
|
||||
mir::CastKind::PointerCoercion(PointerCoercion::MutToConstPointer)
|
||||
| mir::CastKind::PtrToPtr
|
||||
if bx.cx().is_backend_scalar_pair(operand.layout) =>
|
||||
{
|
||||
|
@ -504,8 +508,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
base::cast_to_dyn_star(bx, lldata, operand.layout, cast.ty, llextra);
|
||||
OperandValue::Pair(lldata, llextra)
|
||||
}
|
||||
mir::CastKind::Pointer(
|
||||
PointerCast::MutToConstPointer | PointerCast::ArrayToPointer,
|
||||
mir::CastKind::PointerCoercion(
|
||||
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
|
||||
)
|
||||
| mir::CastKind::IntToInt
|
||||
| mir::CastKind::FloatToInt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue