Skip to content

Commit d0c1e5a

Browse files
committed
rustfmt src/librustc_mir/build/expr
1 parent 527a29a commit d0c1e5a

File tree

9 files changed

+656
-446
lines changed

9 files changed

+656
-446
lines changed

src/librustc_mir/build/expr/as_constant.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1818
/// Compile `expr`, yielding a compile-time constant. Assumes that
1919
/// `expr` is a valid compile-time constant!
2020
pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
21-
where M: Mirror<'tcx, Output=Expr<'tcx>>
21+
where
22+
M: Mirror<'tcx, Output = Expr<'tcx>>,
2223
{
2324
let expr = self.hir.mirror(expr);
2425
self.expr_as_constant(expr)
2526
}
2627

2728
fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'tcx> {
2829
let this = self;
29-
let Expr { ty, temp_lifetime: _, span, kind }
30-
= expr;
30+
let Expr {
31+
ty,
32+
temp_lifetime: _,
33+
span,
34+
kind,
35+
} = expr;
3136
match kind {
32-
ExprKind::Scope { region_scope: _, lint_level: _, value } =>
33-
this.as_constant(value),
34-
ExprKind::Literal { literal, user_ty } =>
35-
Constant { span, ty, user_ty, literal },
36-
_ =>
37-
span_bug!(
38-
span,
39-
"expression is not a valid constant {:?}",
40-
kind),
37+
ExprKind::Scope {
38+
region_scope: _,
39+
lint_level: _,
40+
value,
41+
} => this.as_constant(value),
42+
ExprKind::Literal { literal, user_ty } => Constant {
43+
span,
44+
ty,
45+
user_ty,
46+
literal,
47+
},
48+
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
4149
}
4250
}
4351
}

src/librustc_mir/build/expr/as_operand.rs

