Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f78aa4d

Browse files
committedDec 7, 2016
Run rustfmt on librustc_mir/hair/cx
1 parent 692d7cf commit f78aa4d

File tree

4 files changed

+373
-319
lines changed

4 files changed

+373
-319
lines changed
 

‎src/librustc_mir/hair/cx/block.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,52 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
2626
extent: cx.tcx.region_maps.node_extent(self.id),
2727
span: self.span,
2828
stmts: stmts,
29-
expr: self.expr.to_ref()
29+
expr: self.expr.to_ref(),
3030
}
3131
}
3232
}
3333

3434
fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
3535
block_id: ast::NodeId,
3636
stmts: &'tcx [hir::Stmt])
37-
-> Vec<StmtRef<'tcx>>
38-
{
37+
-> Vec<StmtRef<'tcx>> {
3938
let mut result = vec![];
4039
for (index, stmt) in stmts.iter().enumerate() {
4140
match stmt.node {
42-
hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) =>
41+
hir::StmtExpr(ref expr, id) |
42+
hir::StmtSemi(ref expr, id) => {
4343
result.push(StmtRef::Mirror(Box::new(Stmt {
4444
span: stmt.span,
4545
kind: StmtKind::Expr {
4646
scope: cx.tcx.region_maps.node_extent(id),
47-
expr: expr.to_ref()
47+
expr: expr.to_ref(),
48+
},
49+
})))
50+
}
51+
hir::StmtDecl(ref decl, id) => {
52+
match decl.node {
53+
hir::DeclItem(..) => {
54+
// ignore for purposes of the MIR
4855
}
49-
}))),
50-
hir::StmtDecl(ref decl, id) => match decl.node {
51-
hir::DeclItem(..) => { /* ignore for purposes of the MIR */ }
52-
hir::DeclLocal(ref local) => {
53-
let remainder_extent = CodeExtentData::Remainder(BlockRemainder {
54-
block: block_id,
55-
first_statement_index: index as u32,
56-
});
57-
let remainder_extent =
58-
cx.tcx.region_maps.lookup_code_extent(remainder_extent);
56+
hir::DeclLocal(ref local) => {
57+
let remainder_extent = CodeExtentData::Remainder(BlockRemainder {
58+
block: block_id,
59+
first_statement_index: index as u32,
60+
});
61+
let remainder_extent =
62+
cx.tcx.region_maps.lookup_code_extent(remainder_extent);
5963

60-
let pattern = Pattern::from_hir(cx.tcx, &local.pat);
61-
result.push(StmtRef::Mirror(Box::new(Stmt {
62-
span: stmt.span,
63-
kind: StmtKind::Let {
64-
remainder_scope: remainder_extent,
65-
init_scope: cx.tcx.region_maps.node_extent(id),
66-
pattern: pattern,
67-
initializer: local.init.to_ref(),
68-
},
69-
})));
64+
let pattern = Pattern::from_hir(cx.tcx, &local.pat);
65+
result.push(StmtRef::Mirror(Box::new(Stmt {
66+
span: stmt.span,
67+
kind: StmtKind::Let {
68+
remainder_scope: remainder_extent,
69+
init_scope: cx.tcx.region_maps.node_extent(id),
70+
pattern: pattern,
71+
initializer: local.init.to_ref(),
72+
},
73+
})));
74+
}
7075
}
7176
}
7277
}

‎src/librustc_mir/hair/cx/expr.rs

Lines changed: 307 additions & 258 deletions
Large diffs are not rendered by default.

‎src/librustc_mir/hair/cx/mod.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*!
12-
* This module contains the code to convert from the wacky tcx data
13-
* structures into the hair. The `builder` is generally ignorant of
14-
* the tcx etc, and instead goes through the `Cx` for most of its
15-
* work.
16-
*/
11+
//! This module contains the code to convert from the wacky tcx data
12+
//! structures into the hair. The `builder` is generally ignorant of
13+
//! the tcx etc, and instead goes through the `Cx` for most of its
14+
//! work.
15+
//!
1716
1817
use hair::*;
1918
use rustc::mir::transform::MirSource;
@@ -32,27 +31,25 @@ use rustc::hir;
3231
use rustc_const_math::{ConstInt, ConstUsize};
3332

3433
#[derive(Copy, Clone)]
35-
pub struct Cx<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
34+
pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
3635
tcx: TyCtxt<'a, 'gcx, 'tcx>,
3736
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
3837
constness: hir::Constness,
3938

4039
/// True if this constant/function needs overflow checks.
41-
check_overflow: bool
40+
check_overflow: bool,
4241
}
4342

4443
impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
45-
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
46-
src: MirSource)
47-
-> Cx<'a, 'gcx, 'tcx> {
44+
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, src: MirSource) -> Cx<'a, 'gcx, 'tcx> {
4845
let constness = match src {
4946
MirSource::Const(_) |
5047
MirSource::Static(..) => hir::Constness::Const,
5148
MirSource::Fn(id) => {
5249
let fn_like = FnLikeNode::from_node(infcx.tcx.map.get(id));
5350
fn_like.map_or(hir::Constness::NotConst, |f| f.constness())
5451
}
55-
MirSource::Promoted(..) => bug!()
52+
MirSource::Promoted(..) => bug!(),
5653
};
5754

