Skip to content

Commit 9f6e900

Browse files
authored
Rollup merge of rust-lang#33951 - srinivasreddy:librust_pass_rustfmt, r=nikomatsakis
run rustfmt on librustc_passes folder
2 parents 126af08 + faa039f commit 9f6e900

File tree

6 files changed

+155
-162
lines changed

6 files changed

+155
-162
lines changed

src/librustc_passes/consts.rs

+71-80
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
// by borrowck::gather_loans
2626

2727
use rustc::dep_graph::DepNode;
28-
use rustc::ty::cast::{CastKind};
29-
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
28+
use rustc::ty::cast::CastKind;
29+
use rustc_const_eval::{ConstEvalErr, compare_lit_exprs, lookup_const_fn_by_id};
3030
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
31-
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
31+
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, Math, MiscCatchAll, UnimplementedConstVal};
3232
use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp, NonConstPath};
3333
use rustc_const_eval::ErrKind::UnresolvedPath;
3434
use rustc_const_eval::EvalHint::ExprTypeChecked;
@@ -70,12 +70,12 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
7070
tcx: TyCtxt<'a, 'tcx, 'tcx>,
7171
mode: Mode,
7272
qualif: ConstQualif,
73-
rvalue_borrows: NodeMap<hir::Mutability>
73+
rvalue_borrows: NodeMap<hir::Mutability>,
7474
}
7575

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

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

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

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

144148
let mode = match fk {
145-
FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => {
146-
Mode::ConstFn
147-
}
149+
FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => Mode::ConstFn,
148150
FnKind::Method(_, m, _, _) => {
149151
if m.constness == hir::Constness::Const {
150152
Mode::ConstFn
151153
} else {
152154
Mode::Var
153155
}
154156
}
155-
_ => Mode::Var
157+
_ => Mode::Var,
156158
};
157159

158160
let qualif = self.with_mode(mode, |this| {
@@ -174,11 +176,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
174176
}
175177

176178
/// Returns true if the call is to a const fn or method.
177-
fn handle_const_fn_call(&mut self,
178-
_expr: &hir::Expr,
179-
def_id: DefId,
180-
ret_ty: Ty<'gcx>)
181-
-> bool {
179+
fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
182180
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
183181
let qualif = self.fn_like(fn_like.kind(),
184182
fn_like.decl(),
@@ -293,17 +291,21 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
293291
Some(Ordering::Less) |
294292
Some(Ordering::Equal) => {}
295293
Some(Ordering::Greater) => {
296-
span_err!(self.tcx.sess, start.span, E0030,
297-
"lower range bound must be less than or equal to upper");
294+
span_err!(self.tcx.sess,
295+
start.span,
296+
E0030,
297+
"lower range bound must be less than or equal to upper");
298298
}
299299
None => {
300-
span_err!(self.tcx.sess, p.span, E0014,
300+
span_err!(self.tcx.sess,
301+
p.span,
302+
E0014,
301303
"paths in {}s may only refer to constants",
302304
self.msg());
303305
}
304306
}
305307
}
306-
_ => intravisit::walk_pat(self, p)
308+
_ => intravisit::walk_pat(self, p),
307309
}
308310
}
309311

@@ -313,13 +315,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
313315
match stmt.node {
314316
hir::StmtDecl(ref decl, _) => {
315317
match decl.node {
316-
hir::DeclLocal(_) => {},
318+
hir::DeclLocal(_) => {}
317319
// Item statements are allowed
318-
hir::DeclItem(_) => continue
320+
hir::DeclItem(_) => continue,
319321
}
320322
}
321-
hir::StmtExpr(_, _) => {},
322-
hir::StmtSemi(_, _) => {},
323+
hir::StmtExpr(_, _) => {}
324+
hir::StmtSemi(_, _) => {}
323325
}
324326
self.add_qualif(ConstQualif::NOT_CONST);
325327
}
@@ -352,7 +354,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
352354
// The count is checked elsewhere (typeck).
353355
let count = match node_ty.sty {
354356
ty::TyArray(_, n) => n,
355-
_ => bug!()
357+
_ => bug!(),
356358
};
357359
// [element; 0] is always zero-sized.
358360
if count == 0 {
@@ -377,7 +379,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
377379
}
378380
intravisit::walk_expr(self, ex);
379381
}
380-
_ => intravisit::walk_expr(self, ex)
382+
_ => intravisit::walk_expr(self, ex),
381383
}
382384