+30-20
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
//! See docs in build/expr/mod.rs
1212
13-
use build::{BlockAnd, BlockAndExtension, Builder};
1413
use build::expr::category::Category;
14+
use build::{BlockAnd, BlockAndExtension, Builder};
1515
use hair::*;
1616
use rustc::middle::region;
1717
use rustc::mir::*;
@@ -23,9 +23,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2323
/// The operand returned from this function will *not be valid* after
2424
/// an ExprKind::Scope is passed, so please do *not* return it from
2525
/// functions to avoid bad miscompiles.
26-
pub fn as_local_operand<M>(&mut self, block: BasicBlock, expr: M)
27-
-> BlockAnd<Operand<'tcx>>
28-
where M: Mirror<'tcx, Output = Expr<'tcx>>
26+
pub fn as_local_operand<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Operand<'tcx>>
27+
where
28+
M: Mirror<'tcx, Output = Expr<'tcx>>,
2929
{
3030
let local_scope = self.local_scope();
3131
self.as_operand(block, local_scope, expr)
@@ -37,25 +37,34 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3737
/// this time.
3838
///
3939
/// The operand is known to be live until the end of `scope`.
40-
pub fn as_operand<M>(&mut self,
41-
block: BasicBlock,
42-
scope: Option<region::Scope>,
43-
expr: M) -> BlockAnd<Operand<'tcx>>
44-
where M: Mirror<'tcx, Output = Expr<'tcx>>
40+
pub fn as_operand<M>(
41+
&mut self,
42+
block: BasicBlock,
43+
scope: Option<region::Scope>,
44+
expr: M,
45+
) -> BlockAnd<Operand<'tcx>>
46+
where
47+
M: Mirror<'tcx, Output = Expr<'tcx>>,
4548
{
4649
let expr = self.hir.mirror(expr);
4750
self.expr_as_operand(block, scope, expr)
4851
}
4952

50-
fn expr_as_operand(&mut self,
51-
mut block: BasicBlock,
52-
scope: Option<region::Scope>,
53-
expr: Expr<'tcx>)
54-
-> BlockAnd<Operand<'tcx>> {
53+
fn expr_as_operand(
54+
&mut self,
55+
mut block: BasicBlock,
56+
scope: Option<region::Scope>,
57+
expr: Expr<'tcx>,
58+
) -> BlockAnd<Operand<'tcx>> {
5559
debug!("expr_as_operand(block={:?}, expr={:?})", block, expr);
5660
let this = self;
5761

58-
if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
62+
if let ExprKind::Scope {
63+
region_scope,
64+
lint_level,
65+
value,
66+
} = expr.kind
67+
{
5968
let source_info = this.source_info(expr.span);
6069
let region_scope = (region_scope, source_info);
6170
return this.in_scope(region_scope, lint_level, block, |this| {
@@ -64,16 +73,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
6473
}
6574

6675
let category = Category::of(&expr.kind).unwrap();
67-
debug!("expr_as_operand: category={:?} for={:?}", category, expr.kind);
76+
debug!(
77+
"expr_as_operand: category={:?} for={:?}",
78+
category, expr.kind
79+
);
6880
match category {
6981
Category::Constant => {
7082
let constant = this.as_constant(expr);
7183
block.and(Operand::Constant(box constant))
7284
}
73-
Category::Place |
74-
Category::Rvalue(..) => {
75-
let operand =
76-
unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
85+
Category::Place | Category::Rvalue(..) => {
86+
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
7787
block.and(Operand::Move(Place::Local(operand)))
7888
}
7989
}

src/librustc_mir/build/expr/as_place.rs

+93-79
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@
1010

1111
//! See docs in build/expr/mod.rs
1212
13-
use build::{BlockAnd, BlockAndExtension, Builder};
14-
use build::ForGuard::{OutsideGuard, RefWithinGuard};
1513
use build::expr::category::Category;
14+
use build::ForGuard::{OutsideGuard, RefWithinGuard};
15+
use build::{BlockAnd, BlockAndExtension, Builder};
1616
use hair::*;
17-
use rustc::mir::*;
1817
use rustc::mir::interpret::EvalErrorKind::BoundsCheck;
18+
use rustc::mir::*;
1919

2020
use rustc_data_structures::indexed_vec::Idx;
2121

2222
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
2323
/// Compile `expr`, yielding a place that we can move from etc.
24-
pub fn as_place<M>(&mut self,
25-
block: BasicBlock,
26-
expr: M)
27-
-> BlockAnd<Place<'tcx>>
28-
where M: Mirror<'tcx, Output=Expr<'tcx>>
24+
pub fn as_place<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Place<'tcx>>
25+
where
26+
M: Mirror<'tcx, Output = Expr<'tcx>>,
2927
{
3028
let expr = self.hir.mirror(expr);
3129
self.expr_as_place(block, expr, Mutability::Mut)
@@ -36,36 +34,40 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3634
/// place. The place itself may or may not be mutable:
3735
/// * If this expr is a place expr like a.b, then we will return that place.
3836
/// * Otherwise, a temporary is created: in that event, it will be an immutable temporary.
39-
pub fn as_read_only_place<M>(&mut self,
40-
block: BasicBlock,
41-
expr: M)
42-
-> BlockAnd<Place<'tcx>>
43-
where M: Mirror<'tcx, Output=Expr<'tcx>>
37+
pub fn as_read_only_place<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Place<'tcx>>
38+
where
39+
M: Mirror<'tcx, Output = Expr<'tcx>>,
4440
{
4541
let expr = self.hir.mirror(expr);
4642
self.expr_as_place(block, expr, Mutability::Not)
4743
}
4844

49-
fn expr_as_place(&mut self,
50-
mut block: BasicBlock,
51-
expr: Expr<'tcx>,
52-
mutability: Mutability)
53-
-> BlockAnd<Place<'tcx>> {
54-
debug!("expr_as_place(block={:?}, expr={:?}, mutability={:?})", block, expr, mutability);
45+
fn expr_as_place(
46+
&mut self,
47+
mut block: BasicBlock,
48+
expr: Expr<'tcx>,
49+
mutability: Mutability,
50+
) -> BlockAnd<Place<'tcx>> {
51+
debug!(
52+
"expr_as_place(block={:?}, expr={:?}, mutability={:?})",
53+
block, expr, mutability
54+
);
5555

5656
let this = self;
5757
let expr_span = expr.span;
5858
let source_info = this.source_info(expr_span);
5959
match expr.kind {
60-
ExprKind::Scope { region_scope, lint_level, value } => {
61-
this.in_scope((region_scope, source_info), lint_level, block, |this| {
62-
if mutability == Mutability::Not {
63-
this.as_read_only_place(block, value)
64-
} else {
65-
this.as_place(block, value)
66-
}
67-
})
68-
}
60+
ExprKind::Scope {
61+
region_scope,
62+
lint_level,
63+
value,
64+
} => this.in_scope((region_scope, source_info), lint_level, block, |this| {
65+
if mutability == Mutability::Not {
66+
this.as_read_only_place(block, value)
67+
} else {
68+
this.as_place(block, value)
69+
}
70+
}),
6971
ExprKind::Field { lhs, name } => {
7072
let place = unpack!(block = this.as_place(block, lhs));
7173
let place = place.field(name, expr.ty);
@@ -86,29 +88,40 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8688
let idx = unpack!(block = this.as_temp(block, None, index, Mutability::Mut));
8789

8890
// bounds check:
89-
let (len, lt) = (this.temp(usize_ty.clone(), expr_span),
90-
this.temp(bool_ty, expr_span));
91-
this.cfg.push_assign(block, source_info, // len = len(slice)
92-
&len, Rvalue::Len(slice.clone()));
93-
this.cfg.push_assign(block, source_info, // lt = idx < len
94-
&lt, Rvalue::BinaryOp(BinOp::Lt,
95-
Operand::Copy(Place::Local(idx)),
96-
Operand::Copy(len.clone())));
91+
let (len, lt) = (
92+
this.temp(usize_ty.clone(), expr_span),
93+
this.temp(bool_ty, expr_span),
94+
);
95+
this.cfg.push_assign(
96+
block,
97+
source_info, // len = len(slice)
98+
&len,
99+
Rvalue::Len(slice.clone()),
100+
);
101+
this.cfg.push_assign(
102+
block,
103+
source_info, // lt = idx < len
104+
&lt,
105+
Rvalue::BinaryOp(
106+
BinOp::Lt,
107+
Operand::Copy(Place::Local(idx)),
108+
Operand::Copy(len.clone()),
109+
),
110+
);
97111

98112
let msg = BoundsCheck {
99113
len: Operand::Move(len),
100-
index: Operand::Copy(Place::Local(idx))
114+
index: Operand::Copy(Place::Local(idx)),
101115
};
102-
let success = this.assert(block, Operand::Move(lt), true,
103-
msg, expr_span);
116+
let success = this.assert(block, Operand::Move(lt), true, msg, expr_span);
104117
success.and(slice.index(idx))
105118
}
106-
ExprKind::SelfRef => {
107-
block.and(Place::Local(Local::new(1)))
108-
}
119+
ExprKind::SelfRef => block.and(Place::Local(Local::new(1))),
109120
ExprKind::VarRef { id } => {
110-
let place = if this.is_bound_var_in_guard(id) &&
111-
this.hir.tcx().all_pat_vars_are_implicit_refs_within_guards()
121+
let place = if this.is_bound_var_in_guard(id) && this
122+
.hir
123+
.tcx()
124+
.all_pat_vars_are_implicit_refs_within_guards()
112125
{
113126
let index = this.var_local_id(id, RefWithinGuard);
114127
Place::Local(index).deref()
@@ -118,47 +131,48 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
118131
};
119132
block.and(place)
120133
}
121-
ExprKind::StaticRef { id } => {
122-
block.and(Place::Static(Box::new(Static { def_id: id, ty: expr.ty })))
123-
}
134+
ExprKind::StaticRef { id } => block.and(Place::Static(Box::new(Static {
135+
def_id: id,
136+
ty: expr.ty,
137+
}))),
124138

125-
ExprKind::Array { .. } |
126-
ExprKind::Tuple { .. } |
127-
ExprKind::Adt { .. } |
128-
ExprKind::Closure { .. } |
129-
ExprKind::Unary { .. } |
130-
ExprKind::Binary { .. } |
131-
ExprKind::LogicalOp { .. } |
132-
ExprKind::Box { .. } |
133-
ExprKind::Cast { .. } |
134-
ExprKind::Use { .. } |
135-
ExprKind::NeverToAny { .. } |
136-
ExprKind::ReifyFnPointer { .. } |
137-
ExprKind::ClosureFnPointer { .. } |
138-
ExprKind::UnsafeFnPointer { .. } |
139-
ExprKind::Unsize { .. } |
140-
ExprKind::Repeat { .. } |
141-
ExprKind::Borrow { .. } |
142-
ExprKind::If { .. } |
143-
ExprKind::Match { .. } |
144-
ExprKind::Loop { .. } |
145-
ExprKind::Block { .. } |
146-
ExprKind::Assign { .. } |
147-
ExprKind::AssignOp { .. } |
148-
ExprKind::Break { .. } |
149-
ExprKind::Continue { .. } |
150-
ExprKind::Return { .. } |
151-
ExprKind::Literal { .. } |
152-
ExprKind::InlineAsm { .. } |
153-
ExprKind::Yield { .. } |
154-
ExprKind::Call { .. } => {
139+
ExprKind::Array { .. }
140+
| ExprKind::Tuple { .. }
141+
| ExprKind::Adt { .. }
142+
| ExprKind::Closure { .. }
143+
| ExprKind::Unary { .. }
144+
| ExprKind::Binary { .. }
145+
| ExprKind::LogicalOp { .. }
146+
| ExprKind::Box { .. }
147+
| ExprKind::Cast { .. }
148+
| ExprKind::Use { .. }
149+
| ExprKind::NeverToAny { .. }
150+
| ExprKind::ReifyFnPointer { .. }
151+
| ExprKind::ClosureFnPointer { .. }
152+
| ExprKind::UnsafeFnPointer { .. }
153+
| ExprKind::Unsize { .. }
154+
| ExprKind::Repeat { .. }
155+
| ExprKind::Borrow { .. }
156+
| ExprKind::If { .. }
157+
| ExprKind::Match { .. }
158+
| ExprKind::Loop { .. }
159+
| ExprKind::Block { .. }
160+
| ExprKind::Assign { .. }
161+
| ExprKind::AssignOp { .. }
162+
| ExprKind::Break { .. }
163+
| ExprKind::Continue { .. }
164+
| ExprKind::Return { .. }
165+
| ExprKind::Literal { .. }
166+
| ExprKind::InlineAsm { .. }
167+
| ExprKind::Yield { .. }
168+
| ExprKind::Call { .. } => {
155169
// these are not places, so we need to make a temporary.
156170
debug_assert!(match Category::of(&expr.kind) {
157171
Some(Category::Place) => false,
158172
_ => true,
159173
});
160-
let temp = unpack!(
161-
block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
174+
let temp =
175+
unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability));
162176
block.and(Place::Local(temp))
163177
}
164178
}

0 commit comments

Comments
 (0)