Skip to content

Commit 63b4764

Browse files
author
Saleem Jaffer
committed
refactor ExprKind to use new PointerCast enum
1 parent 6321a32 commit 63b4764

File tree

7 files changed

+21
-99
lines changed

7 files changed

+21
-99
lines changed

src/librustc/ty/structural_impls.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::hir::def::Namespace;
77
use crate::mir::ProjectionKind;
88
use crate::mir::interpret::ConstValue;
99
use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid};
10-
use crate::ty::adjustment::{PointerCast};
1110
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1211
use crate::ty::print::{FmtPrinter, Printer};
1312
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
@@ -327,6 +326,7 @@ CloneTypeFoldableAndLiftImpls! {
327326
crate::ty::IntVarValue,
328327
crate::ty::ParamConst,
329328
crate::ty::ParamTy,
329+
crate::ty::adjustment::PointerCast,
330330
crate::ty::RegionVid,
331331
crate::ty::UniverseIndex,
332332
crate::ty::Variance,
@@ -627,16 +627,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
627627
match *self {
628628
ty::adjustment::Adjust::NeverToAny =>
629629
Some(ty::adjustment::Adjust::NeverToAny),
630-
ty::adjustment::Adjust::Pointer(PointerCast::ReifyFnPointer) =>
631-
Some(ty::adjustment::Adjust::Pointer(PointerCast::ReifyFnPointer)),
632-
ty::adjustment::Adjust::Pointer(PointerCast::UnsafeFnPointer) =>
633-
Some(ty::adjustment::Adjust::Pointer(PointerCast::UnsafeFnPointer)),
634-
ty::adjustment::Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety)) =>
635-
Some(ty::adjustment::Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety))),
636-
ty::adjustment::Adjust::Pointer(PointerCast::MutToConstPointer) =>
637-
Some(ty::adjustment::Adjust::Pointer(PointerCast::MutToConstPointer)),
638-
ty::adjustment::Adjust::Pointer(PointerCast::Unsize) =>
639-
Some(ty::adjustment::Adjust::Pointer(PointerCast::Unsize)),
630+
ty::adjustment::Adjust::Pointer(ptr) =>
631+
Some(ty::adjustment::Adjust::Pointer(ptr)),
640632
ty::adjustment::Adjust::Deref(ref overloaded) => {
641633
tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
642634
}
@@ -1192,16 +1184,6 @@ EnumTypeFoldableImpl! {
11921184
}
11931185
}
11941186

