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 1fd8b88

Browse files
authoredAug 6, 2016
Auto merge of #33951 - srinivasreddy:librust_pass_rustfmt, r=nikomatsakis
run rustfmt on librustc_passes folder
2 parents ecdd51b + a6c9404 commit 1fd8b88

File tree

6 files changed

+200
-173
lines changed

6 files changed

+200
-173
lines changed
 

‎src/librustc_passes/ast_validation.rs

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ impl<'a> AstValidator<'a> {
3838
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
3939
}
4040
if label.name.as_str() == "'_" {
41-
self.session.add_lint(
42-
lint::builtin::LIFETIME_UNDERSCORE, id, span,
43-
format!("invalid label name `{}`", label.name)
44-
);
41+
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
42+
id,
43+
span,
44+
format!("invalid label name `{}`", label.name));
4545
}
4646
}
4747

4848
fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) {
4949
if vis != &Visibility::Inherited {
50-
let mut err = struct_span_err!(self.session, span, E0449,
50+
let mut err = struct_span_err!(self.session,
51+
span,
52+
E0449,
5153
"unnecessary visibility qualifier");
5254
if let Some(note) = note {
5355
err.span_note(span, note);
@@ -71,20 +73,23 @@ impl<'a> AstValidator<'a> {
7173
impl<'a> Visitor for AstValidator<'a> {
7274
fn visit_lifetime(&mut self, lt: &Lifetime) {
7375
if lt.name.as_str() == "'_" {
74-
self.session.add_lint(
75-
lint::builtin::LIFETIME_UNDERSCORE, lt.id, lt.span,
76-
format!("invalid lifetime name `{}`", lt.name)
77-
);
76+
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
77+
lt.id,
78+
lt.span,
79+
format!("invalid lifetime name `{}`", lt.name));
7880
}
7981

8082
visit::walk_lifetime(self, lt)
8183
}
8284

8385
fn visit_expr(&mut self, expr: &Expr) {
8486
match expr.node {
85-
ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) |
86-
ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) |
87-
ExprKind::Break(Some(ident)) | ExprKind::Continue(Some(ident)) => {
87+
ExprKind::While(_, _, Some(ident)) |
88+
ExprKind::Loop(_, Some(ident)) |
89+
ExprKind::WhileLet(_, _, _, Some(ident)) |
90+
ExprKind::ForLoop(_, _, _, Some(ident)) |
91+
ExprKind::Break(Some(ident)) |
92+
ExprKind::Continue(Some(ident)) => {
8893
self.check_label(ident.node, ident.span, expr.id);
8994
}
9095
_ => {}
@@ -97,10 +102,13 @@ impl<'a> Visitor for AstValidator<'a> {
97102
match ty.node {
98103
TyKind::BareFn(ref bfty) => {
99104
self.check_decl_no_pat(&bfty.decl, |span, _| {
100-
let mut err = struct_span_err!(self.session, span, E0561,
101-
"patterns aren't allowed in function pointer types");
102-
err.span_note(span, "this is a recent error, see \
103-
issue #35203 for more details");
105+
let mut err = struct_span_err!(self.session,
106+
span,
107+
E0561,
108+
"patterns aren't allowed in function pointer \
109+
types");
110+
err.span_note(span,
111+
"this is a recent error, see issue #35203 for more details");
104112
err.emit();
105113
});
106114
}
@@ -114,10 +122,10 @@ impl<'a> Visitor for AstValidator<'a> {
114122
if path.global && path.segments.len() > 0 {
115123
let ident = path.segments[0].identifier;
116124
if token::Ident(ident).is_path_segment_keyword() {
117-
self.session.add_lint(
118-
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
119-
format!("global paths cannot start with `{}`", ident)
120-
);
125+
self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
126+
id,
127+
path.span,
128+
format!("global paths cannot start with `{}`", ident));
121129
}
122130
}
123131

@@ -129,8 +137,8 @@ impl<'a> Visitor for AstValidator<'a> {
129137
ItemKind::Use(ref view_path) => {
130138
let path = view_path.node.path();
131139
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
132-
self.err_handler().span_err(path.span, "type or lifetime parameters \
133-
in import path");
140+
self.err_handler()
141+
.span_err(path.span, "type or lifetime parameters in import path");
134142
}
135143
}
136144
ItemKind::Impl(_, _, _, Some(..), _, ref impl_items) => {
@@ -140,15 +148,18 @@ impl<'a> Visitor for AstValidator<'a> {
140148
}
141149
}
142150
ItemKind::Impl(_, _, _, None, _, _) => {
143-
self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
144-
impl items instead"));
151+
self.invalid_visibility(&item.vis,
152+
item.span,
153+
Some("place qualifiers on individual impl items instead"));
145154
}
146155
ItemKind::DefaultImpl(..) => {
147156
self.invalid_visibility(&item.vis, item.span, None);
148157
}
149158
ItemKind::ForeignMod(..) => {
150-
self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
151-
foreign items instead"));
159+
self.invalid_visibility(&item.vis,
160+
item.span,
161+
Some("place qualifiers on individual foreign items \
162+
instead"));
152163
}
153164
ItemKind::Enum(ref def, _) => {
154165
for variant in &def.variants {
@@ -167,11 +178,14 @@ impl<'a> Visitor for AstValidator<'a> {
167178
match fi.node {
168179
ForeignItemKind::Fn(ref decl, _) => {
169180
self.check_decl_no_pat(decl, |span, is_recent| {
170-
let mut err = struct_span_err!(self.session, span, E0130,
171-
"patterns aren't allowed in foreign function declarations");
181+
let mut err = struct_span_err!(self.session,
182+
span,
183+
E0130,
184+
"patterns aren't allowed in foreign function \
185+
declarations");
172186
if is_recent {
173-
err.span_note(span, "this is a recent error, see \
174-
issue #35203 for more details");
187+
err.span_note(span,
188+
"this is a recent error, see issue #35203 for more details");
175189
}
176190
err.emit();
177191
});
@@ -182,16 +196,21 @@ impl<'a> Visitor for AstValidator<'a> {
182196
visit::walk_foreign_item(self, fi)
183197
}
184198

185-
fn visit_variant_data(&mut self, vdata: &VariantData, _: Ident,
186-
_: &Generics, _: NodeId, span: Span) {
199+
fn visit_variant_data(&mut self,
200+
vdata: &VariantData,
201+
_: Ident,
202+
_: &Generics,
203+
_: NodeId,
204+
span: Span) {
187205
if vdata.fields().is_empty() {
188206
if vdata.is_tuple() {
189-
self.err_handler().struct_span_err(span, "empty tuple structs and enum variants \
190-
are not allowed, use unit structs and \
191-
enum variants instead")
192-
.span_help(span, "remove trailing `()` to make a unit \
193-
struct or unit enum variant")
194-
.emit();
207+
self.err_handler()
208+
.struct_span_err(span,
209+
"empty tuple structs and enum variants are not allowed, use \
210+
unit structs and enum variants instead")
211+
.span_help(span,
212+
"remove trailing `()` to make a unit struct or unit enum variant")
213+
.emit();
195214
}
196215
}
197216

@@ -200,10 +219,10 @@ impl<'a> Visitor for AstValidator<'a> {
200219

201220
fn visit_vis(&mut self, vis: &Visibility) {
202221
match *vis {
203-
Visibility::Restricted{ref path, ..} => {
222+
Visibility::Restricted { ref path, .. } => {
204223
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
205-
self.err_handler().span_err(path.span, "type or lifetime parameters \
206-
in visibility path");
224+
self.err_handler()
225+
.span_err(path.span, "type or lifetime parameters in visibility path");
207226
}
208227
}
209228
_ => {}

‎src/librustc_passes/consts.rs

Lines changed: 70 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// by borrowck::gather_loans
2626

2727
use rustc::dep_graph::DepNode;
28-
use rustc::ty::cast::{CastKind};
28+
use rustc::ty::cast::CastKind;
2929
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
3030
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
3131
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
@@ -71,12 +71,12 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
7171
tcx: TyCtxt<'a, 'tcx, 'tcx>,
7272
mode: Mode,
7373
qualif: ConstQualif,
74-
rvalue_borrows: NodeMap<hir::Mutability>
74+
rvalue_borrows: NodeMap<hir::Mutability>,
7575
}
7676

7777
impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
78-
fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
79-
F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R,
78+
fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R
79+
where F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R
8080
{
8181
let (old_mode, old_qualif) = (self.mode, self.qualif);
8282
self.mode = mode;
@@ -87,17 +87,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
8787
r
8888
}
8989

90-
fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R where
91-
F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R,
90+
fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R
91+
where F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R
9292
{
9393
let param_env = match item_id {
9494
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
95-
None => self.tcx.empty_parameter_environment()
95+
None => self.tcx.empty_parameter_environment(),
9696
};
9797

98-
self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal).enter(|infcx| {
99-
f(&mut euv::ExprUseVisitor::new(self, &infcx))
100-
})
98+
self.tcx
99+
.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal)
100+
.enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx)))
101101
}
102102

103103
fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
@@ -111,13 +111,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
111111
}
112112
if let Err(err) = eval_const_expr_partial(self.tcx, expr, ExprTypeChecked, None) {
113113
match err.kind {
114-
UnimplementedConstVal(_) => {},
115-
IndexOpFeatureGated => {},
116-
ErroneousReferencedConstant(_) => {},
117-
_ => self.tcx.sess.add_lint(CONST_ERR, expr.id, expr.span,
118-
format!("constant evaluation error: {}. This will \
119-
become a HARD ERROR in the future",
120-
err.description().into_oneline())),
114+
UnimplementedConstVal(_) => {}
115+
IndexOpFeatureGated => {}
116+
ErroneousReferencedConstant(_) => {}
117+
_ => {
118+
self.tcx.sess.add_lint(CONST_ERR,
119+
expr.id,
120+
expr.span,
121+
format!("constant evaluation error: {}. This will \
122+
become a HARD ERROR in the future",
123+
err.description().into_oneline()))
124+
}
121125
}
122126
}
123127
self.with_mode(mode, |this| {
@@ -143,17 +147,15 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
143147
}
144148

145149
let mode = match fk {
146-
FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => {
147-
Mode::ConstFn
148-
}
150+
FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => Mode::ConstFn,
149151
FnKind::Method(_, m, _, _) => {
150152
if m.constness == hir::Constness::Const {
151153
Mode::ConstFn
152154
} else {
153155
Mode::Var
154156
}
155157
}
156-
_ => Mode::Var
158+
_ => Mode::Var,
157159
};
158160

159161
let qualif = self.with_mode(mode, |this| {
@@ -175,11 +177,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
175177
}
176178

177179
/// Returns true if the call is to a const fn or method.
178-
fn handle_const_fn_call(&mut self,
179-
_expr: &hir::Expr,
180-
def_id: DefId,
181-
ret_ty: Ty<'gcx>)
182-
-> bool {
180+
fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
183181
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
184182
let qualif = self.fn_like(fn_like.kind(),
185183
fn_like.decl(),
@@ -285,13 +283,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
285283
Ok(Ordering::Less) |
286284
Ok(Ordering::Equal) => {}
287285
Ok(Ordering::Greater) => {
288-
span_err!(self.tcx.sess, start.span, E0030,
289-
"lower range bound must be less than or equal to upper");
286+
span_err!(self.tcx.sess,
287+
start.span,
288+
E0030,
289+
"lower range bound must be less than or equal to upper");
290290
}
291291
Err(ErrorReported) => {}
292292
}
293293
}
294-
_ => intravisit::walk_pat(self, p)
294+
_ => intravisit::walk_pat(self, p),
295295
}
296296
}
297297

@@ -301,13 +301,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
301301
match stmt.node {
302302
hir::StmtDecl(ref decl, _) => {
303303
match decl.node {
304-
hir::DeclLocal(_) => {},
304+
hir::DeclLocal(_) => {}
305305
// Item statements are allowed
306-
hir::DeclItem(_) => continue
306+
hir::DeclItem(_) => continue,
307307
}
308308
}
309-
hir::StmtExpr(_, _) => {},
310-
hir::StmtSemi(_, _) => {},
309+
hir::StmtExpr(_, _) => {}
310+
hir::StmtSemi(_, _) => {}
311311
}
312312
self.add_qualif(ConstQualif::NOT_CONST);
313313
}
@@ -340,7 +340,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
340340
// The count is checked elsewhere (typeck).
341341
let count = match node_ty.sty {
342342
ty::TyArray(_, n) => n,
343-
_ => bug!()
343+
_ => bug!(),
344344
};
345345
// [element; 0] is always zero-sized.
346346
if count == 0 {
@@ -354,7 +354,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
354354
for pat in arms.iter().flat_map(|arm| &arm.pats) {
355355
let pat_borrow = self.rvalue_borrows.remove(&pat.id);
356356
match (borrow, pat_borrow) {
357-
(None, _) | (_, Some(hir::MutMutable)) => {
357+
(None, _) |
358+
(_, Some(hir::MutMutable)) => {
358359
borrow = pat_borrow;
359360
}
360361
_ => {}
@@ -365,7 +366,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
365366
}
366367
intravisit::walk_expr(self, ex);
367368
}
368-
_ => intravisit::walk_expr(self, ex)
369+
_ => intravisit::walk_expr(self, ex),
369370
}
370371

371372
// Handle borrows on (or inside the autorefs of) this expression.
@@ -405,17 +406,18 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
405406
if self.mode == Mode::Var && !self.qualif.intersects(ConstQualif::NOT_CONST) {
406407
match eval_const_expr_partial(self.tcx, ex, ExprTypeChecked, None) {
407408
Ok(_) => {}
408-
Err(ConstEvalErr { kind: UnimplementedConstVal(_), ..}) |
409-
Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
410-
Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
411-
Err(ConstEvalErr { kind: NonConstPath, ..}) |
412-
Err(ConstEvalErr { kind: UnresolvedPath, ..}) |
413-
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
414-
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
415-
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
416-
Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
409+
Err(ConstEvalErr { kind: UnimplementedConstVal(_), .. }) |
410+
Err(ConstEvalErr { kind: MiscCatchAll, .. }) |
411+
Err(ConstEvalErr { kind: MiscBinaryOp, .. }) |
412+
Err(ConstEvalErr { kind: NonConstPath, .. }) |
413+
Err(ConstEvalErr { kind: UnresolvedPath, .. }) |
414+
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), .. }) |
415+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), .. }) |
416+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), .. }) |
417+
Err(ConstEvalErr { kind: IndexOpFeatureGated, .. }) => {}
417418
Err(msg) => {
418-
self.tcx.sess.add_lint(CONST_ERR, ex.id,
419+
self.tcx.sess.add_lint(CONST_ERR,
420+
ex.id,
419421
msg.span,
420422
msg.description().into_oneline().into_owned())
421423
}
@@ -434,8 +436,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
434436
/// every nested expression. If the expression is not part
435437
/// of a const/static item, it is qualified for promotion
436438
/// instead of producing errors.
437-
fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
438-
e: &hir::Expr, node_ty: Ty<'tcx>) {
439+
fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node_ty: Ty<'tcx>) {
439440
match node_ty.sty {
440441
ty::TyStruct(def, _) |
441442
ty::TyEnum(def, _) if def.has_dtor() => {
@@ -635,25 +636,23 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
635636
Some(&ty::adjustment::AdjustUnsafeFnPointer) |
636637
Some(&ty::adjustment::AdjustMutToConstPointer) => {}
637638

638-
Some(&ty::adjustment::AdjustDerefRef(
639-
ty::adjustment::AutoDerefRef { autoderefs, .. }
640-
)) => {
641-
if (0..autoderefs as u32).any(|autoderef| {
642-
v.tcx.is_overloaded_autoderef(e.id, autoderef)
643-
}) {
639+
Some(&ty::adjustment::AdjustDerefRef(ty::adjustment::AutoDerefRef { autoderefs, .. })) => {
640+
if (0..autoderefs as u32)
641+
.any(|autoderef| v.tcx.is_overloaded_autoderef(e.id, autoderef)) {
644642
v.add_qualif(ConstQualif::NOT_CONST);
645643
}
646644
}
647645
}
648646
}
649647

650648
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
651-
tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
652-
tcx: tcx,
653-
mode: Mode::Var,
654-
qualif: ConstQualif::NOT_CONST,
655-
rvalue_borrows: NodeMap()
656-
});
649+
tcx.visit_all_items_in_krate(DepNode::CheckConst,
650+
&mut CheckCrateVisitor {
651+
tcx: tcx,
652+
mode: Mode::Var,
653+
qualif: ConstQualif::NOT_CONST,
654+
rvalue_borrows: NodeMap(),
655+
});
657656
tcx.sess.abort_if_errors();
658657
}
659658

@@ -675,7 +674,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
675674

676675
Categorization::Rvalue(..) |
677676
Categorization::Upvar(..) |
678-
Categorization::Local(..) => break
677+
Categorization::Local(..) => break,
679678
}
680679
}
681680
}
@@ -685,8 +684,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
685684
cmt: mc::cmt<'tcx>,
686685
_loan_region: ty::Region,
687686
bk: ty::BorrowKind,
688-
loan_cause: euv::LoanCause)
689-
{
687+
loan_cause: euv::LoanCause) {
690688
// Kind of hacky, but we allow Unsafe coercions in constants.
691689
// These occur when we convert a &T or *T to a *U, as well as
692690
// when making a thin pointer (e.g., `*T`) into a fat pointer
@@ -695,7 +693,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
695693
euv::LoanCause::AutoUnsafe => {
696694
return;
697695
}
698-
_ => { }
696+
_ => {}
699697
}
700698

701699
let mut cur = &cmt;
@@ -715,7 +713,8 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
715713
// type of the expression. `&mut [1]` has exactly the
716714
// same representation as &mut 1.
717715
match cmt.ty.sty {
718-
ty::TyArray(_, _) | ty::TySlice(_) => break,
716+
ty::TyArray(_, _) |
717+
ty::TySlice(_) => break,
719718
_ => {}
720719
}
721720
}
@@ -732,27 +731,20 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
732731
}
733732

734733
Categorization::Upvar(..) |
735-
Categorization::Local(..) => break
734+
Categorization::Local(..) => break,
736735
}
737736
}
738737
}
739738

740-
fn decl_without_init(&mut self,
741-
_id: ast::NodeId,
742-
_span: Span) {}
739+
fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
743740
fn mutate(&mut self,
744741
_assignment_id: ast::NodeId,
745742
_assignment_span: Span,
746743
_assignee_cmt: mc::cmt,
747-
_mode: euv::MutateMode) {}
744+
_mode: euv::MutateMode) {
745+
}
748746

749-
fn matched_pat(&mut self,
750-
_: &hir::Pat,
751-
_: mc::cmt,
752-
_: euv::MatchMode) {}
747+
fn matched_pat(&mut self, _: &hir::Pat, _: mc::cmt, _: euv::MatchMode) {}
753748

754-
fn consume_pat(&mut self,
755-
_consume_pat: &hir::Pat,
756-
_cmt: mc::cmt,
757-
_mode: euv::ConsumeMode) {}
749+
fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: mc::cmt, _mode: euv::ConsumeMode) {}
758750
}

‎src/librustc_passes/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@
2828
#![feature(rustc_private)]
2929

3030
extern crate core;
31-
#[macro_use] extern crate rustc;
31+
#[macro_use]
32+
extern crate rustc;
3233
extern crate rustc_const_eval;
3334
extern crate rustc_const_math;
3435

35-
#[macro_use] extern crate log;
36-
#[macro_use] extern crate syntax;
36+
#[macro_use]
37+
extern crate log;
38+
#[macro_use]
39+
extern crate syntax;
3740
extern crate syntax_pos;
3841
extern crate rustc_errors as errors;
3942

‎src/librustc_passes/loops.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ use syntax_pos::Span;
1919

2020
#[derive(Clone, Copy, PartialEq)]
2121
enum Context {
22-
Normal, Loop, Closure
22+
Normal,
23+
Loop,
24+
Closure,
2325
}
2426

2527
#[derive(Copy, Clone)]
2628
struct CheckLoopVisitor<'a> {
2729
sess: &'a Session,
28-
cx: Context
30+
cx: Context,
2931
}
3032

3133
pub fn check_crate(sess: &Session, map: &Map) {
3234
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
3335
let krate = map.krate();
34-
krate.visit_all_items(&mut CheckLoopVisitor { sess: sess, cx: Normal });
36+
krate.visit_all_items(&mut CheckLoopVisitor {
37+
sess: sess,
38+
cx: Normal,
39+
});
3540
}
3641

3742
impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
@@ -53,14 +58,14 @@ impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
5358
}
5459
hir::ExprBreak(_) => self.require_loop("break", e.span),
5560
hir::ExprAgain(_) => self.require_loop("continue", e.span),
56-
_ => intravisit::walk_expr(self, e)
61+
_ => intravisit::walk_expr(self, e),
5762
}
5863
}
5964
}
6065

