refactor ExprKind to use new PointerCast enum
This commit is contained in:
@@ -7,7 +7,6 @@ use crate::hir::def::Namespace;
|
|||||||
use crate::mir::ProjectionKind;
|
use crate::mir::ProjectionKind;
|
||||||
use crate::mir::interpret::ConstValue;
|
use crate::mir::interpret::ConstValue;
|
||||||
use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid};
|
use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid};
|
||||||
use crate::ty::adjustment::{PointerCast};
|
|
||||||
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
use crate::ty::print::{FmtPrinter, Printer};
|
use crate::ty::print::{FmtPrinter, Printer};
|
||||||
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
||||||
@@ -327,6 +326,7 @@ CloneTypeFoldableAndLiftImpls! {
|
|||||||
crate::ty::IntVarValue,
|
crate::ty::IntVarValue,
|
||||||
crate::ty::ParamConst,
|
crate::ty::ParamConst,
|
||||||
crate::ty::ParamTy,
|
crate::ty::ParamTy,
|
||||||
|
crate::ty::adjustment::PointerCast,
|
||||||
crate::ty::RegionVid,
|
crate::ty::RegionVid,
|
||||||
crate::ty::UniverseIndex,
|
crate::ty::UniverseIndex,
|
||||||
crate::ty::Variance,
|
crate::ty::Variance,
|
||||||
@@ -627,16 +627,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
|
|||||||
match *self {
|
match *self {
|
||||||
ty::adjustment::Adjust::NeverToAny =>
|
ty::adjustment::Adjust::NeverToAny =>
|
||||||
Some(ty::adjustment::Adjust::NeverToAny),
|
Some(ty::adjustment::Adjust::NeverToAny),
|
||||||
ty::adjustment::Adjust::Pointer(PointerCast::ReifyFnPointer) =>
|
ty::adjustment::Adjust::Pointer(ptr) =>
|
||||||
Some(ty::adjustment::Adjust::Pointer(PointerCast::ReifyFnPointer)),
|
Some(ty::adjustment::Adjust::Pointer(ptr)),
|
||||||
ty::adjustment::Adjust::Pointer(PointerCast::UnsafeFnPointer) =>
|
|
||||||
Some(ty::adjustment::Adjust::Pointer(PointerCast::UnsafeFnPointer)),
|
|
||||||
ty::adjustment::Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety)) =>
|
|
||||||
Some(ty::adjustment::Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety))),
|
|
||||||
ty::adjustment::Adjust::Pointer(PointerCast::MutToConstPointer) =>
|
|
||||||
Some(ty::adjustment::Adjust::Pointer(PointerCast::MutToConstPointer)),
|
|
||||||
ty::adjustment::Adjust::Pointer(PointerCast::Unsize) =>
|
|
||||||
Some(ty::adjustment::Adjust::Pointer(PointerCast::Unsize)),
|
|
||||||
ty::adjustment::Adjust::Deref(ref overloaded) => {
|
ty::adjustment::Adjust::Deref(ref overloaded) => {
|
||||||
tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
|
tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
|
||||||
}
|
}
|
||||||
@@ -1192,16 +1184,6 @@ EnumTypeFoldableImpl! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnumTypeFoldableImpl! {
|
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::PointerCast {
|
|
||||||
(ty::adjustment::PointerCast::ReifyFnPointer),
|
|
||||||
(ty::adjustment::PointerCast::UnsafeFnPointer),
|
|
||||||
(ty::adjustment::PointerCast::ClosureFnPointer)(a),
|
|
||||||
(ty::adjustment::PointerCast::MutToConstPointer),
|
|
||||||
(ty::adjustment::PointerCast::Unsize),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BraceStructTypeFoldableImpl! {
|
BraceStructTypeFoldableImpl! {
|
||||||
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
|
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
|
||||||
region, mutbl,
|
region, mutbl,
|
||||||
|
|||||||
@@ -193,11 +193,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||||||
| ExprKind::Cast { .. }
|
| ExprKind::Cast { .. }
|
||||||
| ExprKind::Use { .. }
|
| ExprKind::Use { .. }
|
||||||
| ExprKind::NeverToAny { .. }
|
| ExprKind::NeverToAny { .. }
|
||||||
| ExprKind::ReifyFnPointer { .. }
|
| ExprKind::Pointer { .. }
|
||||||
| ExprKind::ClosureFnPointer { .. }
|
|
||||||
| ExprKind::UnsafeFnPointer { .. }
|
|
||||||
| ExprKind::MutToConstPointer { .. }
|
|
||||||
| ExprKind::Unsize { .. }
|
|
||||||
| ExprKind::Repeat { .. }
|
| ExprKind::Repeat { .. }
|
||||||
| ExprKind::Borrow { .. }
|
| ExprKind::Borrow { .. }
|
||||||
| ExprKind::If { .. }
|
| ExprKind::If { .. }
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use rustc::middle::region;
|
|||||||
use rustc::mir::interpret::InterpError;
|
use rustc::mir::interpret::InterpError;
|
||||||
use rustc::mir::*;
|
use rustc::mir::*;
|
||||||
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
|
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
|
||||||
use rustc::ty::adjustment::{PointerCast};
|
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
@@ -155,35 +154,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
let source = unpack!(block = this.as_operand(block, scope, source));
|
||||||
block.and(Rvalue::Use(source))
|
block.and(Rvalue::Use(source))
|
||||||
}
|
}
|
||||||
ExprKind::ReifyFnPointer { source } => {
|
ExprKind::Pointer { cast, source } => {
|
||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
let source = unpack!(block = this.as_operand(block, scope, source));
|
||||||
block.and(Rvalue::Cast(
|
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
|
||||||
CastKind::Pointer(PointerCast::ReifyFnPointer), source, expr.ty)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ExprKind::UnsafeFnPointer { source } => {
|
|
||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
|
||||||
block.and(Rvalue::Cast(
|
|
||||||
CastKind::Pointer(PointerCast::UnsafeFnPointer), source, expr.ty)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ExprKind::ClosureFnPointer { source, unsafety } => {
|
|
||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
|
||||||
block.and(Rvalue::Cast(
|
|
||||||
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)), source, expr.ty)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ExprKind::MutToConstPointer { source } => {
|
|
||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
|
||||||
block.and(Rvalue::Cast(
|
|
||||||
CastKind::Pointer(PointerCast::MutToConstPointer), source, expr.ty)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ExprKind::Unsize { source } => {
|
|
||||||
let source = unpack!(block = this.as_operand(block, scope, source));
|
|
||||||
block.and(Rvalue::Cast(
|
|
||||||
CastKind::Pointer(PointerCast::Unsize), source, expr.ty)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ExprKind::Array { fields } => {
|
ExprKind::Array { fields } => {
|
||||||
// (*) We would (maybe) be closer to codegen if we
|
// (*) We would (maybe) be closer to codegen if we
|
||||||
|
|||||||
@@ -59,11 +59,7 @@ impl Category {
|
|||||||
| ExprKind::Box { .. }
|
| ExprKind::Box { .. }
|
||||||
| ExprKind::Cast { .. }
|
| ExprKind::Cast { .. }
|
||||||
| ExprKind::Use { .. }
|
| ExprKind::Use { .. }
|
||||||
| ExprKind::ReifyFnPointer { .. }
|
| ExprKind::Pointer { .. }
|
||||||
| ExprKind::ClosureFnPointer { .. }
|
|
||||||
| ExprKind::UnsafeFnPointer { .. }
|
|
||||||
| ExprKind::MutToConstPointer { .. }
|
|
||||||
| ExprKind::Unsize { .. }
|
|
||||||
| ExprKind::Repeat { .. }
|
| ExprKind::Repeat { .. }
|
||||||
| ExprKind::Borrow { .. }
|
| ExprKind::Borrow { .. }
|
||||||
| ExprKind::Assign { .. }
|
| ExprKind::Assign { .. }
|
||||||
|
|||||||
@@ -380,11 +380,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||||||
| ExprKind::Box { .. }
|
| ExprKind::Box { .. }
|
||||||
| ExprKind::Cast { .. }
|
| ExprKind::Cast { .. }
|
||||||
| ExprKind::Use { .. }
|
| ExprKind::Use { .. }
|
||||||
| ExprKind::ReifyFnPointer { .. }
|
| ExprKind::Pointer { .. }
|
||||||
| ExprKind::ClosureFnPointer { .. }
|
|
||||||
| ExprKind::UnsafeFnPointer { .. }
|
|
||||||
| ExprKind::MutToConstPointer { .. }
|
|
||||||
| ExprKind::Unsize { .. }
|
|
||||||
| ExprKind::Repeat { .. }
|
| ExprKind::Repeat { .. }
|
||||||
| ExprKind::Borrow { .. }
|
| ExprKind::Borrow { .. }
|
||||||
| ExprKind::Array { .. }
|
| ExprKind::Array { .. }
|
||||||
|
|||||||
@@ -75,21 +75,21 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||||||
-> Expr<'tcx> {
|
-> Expr<'tcx> {
|
||||||
let Expr { temp_lifetime, mut span, .. } = expr;
|
let Expr { temp_lifetime, mut span, .. } = expr;
|
||||||
let kind = match adjustment.kind {
|
let kind = match adjustment.kind {
|
||||||
Adjust::Pointer(PointerCast::ReifyFnPointer) => {
|
Adjust::Pointer(PointerCast::Unsize) => {
|
||||||
ExprKind::ReifyFnPointer { source: expr.to_ref() }
|
if let ExprKind::Block { body } = expr.kind {
|
||||||
|
if let Some(ref last_expr) = body.expr {
|
||||||
|
span = last_expr.span;
|
||||||
|
expr.span = span;
|
||||||
}
|
}
|
||||||
Adjust::Pointer(PointerCast::UnsafeFnPointer) => {
|
|
||||||
ExprKind::UnsafeFnPointer { source: expr.to_ref() }
|
|
||||||
}
|
}
|
||||||
Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
|
ExprKind::Pointer { cast: PointerCast::Unsize, source: expr.to_ref() }
|
||||||
ExprKind::ClosureFnPointer { source: expr.to_ref(), unsafety }
|
}
|
||||||
|
Adjust::Pointer(cast) => {
|
||||||
|
ExprKind::Pointer { cast, source: expr.to_ref() }
|
||||||
}
|
}
|
||||||
Adjust::NeverToAny => {
|
Adjust::NeverToAny => {
|
||||||
ExprKind::NeverToAny { source: expr.to_ref() }
|
ExprKind::NeverToAny { source: expr.to_ref() }
|
||||||
}
|
}
|
||||||
Adjust::Pointer(PointerCast::MutToConstPointer) => {
|
|
||||||
ExprKind::MutToConstPointer { source: expr.to_ref() }
|
|
||||||
}
|
|
||||||
Adjust::Deref(None) => {
|
Adjust::Deref(None) => {
|
||||||
// Adjust the span from the block, to the last expression of the
|
// Adjust the span from the block, to the last expression of the
|
||||||
// block. This is a better span when returning a mutable reference
|
// block. This is a better span when returning a mutable reference
|
||||||
@@ -187,16 +187,6 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
|||||||
// since they get rid of a borrow implicitly.
|
// since they get rid of a borrow implicitly.
|
||||||
ExprKind::Use { source: cast_expr.to_ref() }
|
ExprKind::Use { source: cast_expr.to_ref() }
|
||||||
}
|
}
|
||||||
Adjust::Pointer(PointerCast::Unsize) => {
|
|
||||||
// See the above comment for Adjust::Deref
|
|
||||||
if let ExprKind::Block { body } = expr.kind {
|
|
||||||
if let Some(ref last_expr) = body.expr {
|
|
||||||
span = last_expr.span;
|
|
||||||
expr.span = span;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExprKind::Unsize { source: expr.to_ref() }
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Expr {
|
Expr {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use rustc::infer::canonical::Canonical;
|
|||||||
use rustc::middle::region;
|
use rustc::middle::region;
|
||||||
use rustc::ty::subst::SubstsRef;
|
use rustc::ty::subst::SubstsRef;
|
||||||
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, UserType};
|
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, UserType};
|
||||||
|
use rustc::ty::adjustment::{PointerCast};
|
||||||
use rustc::ty::layout::VariantIdx;
|
use rustc::ty::layout::VariantIdx;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
@@ -180,20 +181,8 @@ pub enum ExprKind<'tcx> {
|
|||||||
NeverToAny {
|
NeverToAny {
|
||||||
source: ExprRef<'tcx>,
|
source: ExprRef<'tcx>,
|
||||||
},
|
},
|
||||||
ReifyFnPointer {
|
Pointer {
|
||||||
source: ExprRef<'tcx>,
|
cast: PointerCast,
|
||||||
},
|
|
||||||
ClosureFnPointer {
|
|
||||||
source: ExprRef<'tcx>,
|
|
||||||
unsafety: hir::Unsafety,
|
|
||||||
},
|
|
||||||
UnsafeFnPointer {
|
|
||||||
source: ExprRef<'tcx>,
|
|
||||||
},
|
|
||||||
MutToConstPointer {
|
|
||||||
source: ExprRef<'tcx>,
|
|
||||||
},
|
|
||||||
Unsize {
|
|
||||||
source: ExprRef<'tcx>,
|
source: ExprRef<'tcx>,
|
||||||
},
|
},
|
||||||
If {
|
If {
|
||||||
|
|||||||
Reference in New Issue
Block a user