383385
// Handle borrows on (or inside the autorefs of) this expression.
@@ -417,19 +419,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
417419
if self.mode == Mode::Var && !self.qualif.intersects(ConstQualif::NOT_CONST) {
418420
match eval_const_expr_partial(self.tcx, ex, ExprTypeChecked, None) {
419421
Ok(_) => {}
420-
Err(ConstEvalErr { kind: UnimplementedConstVal(_), ..}) |
421-
Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
422-
Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
423-
Err(ConstEvalErr { kind: NonConstPath, ..}) |
424-
Err(ConstEvalErr { kind: UnresolvedPath, ..}) |
425-
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
426-
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
427-
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
428-
Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
422+
Err(ConstEvalErr { kind: UnimplementedConstVal(_), .. }) |
423+
Err(ConstEvalErr { kind: MiscCatchAll, .. }) |
424+
Err(ConstEvalErr { kind: MiscBinaryOp, .. }) |
425+
Err(ConstEvalErr { kind: NonConstPath, .. }) |
426+
Err(ConstEvalErr { kind: UnresolvedPath, .. }) |
427+
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), .. }) |
428+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), .. }) |
429+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), .. }) |
430+
Err(ConstEvalErr { kind: IndexOpFeatureGated, .. }) => {}
429431
Err(msg) => {
430-
self.tcx.sess.add_lint(CONST_ERR, ex.id,
431-
msg.span,
432-
msg.description().into_owned())
432+
self.tcx
433+
.sess
434+
.add_lint(CONST_ERR, ex.id, msg.span, msg.description().into_owned())
433435
}
434436
}
435437
}
@@ -446,8 +448,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
446448
/// every nested expression. If the expression is not part
447449
/// of a const/static item, it is qualified for promotion
448450
/// instead of producing errors.
449-
fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
450-
e: &hir::Expr, node_ty: Ty<'tcx>) {
451+
fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node_ty: Ty<'tcx>) {
451452
match node_ty.sty {
452453
ty::TyStruct(def, _) |
453454
ty::TyEnum(def, _) if def.has_dtor() => {
@@ -647,25 +648,23 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
647648
Some(&ty::adjustment::AdjustUnsafeFnPointer) |
648649
Some(&ty::adjustment::AdjustMutToConstPointer) => {}
649650

650-
Some(&ty::adjustment::AdjustDerefRef(
651-
ty::adjustment::AutoDerefRef { autoderefs, .. }
652-
)) => {
653-
if (0..autoderefs as u32).any(|autoderef| {
654-
v.tcx.is_overloaded_autoderef(e.id, autoderef)
655-
}) {
651+
Some(&ty::adjustment::AdjustDerefRef(ty::adjustment::AutoDerefRef { autoderefs, .. })) => {
652+
if (0..autoderefs as u32)
653+
.any(|autoderef| v.tcx.is_overloaded_autoderef(e.id, autoderef)) {
656654
v.add_qualif(ConstQualif::NOT_CONST);
657655
}
658656
}
659657
}
660658
}
661659

662660
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
663-
tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
664-
tcx: tcx,
665-
mode: Mode::Var,
666-
qualif: ConstQualif::NOT_CONST,
667-
rvalue_borrows: NodeMap()
668-
});
661+
tcx.visit_all_items_in_krate(DepNode::CheckConst,
662+
&mut CheckCrateVisitor {
663+
tcx: tcx,
664+
mode: Mode::Var,
665+
qualif: ConstQualif::NOT_CONST,
666+
rvalue_borrows: NodeMap(),
667+
});
669668
tcx.sess.abort_if_errors();
670669
}
671670

@@ -687,7 +686,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
687686

688687
Categorization::Rvalue(..) |
689688
Categorization::Upvar(..) |
690-
Categorization::Local(..) => break
689+
Categorization::Local(..) => break,
691690
}
692691
}
693692
}
@@ -697,8 +696,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
697696
cmt: mc::cmt<'tcx>,
698697
_loan_region: ty::Region,
699698
bk: ty::BorrowKind,
700-
loan_cause: euv::LoanCause)
701-
{
699+
loan_cause: euv::LoanCause) {
702700
// Kind of hacky, but we allow Unsafe coercions in constants.
703701
// These occur when we convert a &T or *T to a *U, as well as
704702
// when making a thin pointer (e.g., `*T`) into a fat pointer
@@ -707,7 +705,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
707705
euv::LoanCause::AutoUnsafe => {
708706
return;
709707
}
710-
_ => { }
708+
_ => {}
711709
}
712710

713711
let mut cur = &cmt;
@@ -744,27 +742,20 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
744742
}
745743

746744
Categorization::Upvar(..) |
747-
Categorization::Local(..) => break
745+
Categorization::Local(..) => break,
748746
}
749747
}
750748
}
751749

752-
fn decl_without_init(&mut self,
753-
_id: ast::NodeId,
754-
_span: Span) {}
750+
fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
755751
fn mutate(&mut self,
756752
_assignment_id: ast::NodeId,
757753
_assignment_span: Span,
758754
_assignee_cmt: mc::cmt,
759-
_mode: euv::MutateMode) {}
755+
_mode: euv::MutateMode) {
756+
}
760757

761-
fn matched_pat(&mut self,
762-
_: &hir::Pat,
763-
_: mc::cmt,
764-
_: euv::MatchMode) {}
758+
fn matched_pat(&mut self, _: &hir::Pat, _: mc::cmt, _: euv::MatchMode) {}
765759

766-
fn consume_pat(&mut self,
767-
_consume_pat: &hir::Pat,
768-
_cmt: mc::cmt,
769-
_mode: euv::ConsumeMode) {}
760+
fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: mc::cmt, _mode: euv::ConsumeMode) {}
770761
}

src/librustc_passes/lib.rs

+6-3
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

3841
pub mod diagnostics;
3942

src/librustc_passes/loops.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ use syntax::codemap::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
}

0 commit comments

Comments
 (0)