6166
impl<'a> CheckLoopVisitor<'a> {
62-
fn with_context<F>(&mut self, cx: Context, f: F) where
63-
F: FnOnce(&mut CheckLoopVisitor<'a>),
67+
fn with_context<F>(&mut self, cx: Context, f: F)
68+
where F: FnOnce(&mut CheckLoopVisitor<'a>)
6469
{
6570
let old_cx = self.cx;
6671
self.cx = cx;
@@ -72,12 +77,10 @@ impl<'a> CheckLoopVisitor<'a> {
7277
match self.cx {
7378
Loop => {}
7479
Closure => {
75-
span_err!(self.sess, span, E0267,
76-
"`{}` inside of a closure", name);
80+
span_err!(self.sess, span, E0267, "`{}` inside of a closure", name);
7781
}
7882
Normal => {
79-
span_err!(self.sess, span, E0268,
80-
"`{}` outside of loop", name);
83+
span_err!(self.sess, span, E0268, "`{}` outside of loop", name);
8184
}
8285
}
8386
}

‎src/librustc_passes/no_asm.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ use syntax::visit::Visitor;
1919
use syntax::visit;
2020

2121
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
22-
if sess.target.target.options.allow_asm { return; }
22+
if sess.target.target.options.allow_asm {
23+
return;
24+
}
2325

24-
visit::walk_crate(&mut CheckNoAsm { sess: sess, }, krate);
26+
visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate);
2527
}
2628

2729
#[derive(Copy, Clone)]
@@ -32,9 +34,13 @@ struct CheckNoAsm<'a> {
3234
impl<'a> Visitor for CheckNoAsm<'a> {
3335
fn visit_expr(&mut self, e: &ast::Expr) {
3436
match e.node {
35-
ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
36-
"asm! is unsupported on this target"),
37-
_ => {},
37+
ast::ExprKind::InlineAsm(_) => {
38+
span_err!(self.sess,
39+
e.span,
40+
E0472,
41+
"asm! is unsupported on this target")
42+
}
43+
_ => {}
3844
}
3945
visit::walk_expr(self, e)
4046
}

‎src/librustc_passes/static_recursion.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
use rustc::dep_graph::DepNode;
1515
use rustc::hir::map as ast_map;
16-
use rustc::session::{Session, CompileResult};
16+
use rustc::session::{CompileResult, Session};
1717
use rustc::hir::def::{Def, DefMap};
1818
use rustc::util::nodemap::NodeMap;
1919

20-
use syntax::{ast};
20+
use syntax::ast;
2121
use syntax::feature_gate::{GateIssue, emit_feature_err};
2222
use syntax_pos::Span;
2323
use rustc::hir::intravisit::{self, Visitor};
@@ -41,18 +41,17 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
4141
match it.node {
4242
hir::ItemStatic(..) |
4343
hir::ItemConst(..) => {
44-
let mut recursion_visitor =
45-
CheckItemRecursionVisitor::new(self, &it.span);
44+
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span);
4645
recursion_visitor.visit_item(it);
47-
},
46+
}
4847
hir::ItemEnum(ref enum_def, ref generics) => {
4948
// We could process the whole enum, but handling the variants
5049
// with discriminant expressions one by one gives more specific,
5150
// less redundant output.
5251
for variant in &enum_def.variants {
5352
if let Some(_) = variant.node.disr_expr {
54-
let mut recursion_visitor =
55-
CheckItemRecursionVisitor::new(self, &variant.span);
53+
let mut recursion_visitor = CheckItemRecursionVisitor::new(self,
54+
&variant.span);
5655
recursion_visitor.populate_enum_discriminants(enum_def);
5756
recursion_visitor.visit_variant(variant, generics, it.id);
5857
}
@@ -67,8 +66,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
6766
match ti.node {
6867
hir::ConstTraitItem(_, ref default) => {
6968
if let Some(_) = *default {
70-
let mut recursion_visitor =
71-
CheckItemRecursionVisitor::new(self, &ti.span);
69+
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ti.span);
7270
recursion_visitor.visit_trait_item(ti);
7371
}
7472
}
@@ -80,8 +78,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
8078
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
8179
match ii.node {
8280
hir::ImplItemKind::Const(..) => {
83-
let mut recursion_visitor =
84-
CheckItemRecursionVisitor::new(self, &ii.span);
81+
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
8582
recursion_visitor.visit_impl_item(ii);
8683
}
8784
_ => {}
@@ -117,7 +114,8 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
117114
}
118115

119116
impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
120-
fn new(v: &'a CheckCrateVisitor<'a, 'ast>, span: &'a Span)
117+
fn new(v: &'a CheckCrateVisitor<'a, 'ast>,
118+
span: &'a Span)
121119
-> CheckItemRecursionVisitor<'a, 'ast> {
122120
CheckItemRecursionVisitor {
123121
root_span: span,
@@ -129,7 +127,8 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
129127
}
130128
}
131129
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
132-
where F: Fn(&mut Self) {
130+
where F: Fn(&mut Self)
131+
{
133132
if self.idstack.iter().any(|&x| x == id) {
134133
let any_static = self.idstack.iter().any(|&x| {
135134
if let ast_map::NodeItem(item) = self.ast_map.get(x) {
@@ -146,7 +145,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
146145
if !self.sess.features.borrow().static_recursion {
147146
emit_feature_err(&self.sess.parse_sess.span_diagnostic,
148147
"static_recursion",
149-
*self.root_span, GateIssue::Language, "recursive static");
148+
*self.root_span,
149+
GateIssue::Language,
150+
"recursive static");
150151
}
151152
} else {
152153
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
@@ -170,7 +171,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
170171
// has no variants.
171172
let mut discriminant_map = self.discriminant_map.borrow_mut();
172173
match enum_definition.variants.first() {
173-
None => { return; }
174+
None => {
175+
return;
176+
}
174177
Some(variant) if discriminant_map.contains_key(&variant.node.data.id()) => {
175178
return;
176179
}
@@ -203,14 +206,19 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
203206
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
204207
}
205208

206-
fn visit_enum_def(&mut self, enum_definition: &'ast hir::EnumDef,
207-
generics: &'ast hir::Generics, item_id: ast::NodeId, _: Span) {
209+
fn visit_enum_def(&mut self,
210+
enum_definition: &'ast hir::EnumDef,
211+
generics: &'ast hir::Generics,
212+
item_id: ast::NodeId,
213+
_: Span) {
208214
self.populate_enum_discriminants(enum_definition);
209215
intravisit::walk_enum_def(self, enum_definition, generics, item_id);
210216
}
211217

212-
fn visit_variant(&mut self, variant: &'ast hir::Variant,
213-
_: &'ast hir::Generics, _: ast::NodeId) {
218+
fn visit_variant(&mut self,
219+
variant: &'ast hir::Variant,
220+
_: &'ast hir::Generics,
221+
_: ast::NodeId) {
214222
let variant_id = variant.node.data.id();
215223
let maybe_expr;
216224
if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
@@ -246,18 +254,14 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
246254
Some(Def::Const(def_id)) => {
247255
if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
248256
match self.ast_map.get(node_id) {
249-
ast_map::NodeItem(item) =>
250-
self.visit_item(item),
251-
ast_map::NodeTraitItem(item) =>
252-
self.visit_trait_item(item),
253-
ast_map::NodeImplItem(item) =>
254-
self.visit_impl_item(item),
255-
ast_map::NodeForeignItem(_) => {},
257+
ast_map::NodeItem(item) => self.visit_item(item),
258+
ast_map::NodeTraitItem(item) => self.visit_trait_item(item),
259+
ast_map::NodeImplItem(item) => self.visit_impl_item(item),
260+
ast_map::NodeForeignItem(_) => {}
256261
_ => {
257-
span_bug!(
258-
e.span,
259-
"expected item, found {}",
260-
self.ast_map.node_to_string(node_id));
262+
span_bug!(e.span,
263+
"expected item, found {}",
264+
self.ast_map.node_to_string(node_id));
261265
}
262266
}
263267
}
@@ -268,9 +272,9 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
268272
// might be (if any).
269273
Some(Def::Variant(enum_id, variant_id)) => {
270274
if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
271-
if let hir::ItemEnum(ref enum_def, ref generics) =
272-
self.ast_map.expect_item(enum_node_id).node
273-
{
275+
if let hir::ItemEnum(ref enum_def, ref generics) = self.ast_map
276+
.expect_item(enum_node_id)
277+
.node {
274278
self.populate_enum_discriminants(enum_def);
275279
let enum_id = self.ast_map.as_local_node_id(enum_id).unwrap();
276280
let variant_id = self.ast_map.as_local_node_id(variant_id).unwrap();
@@ -283,10 +287,10 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
283287
}
284288
}
285289
}
286-
_ => ()
290+
_ => (),
287291
}
288-
},
289-
_ => ()
292+
}
293+
_ => (),
290294
}
291295
intravisit::walk_expr(self, e);
292296
}

0 commit comments

Comments
 (0)
Please sign in to comment.