1195-
EnumTypeFoldableImpl! {
1196-
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::PointerCast {
1197-
(ty::adjustment::PointerCast::ReifyFnPointer),
1198-
(ty::adjustment::PointerCast::UnsafeFnPointer),
1199-
(ty::adjustment::PointerCast::ClosureFnPointer)(a),
1200-
(ty::adjustment::PointerCast::MutToConstPointer),
1201-
(ty::adjustment::PointerCast::Unsize),
1202-
}
1203-
}
1204-
12051187
BraceStructTypeFoldableImpl! {
12061188
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
12071189
region, mutbl,

src/librustc_mir/build/expr/as_place.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
193193
| ExprKind::Cast { .. }
194194
| ExprKind::Use { .. }
195195
| ExprKind::NeverToAny { .. }
196-
| ExprKind::ReifyFnPointer { .. }
197-
| ExprKind::ClosureFnPointer { .. }
198-
| ExprKind::UnsafeFnPointer { .. }
199-
| ExprKind::MutToConstPointer { .. }
200-
| ExprKind::Unsize { .. }
196+
| ExprKind::Pointer { .. }
201197
| ExprKind::Repeat { .. }
202198
| ExprKind::Borrow { .. }
203199
| ExprKind::If { .. }

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc::middle::region;
1010
use rustc::mir::interpret::InterpError;
1111
use rustc::mir::*;
1212
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
13-
use rustc::ty::adjustment::{PointerCast};
1413
use syntax_pos::Span;
1514

1615
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
@@ -155,35 +154,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
155154
let source = unpack!(block = this.as_operand(block, scope, source));
156155
block.and(Rvalue::Use(source))
157156
}
158-
ExprKind::ReifyFnPointer { source } => {
157+
ExprKind::Pointer { cast, source } => {
159158
let source = unpack!(block = this.as_operand(block, scope, source));
160-
block.and(Rvalue::Cast(
161-
CastKind::Pointer(PointerCast::ReifyFnPointer), source, expr.ty)
162-
)
163-
}
164-
ExprKind::UnsafeFnPointer { source } => {
165-
let source = unpack!(block = this.as_operand(block, scope, source));
166-
block.and(Rvalue::Cast(
167-
CastKind::Pointer(PointerCast::UnsafeFnPointer), source, expr.ty)
168-
)
169-
}
170-
ExprKind::ClosureFnPointer { source, unsafety } => {
171-
let source = unpack!(block = this.as_operand(block, scope, source));
172-
block.and(Rvalue::Cast(
173-
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)), source, expr.ty)
174-
)
175-
}
176-
ExprKind::MutToConstPointer { source } => {
177-
let source = unpack!(block = this.as_operand(block, scope, source));
178-
block.and(Rvalue::Cast(
179-
CastKind::Pointer(PointerCast::MutToConstPointer), source, expr.ty)
180-
)
181-
}
182-
ExprKind::Unsize { source } => {
183-
let source = unpack!(block = this.as_operand(block, scope, source));
184-
block.and(Rvalue::Cast(
185-
CastKind::Pointer(PointerCast::Unsize), source, expr.ty)
186-
)
159+
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
187160
}
188161
ExprKind::Array { fields } => {
189162
// (*) We would (maybe) be closer to codegen if we

src/librustc_mir/build/expr/category.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ impl Category {
5959
| ExprKind::Box { .. }
6060
| ExprKind::Cast { .. }
6161
| ExprKind::Use { .. }
62-
| ExprKind::ReifyFnPointer { .. }
63-
| ExprKind::ClosureFnPointer { .. }
64-
| ExprKind::UnsafeFnPointer { .. }
65-
| ExprKind::MutToConstPointer { .. }
66-
| ExprKind::Unsize { .. }
62+
| ExprKind::Pointer { .. }
6763
| ExprKind::Repeat { .. }
6864
| ExprKind::Borrow { .. }
6965
| ExprKind::Assign { .. }

src/librustc_mir/build/expr/into.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
380380
| ExprKind::Box { .. }
381381
| ExprKind::Cast { .. }
382382
| ExprKind::Use { .. }
383-
| ExprKind::ReifyFnPointer { .. }
384-
| ExprKind::ClosureFnPointer { .. }
385-
| ExprKind::UnsafeFnPointer { .. }
386-
| ExprKind::MutToConstPointer { .. }
387-
| ExprKind::Unsize { .. }
383+
| ExprKind::Pointer { .. }
388384
| ExprKind::Repeat { .. }
389385
| ExprKind::Borrow { .. }
390386
| ExprKind::Array { .. }

src/librustc_mir/hair/cx/expr.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
7575
-> Expr<'tcx> {
7676
let Expr { temp_lifetime, mut span, .. } = expr;
7777
let kind = match adjustment.kind {
78-
Adjust::Pointer(PointerCast::ReifyFnPointer) => {
79-
ExprKind::ReifyFnPointer { source: expr.to_ref() }
80-
}
81-
Adjust::Pointer(PointerCast::UnsafeFnPointer) => {
82-
ExprKind::UnsafeFnPointer { source: expr.to_ref() }
78+
Adjust::Pointer(PointerCast::Unsize) => {
79+
if let ExprKind::Block { body } = expr.kind {
80+
if let Some(ref last_expr) = body.expr {
81+
span = last_expr.span;
82+
expr.span = span;
83+
}
84+
}
85+
ExprKind::Pointer { cast: PointerCast::Unsize, source: expr.to_ref() }
8386
}
84-
Adjust::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
85-
ExprKind::ClosureFnPointer { source: expr.to_ref(), unsafety }
87+
Adjust::Pointer(cast) => {
88+
ExprKind::Pointer { cast, source: expr.to_ref() }
8689
}
8790
Adjust::NeverToAny => {
8891
ExprKind::NeverToAny { source: expr.to_ref() }
8992
}
90-
Adjust::Pointer(PointerCast::MutToConstPointer) => {
91-
ExprKind::MutToConstPointer { source: expr.to_ref() }
92-
}
9393
Adjust::Deref(None) => {
9494
// Adjust the span from the block, to the last expression of the
9595
// 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>,
187187
// since they get rid of a borrow implicitly.
188188
ExprKind::Use { source: cast_expr.to_ref() }
189189
}
190-
Adjust::Pointer(PointerCast::Unsize) => {
191-
// See the above comment for Adjust::Deref
192-
if let ExprKind::Block { body } = expr.kind {
193-
if let Some(ref last_expr) = body.expr {
194-
span = last_expr.span;
195-
expr.span = span;
196-
}
197-
}
198-
ExprKind::Unsize { source: expr.to_ref() }
199-
}
200190
};
201191

202192
Expr {

src/librustc_mir/hair/mod.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc::infer::canonical::Canonical;
1010
use rustc::middle::region;
1111
use rustc::ty::subst::SubstsRef;
1212
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, UserType};
13+
use rustc::ty::adjustment::{PointerCast};
1314
use rustc::ty::layout::VariantIdx;
1415
use rustc::hir;
1516
use syntax_pos::Span;
@@ -180,20 +181,8 @@ pub enum ExprKind<'tcx> {
180181
NeverToAny {
181182
source: ExprRef<'tcx>,
182183
},
183-
ReifyFnPointer {
184-
source: ExprRef<'tcx>,
185-
},
186-
ClosureFnPointer {
187-
source: ExprRef<'tcx>,
188-
unsafety: hir::Unsafety,
189-
},
190-
UnsafeFnPointer {
191-
source: ExprRef<'tcx>,
192-
},
193-
MutToConstPointer {
194-
source: ExprRef<'tcx>,
195-
},
196-
Unsize {
184+
Pointer {
185+
cast: PointerCast,
197186
source: ExprRef<'tcx>,
198187
},
199188
If {

0 commit comments

Comments
 (0)