5855
let src_node_id = src.item_id();
@@ -70,13 +67,16 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
7067
// Some functions always have overflow checks enabled,
7168
// however, they may not get codegen'd, depending on
7269
// the settings for the crate they are translated in.
73-
let mut check_overflow = attrs.iter().any(|item| {
74-
item.check_name("rustc_inherit_overflow_checks")
75-
});
70+
let mut check_overflow = attrs.iter()
71+
.any(|item| item.check_name("rustc_inherit_overflow_checks"));
7672

7773
// Respect -Z force-overflow-checks=on and -C debug-assertions.
78-
check_overflow |= infcx.tcx.sess.opts.debugging_opts.force_overflow_checks
79-
.unwrap_or(infcx.tcx.sess.opts.debug_assertions);
74+
check_overflow |= infcx.tcx
75+
.sess
76+
.opts
77+
.debugging_opts
78+
.force_overflow_checks
79+
.unwrap_or(infcx.tcx.sess.opts.debug_assertions);
8080

8181
// Constants and const fn's always need overflow checks.
8282
check_overflow |= constness == hir::Constness::Const;
@@ -85,7 +85,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
8585
tcx: infcx.tcx,
8686
infcx: infcx,
8787
constness: constness,
88-
check_overflow: check_overflow
88+
check_overflow: check_overflow,
8989
}
9090
}
9191
}
@@ -102,7 +102,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
102102

103103
pub fn usize_literal(&mut self, value: u64) -> Literal<'tcx> {
104104
match ConstUsize::new(value, self.tcx.sess.target.uint_type) {
105-
Ok(val) => Literal::Value { value: ConstVal::Integral(ConstInt::Usize(val))},
105+
Ok(val) => Literal::Value { value: ConstVal::Integral(ConstInt::Usize(val)) },
106106
Err(_) => bug!("usize literal out of range for target"),
107107
}
108108
}
@@ -128,9 +128,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
128128
}
129129

130130
pub fn const_eval_literal(&mut self, e: &hir::Expr) -> Literal<'tcx> {
131-
Literal::Value {
132-
value: const_eval::eval_const_expr(self.tcx.global_tcx(), e)
133-
}
131+
Literal::Value { value: const_eval::eval_const_expr(self.tcx.global_tcx(), e) }
134132
}
135133

136134
pub fn trait_method(&mut self,
@@ -145,10 +143,11 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
145143
if item.kind == ty::AssociatedKind::Method && item.name == method_name {
146144
let method_ty = self.tcx.item_type(item.def_id);
147145
let method_ty = method_ty.subst(self.tcx, substs);
148-
return (method_ty, Literal::Item {
149-
def_id: item.def_id,
150-
substs: substs,
151-
});
146+
return (method_ty,
147+
Literal::Item {
148+
def_id: item.def_id,
149+
substs: substs,
150+
});
152151
}
153152
}
154153

@@ -168,7 +167,8 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
168167
pub fn needs_drop(&mut self, ty: Ty<'tcx>) -> bool {
169168
let ty = self.tcx.lift_to_global(&ty).unwrap_or_else(|| {
170169
bug!("MIR: Cx::needs_drop({}) got \
171-
type with inference types/regions", ty);
170+
type with inference types/regions",
171+
ty);
172172
});
173173
self.tcx.type_needs_drop_given_env(ty, &self.infcx.parameter_environment)
174174
}

‎src/librustc_mir/hair/cx/to_ref.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ pub trait ToRef {
1818
fn to_ref(self) -> Self::Output;
1919
}
2020

21-
impl<'a,'tcx:'a> ToRef for &'tcx hir::Expr {
21+
impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr {
2222
type Output = ExprRef<'tcx>;
2323

2424
fn to_ref(self) -> ExprRef<'tcx> {
2525
ExprRef::Hair(self)
2626
}
2727
}
2828

29-
impl<'a,'tcx:'a> ToRef for &'tcx P<hir::Expr> {
29+
impl<'a, 'tcx: 'a> ToRef for &'tcx P<hir::Expr> {
3030
type Output = ExprRef<'tcx>;
3131

3232
fn to_ref(self) -> ExprRef<'tcx> {
3333
ExprRef::Hair(&**self)
3434
}
3535
}
3636

37-
impl<'a,'tcx:'a> ToRef for Expr<'tcx> {
37+
impl<'a, 'tcx: 'a> ToRef for Expr<'tcx> {
3838
type Output = ExprRef<'tcx>;
3939

4040
fn to_ref(self) -> ExprRef<'tcx> {
4141
ExprRef::Mirror(Box::new(self))
4242
}
4343
}
4444

45-
impl<'a,'tcx:'a,T,U> ToRef for &'tcx Option<T>
46-
where &'tcx T: ToRef<Output=U>
45+
impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Option<T>
46+
where &'tcx T: ToRef<Output = U>
4747
{
4848
type Output = Option<U>;
4949

@@ -52,8 +52,8 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Option<T>
5252
}
5353
}
5454

55-
impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
56-
where &'tcx T: ToRef<Output=U>
55+
impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Vec<T>
56+
where &'tcx T: ToRef<Output = U>
5757
{
5858
type Output = Vec<U>;
5959

@@ -62,8 +62,8 @@ impl<'a,'tcx:'a,T,U> ToRef for &'tcx Vec<T>
6262
}
6363
}
6464

65-
impl<'a,'tcx:'a,T,U> ToRef for &'tcx P<[T]>
66-
where &'tcx T: ToRef<Output=U>
65+
impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx P<[T]>
66+
where &'tcx T: ToRef<Output = U>
6767
{
6868
type Output = Vec<U>;
6969

0 commit comments

Comments
 (0)
Please sign in to comment.