]> git.lizzy.rs Git - rust.git/commitdiff
run rustfmt on librustc_passes folder
authorSrinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>
Thu, 21 Jul 2016 01:31:14 +0000 (07:01 +0530)
committerSrinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>
Thu, 4 Aug 2016 17:38:13 +0000 (23:08 +0530)
src/librustc_passes/ast_validation.rs
src/librustc_passes/consts.rs
src/librustc_passes/lib.rs
src/librustc_passes/loops.rs
src/librustc_passes/no_asm.rs
src/librustc_passes/static_recursion.rs

index d2cf48eddebac2de42b84571262075df045d4af7..91d2500564fd3b7d246f406fcb8d117fb0fede0b 100644 (file)
@@ -38,16 +38,18 @@ fn check_label(&self, label: Ident, span: Span, id: NodeId) {
             self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
         }
         if label.name.as_str() == "'_" {
-            self.session.add_lint(
-                lint::builtin::LIFETIME_UNDERSCORE, id, span,
-                format!("invalid label name `{}`", label.name)
-            );
+            self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+                                  id,
+                                  span,
+                                  format!("invalid label name `{}`", label.name));
         }
     }
 
     fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) {
         if vis != &Visibility::Inherited {
-            let mut err = struct_span_err!(self.session, span, E0449,
+            let mut err = struct_span_err!(self.session,
+                                           span,
+                                           E0449,
                                            "unnecessary visibility qualifier");
             if let Some(note) = note {
                 err.span_note(span, note);
@@ -71,10 +73,10 @@ fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err:
 impl<'a> Visitor for AstValidator<'a> {
     fn visit_lifetime(&mut self, lt: &Lifetime) {
         if lt.name.as_str() == "'_" {
-            self.session.add_lint(
-                lint::builtin::LIFETIME_UNDERSCORE, lt.id, lt.span,
-                format!("invalid lifetime name `{}`", lt.name)
-            );
+            self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+                                  lt.id,
+                                  lt.span,
+                                  format!("invalid lifetime name `{}`", lt.name));
         }
 
         visit::walk_lifetime(self, lt)
@@ -82,9 +84,12 @@ fn visit_lifetime(&mut self, lt: &Lifetime) {
 
     fn visit_expr(&mut self, expr: &Expr) {
         match expr.node {
-            ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) |
-            ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) |
-            ExprKind::Break(Some(ident)) | ExprKind::Continue(Some(ident)) => {
+            ExprKind::While(_, _, Some(ident)) |
+            ExprKind::Loop(_, Some(ident)) |
+            ExprKind::WhileLet(_, _, _, Some(ident)) |
+            ExprKind::ForLoop(_, _, _, Some(ident)) |
+            ExprKind::Break(Some(ident)) |
+            ExprKind::Continue(Some(ident)) => {
                 self.check_label(ident.node, ident.span, expr.id);
             }
             _ => {}
@@ -97,10 +102,13 @@ fn visit_ty(&mut self, ty: &Ty) {
         match ty.node {
             TyKind::BareFn(ref bfty) => {
                 self.check_decl_no_pat(&bfty.decl, |span, _| {
-                    let mut err = struct_span_err!(self.session, span, E0561,
-                                            "patterns aren't allowed in function pointer types");
-                    err.span_note(span, "this is a recent error, see \
-                                         issue #35203 for more details");
+                    let mut err = struct_span_err!(self.session,
+                                                   span,
+                                                   E0561,
+                                                   "patterns aren't allowed in function pointer \
+                                                    types");
+                    err.span_note(span,
+                                  "this is a recent error, see issue #35203 for more details");
                     err.emit();
                 });
             }
@@ -114,10 +122,10 @@ fn visit_path(&mut self, path: &Path, id: NodeId) {
         if path.global && path.segments.len() > 0 {
             let ident = path.segments[0].identifier;
             if token::Ident(ident).is_path_segment_keyword() {
-                self.session.add_lint(
-                    lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
-                    format!("global paths cannot start with `{}`", ident)
-                );
+                self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
+                                      id,
+                                      path.span,
+                                      format!("global paths cannot start with `{}`", ident));
             }
         }
 
@@ -129,8 +137,8 @@ fn visit_item(&mut self, item: &Item) {
             ItemKind::Use(ref view_path) => {
                 let path = view_path.node.path();
                 if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
-                    self.err_handler().span_err(path.span, "type or lifetime parameters \
-                                                            in import path");
+                    self.err_handler()
+                        .span_err(path.span, "type or lifetime parameters in import path");
                 }
             }
             ItemKind::Impl(_, _, _, Some(..), _, ref impl_items) => {
@@ -140,15 +148,18 @@ fn visit_item(&mut self, item: &Item) {
                 }
             }
             ItemKind::Impl(_, _, _, None, _, _) => {
-                self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
-                                                                    impl items instead"));
+                self.invalid_visibility(&item.vis,
+                                        item.span,
+                                        Some("place qualifiers on individual impl items instead"));
             }
             ItemKind::DefaultImpl(..) => {
                 self.invalid_visibility(&item.vis, item.span, None);
             }
             ItemKind::ForeignMod(..) => {
-                self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
-                                                                    foreign items instead"));
+                self.invalid_visibility(&item.vis,
+                                        item.span,
+                                        Some("place qualifiers on individual foreign items \
+                                              instead"));
             }
             ItemKind::Enum(ref def, _) => {
                 for variant in &def.variants {
@@ -167,11 +178,14 @@ fn visit_foreign_item(&mut self, fi: &ForeignItem) {
         match fi.node {
             ForeignItemKind::Fn(ref decl, _) => {
                 self.check_decl_no_pat(decl, |span, is_recent| {
-                    let mut err = struct_span_err!(self.session, span, E0130,
-                                        "patterns aren't allowed in foreign function declarations");
+                    let mut err = struct_span_err!(self.session,
+                                                   span,
+                                                   E0130,
+                                                   "patterns aren't allowed in foreign function \
+                                                    declarations");
                     if is_recent {
-                        err.span_note(span, "this is a recent error, see \
-                                             issue #35203 for more details");
+                        err.span_note(span,
+                                      "this is a recent error, see issue #35203 for more details");
                     }
                     err.emit();
                 });
@@ -182,16 +196,21 @@ fn visit_foreign_item(&mut self, fi: &ForeignItem) {
         visit::walk_foreign_item(self, fi)
     }
 
-    fn visit_variant_data(&mut self, vdata: &VariantData, _: Ident,
-                          _: &Generics, _: NodeId, span: Span) {
+    fn visit_variant_data(&mut self,
+                          vdata: &VariantData,
+                          _: Ident,
+                          _: &Generics,
+                          _: NodeId,
+                          span: Span) {
         if vdata.fields().is_empty() {
             if vdata.is_tuple() {
-                self.err_handler().struct_span_err(span, "empty tuple structs and enum variants \
-                                                          are not allowed, use unit structs and \
-                                                          enum variants instead")
-                                         .span_help(span, "remove trailing `()` to make a unit \
-                                                           struct or unit enum variant")
-                                         .emit();
+                self.err_handler()
+                    .struct_span_err(span,
+                                     "empty tuple structs and enum variants are not allowed, use \
+                                      unit structs and enum variants instead")
+                    .span_help(span,
+                               "remove trailing `()` to make a unit struct or unit enum variant")
+                    .emit();
             }
         }
 
@@ -200,10 +219,10 @@ struct or unit enum variant")
 
     fn visit_vis(&mut self, vis: &Visibility) {
         match *vis {
-            Visibility::Restricted{ref path, ..} => {
+            Visibility::Restricted { ref path, .. } => {
                 if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
-                    self.err_handler().span_err(path.span, "type or lifetime parameters \
-                                                            in visibility path");
+                    self.err_handler()
+                        .span_err(path.span, "type or lifetime parameters in visibility path");
                 }
             }
             _ => {}
index 1030a4b0116de5a07572ffa53fa974d909f4b6b7..fc55118c9f4c518ed0fa989067cf40f95f580f9e 100644 (file)
@@ -25,7 +25,7 @@
 // by borrowck::gather_loans
 
 use rustc::dep_graph::DepNode;
-use rustc::ty::cast::{CastKind};
+use rustc::ty::cast::CastKind;
 use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
 use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
 use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
@@ -71,12 +71,12 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     mode: Mode,
     qualif: ConstQualif,
-    rvalue_borrows: NodeMap<hir::Mutability>
+    rvalue_borrows: NodeMap<hir::Mutability>,
 }
 
 impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
-    fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
-        F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R,
+    fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R
+        where F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R
     {
         let (old_mode, old_qualif) = (self.mode, self.qualif);
         self.mode = mode;
@@ -87,17 +87,17 @@ fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
         r
     }
 
-    fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R where
-        F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R,
+    fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R
+        where F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R
     {
         let param_env = match item_id {
             Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
-            None => self.tcx.empty_parameter_environment()
+            None => self.tcx.empty_parameter_environment(),
         };
 
-        self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal).enter(|infcx| {
-            f(&mut euv::ExprUseVisitor::new(self, &infcx))
-        })
+        self.tcx
+            .infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal)
+            .enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx)))
     }
 
     fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
@@ -111,13 +111,17 @@ fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
         }
         if let Err(err) = eval_const_expr_partial(self.tcx, expr, ExprTypeChecked, None) {
             match err.kind {
-                UnimplementedConstVal(_) => {},
-                IndexOpFeatureGated => {},
-                ErroneousReferencedConstant(_) => {},
-                _ => self.tcx.sess.add_lint(CONST_ERR, expr.id, expr.span,
-                                         format!("constant evaluation error: {}. This will \
-                                                 become a HARD ERROR in the future",
-                                                 err.description().into_oneline())),
+                UnimplementedConstVal(_) => {}
+                IndexOpFeatureGated => {}
+                ErroneousReferencedConstant(_) => {}
+                _ => {
+                    self.tcx.sess.add_lint(CONST_ERR,
+                                           expr.id,
+                                           expr.span,
+                                           format!("constant evaluation error: {}. This will \
+                                                    become a HARD ERROR in the future",
+                                                   err.description().into_oneline()))
+                }
             }
         }
         self.with_mode(mode, |this| {
@@ -143,9 +147,7 @@ fn fn_like(&mut self,
         }
 
         let mode = match fk {
-            FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => {
-                Mode::ConstFn
-            }
+            FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => Mode::ConstFn,
             FnKind::Method(_, m, _, _) => {
                 if m.constness == hir::Constness::Const {
                     Mode::ConstFn
@@ -153,7 +155,7 @@ fn fn_like(&mut self,
                     Mode::Var
                 }
             }
-            _ => Mode::Var
+            _ => Mode::Var,
         };
 
         let qualif = self.with_mode(mode, |this| {
@@ -175,11 +177,7 @@ fn add_qualif(&mut self, qualif: ConstQualif) {
     }
 
     /// Returns true if the call is to a const fn or method.
-    fn handle_const_fn_call(&mut self,
-                            _expr: &hir::Expr,
-                            def_id: DefId,
-                            ret_ty: Ty<'gcx>)
-                            -> bool {
+    fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
         if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
             let qualif = self.fn_like(fn_like.kind(),
                                       fn_like.decl(),
@@ -285,13 +283,15 @@ fn visit_pat(&mut self, p: &hir::Pat) {
                     Ok(Ordering::Less) |
                     Ok(Ordering::Equal) => {}
                     Ok(Ordering::Greater) => {
-                        span_err!(self.tcx.sess, start.span, E0030,
-                            "lower range bound must be less than or equal to upper");
+                        span_err!(self.tcx.sess,
+                                  start.span,
+                                  E0030,
+                                  "lower range bound must be less than or equal to upper");
                     }
                     Err(ErrorReported) => {}
                 }
             }
-            _ => intravisit::walk_pat(self, p)
+            _ => intravisit::walk_pat(self, p),
         }
     }
 
@@ -301,13 +301,13 @@ fn visit_block(&mut self, block: &hir::Block) {
             match stmt.node {
                 hir::StmtDecl(ref decl, _) => {
                     match decl.node {
-                        hir::DeclLocal(_) => {},
+                        hir::DeclLocal(_) => {}
                         // Item statements are allowed
-                        hir::DeclItem(_) => continue
+                        hir::DeclItem(_) => continue,
                     }
                 }
-                hir::StmtExpr(_, _) => {},
-                hir::StmtSemi(_, _) => {},
+                hir::StmtExpr(_, _) => {}
+                hir::StmtSemi(_, _) => {}
             }
             self.add_qualif(ConstQualif::NOT_CONST);
         }
@@ -340,7 +340,7 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                 // The count is checked elsewhere (typeck).
                 let count = match node_ty.sty {
                     ty::TyArray(_, n) => n,
-                    _ => bug!()
+                    _ => bug!(),
                 };
                 // [element; 0] is always zero-sized.
                 if count == 0 {
@@ -354,7 +354,8 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                 for pat in arms.iter().flat_map(|arm| &arm.pats) {
                     let pat_borrow = self.rvalue_borrows.remove(&pat.id);
                     match (borrow, pat_borrow) {
-                        (None, _) | (_, Some(hir::MutMutable)) => {
+                        (None, _) |
+                        (_, Some(hir::MutMutable)) => {
                             borrow = pat_borrow;
                         }
                         _ => {}
@@ -365,7 +366,7 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                 }
                 intravisit::walk_expr(self, ex);
             }
-            _ => intravisit::walk_expr(self, ex)
+            _ => intravisit::walk_expr(self, ex),
         }
 
         // Handle borrows on (or inside the autorefs of) this expression.
@@ -405,17 +406,18 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
         if self.mode == Mode::Var && !self.qualif.intersects(ConstQualif::NOT_CONST) {
             match eval_const_expr_partial(self.tcx, ex, ExprTypeChecked, None) {
                 Ok(_) => {}
-                Err(ConstEvalErr { kind: UnimplementedConstVal(_), ..}) |
-                Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
-                Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
-                Err(ConstEvalErr { kind: NonConstPath, ..}) |
-                Err(ConstEvalErr { kind: UnresolvedPath, ..}) |
-                Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
-                Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
-                Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
-                Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
+                Err(ConstEvalErr { kind: UnimplementedConstVal(_), .. }) |
+                Err(ConstEvalErr { kind: MiscCatchAll, .. }) |
+                Err(ConstEvalErr { kind: MiscBinaryOp, .. }) |
+                Err(ConstEvalErr { kind: NonConstPath, .. }) |
+                Err(ConstEvalErr { kind: UnresolvedPath, .. }) |
+                Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), .. }) |
+                Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), .. }) |
+                Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), .. }) |
+                Err(ConstEvalErr { kind: IndexOpFeatureGated, .. }) => {}
                 Err(msg) => {
-                    self.tcx.sess.add_lint(CONST_ERR, ex.id,
+                    self.tcx.sess.add_lint(CONST_ERR,
+                                           ex.id,
                                            msg.span,
                                            msg.description().into_oneline().into_owned())
                 }
@@ -434,8 +436,7 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
 /// every nested expression. If the expression is not part
 /// of a const/static item, it is qualified for promotion
 /// instead of producing errors.
-fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
-                        e: &hir::Expr, node_ty: Ty<'tcx>) {
+fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node_ty: Ty<'tcx>) {
     match node_ty.sty {
         ty::TyStruct(def, _) |
         ty::TyEnum(def, _) if def.has_dtor() => {
@@ -635,12 +636,9 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
         Some(&ty::adjustment::AdjustUnsafeFnPointer) |
         Some(&ty::adjustment::AdjustMutToConstPointer) => {}
 
-        Some(&ty::adjustment::AdjustDerefRef(
-            ty::adjustment::AutoDerefRef { autoderefs, .. }
-        )) => {
-            if (0..autoderefs as u32).any(|autoderef| {
-                    v.tcx.is_overloaded_autoderef(e.id, autoderef)
-            }) {
+        Some(&ty::adjustment::AdjustDerefRef(ty::adjustment::AutoDerefRef { autoderefs, .. })) => {
+            if (0..autoderefs as u32)
+                .any(|autoderef| v.tcx.is_overloaded_autoderef(e.id, autoderef)) {
                 v.add_qualif(ConstQualif::NOT_CONST);
             }
         }
@@ -648,12 +646,13 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
 }
 
 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
-    tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
-        tcx: tcx,
-        mode: Mode::Var,
-        qualif: ConstQualif::NOT_CONST,
-        rvalue_borrows: NodeMap()
-    });
+    tcx.visit_all_items_in_krate(DepNode::CheckConst,
+                                 &mut CheckCrateVisitor {
+                                     tcx: tcx,
+                                     mode: Mode::Var,
+                                     qualif: ConstQualif::NOT_CONST,
+                                     rvalue_borrows: NodeMap(),
+                                 });
     tcx.sess.abort_if_errors();
 }
 
@@ -675,7 +674,7 @@ fn consume(&mut self,
 
                 Categorization::Rvalue(..) |
                 Categorization::Upvar(..) |
-                Categorization::Local(..) => break
+                Categorization::Local(..) => break,
             }
         }
     }
@@ -685,8 +684,7 @@ fn borrow(&mut self,
               cmt: mc::cmt<'tcx>,
               _loan_region: ty::Region,
               bk: ty::BorrowKind,
-              loan_cause: euv::LoanCause)
-    {
+              loan_cause: euv::LoanCause) {
         // Kind of hacky, but we allow Unsafe coercions in constants.
         // These occur when we convert a &T or *T to a *U, as well as
         // when making a thin pointer (e.g., `*T`) into a fat pointer
@@ -695,7 +693,7 @@ fn borrow(&mut self,
             euv::LoanCause::AutoUnsafe => {
                 return;
             }
-            _ => { }
+            _ => {}
         }
 
         let mut cur = &cmt;
@@ -715,7 +713,8 @@ fn borrow(&mut self,
                         // type of the expression.  `&mut [1]` has exactly the
                         // same representation as &mut 1.
                         match cmt.ty.sty {
-                            ty::TyArray(_, _) | ty::TySlice(_) => break,
+                            ty::TyArray(_, _) |
+                            ty::TySlice(_) => break,
                             _ => {}
                         }
                     }
@@ -732,27 +731,20 @@ fn borrow(&mut self,
                 }
 
                 Categorization::Upvar(..) |
-                Categorization::Local(..) => break
+                Categorization::Local(..) => break,
             }
         }
     }
 
-    fn decl_without_init(&mut self,
-                         _id: ast::NodeId,
-                         _span: Span) {}
+    fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
     fn mutate(&mut self,
               _assignment_id: ast::NodeId,
               _assignment_span: Span,
               _assignee_cmt: mc::cmt,
-              _mode: euv::MutateMode) {}
+              _mode: euv::MutateMode) {
+    }
 
-    fn matched_pat(&mut self,
-                   _: &hir::Pat,
-                   _: mc::cmt,
-                   _: euv::MatchMode) {}
+    fn matched_pat(&mut self, _: &hir::Pat, _: mc::cmt, _: euv::MatchMode) {}
 
-    fn consume_pat(&mut self,
-                   _consume_pat: &hir::Pat,
-                   _cmt: mc::cmt,
-                   _mode: euv::ConsumeMode) {}
+    fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: mc::cmt, _mode: euv::ConsumeMode) {}
 }
index 650613f4844f526facb139225cc39d3a8a46e1e4..e59c4a6fc4186bfbb9664dcf7042a630ce574de9 100644 (file)
 #![feature(rustc_private)]
 
 extern crate core;
-#[macro_use] extern crate rustc;
+#[macro_use]
+extern crate rustc;
 extern crate rustc_const_eval;
 extern crate rustc_const_math;
 
-#[macro_use] extern crate log;
-#[macro_use] extern crate syntax;
+#[macro_use]
+extern crate log;
+#[macro_use]
+extern crate syntax;
 extern crate syntax_pos;
 extern crate rustc_errors as errors;
 
index dd0f16baaa395d524e6e91bf2abdcb3dbe5e0d65..4e251793f6917ae645fc6c14c7581aa26c3f658d 100644 (file)
 
 #[derive(Clone, Copy, PartialEq)]
 enum Context {
-    Normal, Loop, Closure
+    Normal,
+    Loop,
+    Closure,
 }
 
 #[derive(Copy, Clone)]
 struct CheckLoopVisitor<'a> {
     sess: &'a Session,
-    cx: Context
+    cx: Context,
 }
 
 pub fn check_crate(sess: &Session, map: &Map) {
     let _task = map.dep_graph.in_task(DepNode::CheckLoops);
     let krate = map.krate();
-    krate.visit_all_items(&mut CheckLoopVisitor { sess: sess, cx: Normal });
+    krate.visit_all_items(&mut CheckLoopVisitor {
+        sess: sess,
+        cx: Normal,
+    });
 }
 
 impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
@@ -53,14 +58,14 @@ fn visit_expr(&mut self, e: &hir::Expr) {
             }
             hir::ExprBreak(_) => self.require_loop("break", e.span),
             hir::ExprAgain(_) => self.require_loop("continue", e.span),
-            _ => intravisit::walk_expr(self, e)
+            _ => intravisit::walk_expr(self, e),
         }
     }
 }
 
 impl<'a> CheckLoopVisitor<'a> {
-    fn with_context<F>(&mut self, cx: Context, f: F) where
-        F: FnOnce(&mut CheckLoopVisitor<'a>),
+    fn with_context<F>(&mut self, cx: Context, f: F)
+        where F: FnOnce(&mut CheckLoopVisitor<'a>)
     {
         let old_cx = self.cx;
         self.cx = cx;
@@ -72,12 +77,10 @@ fn require_loop(&self, name: &str, span: Span) {
         match self.cx {
             Loop => {}
             Closure => {
-                span_err!(self.sess, span, E0267,
-                                   "`{}` inside of a closure", name);
+                span_err!(self.sess, span, E0267, "`{}` inside of a closure", name);
             }
             Normal => {
-                span_err!(self.sess, span, E0268,
-                                   "`{}` outside of loop", name);
+                span_err!(self.sess, span, E0268, "`{}` outside of loop", name);
             }
         }
     }
index 314513a974ecdb826b728523403a5056c635a062..af3065d64e8db08bc7fd8ee36cca33a93971fff3 100644 (file)
 use syntax::visit;
 
 pub fn check_crate(sess: &Session, krate: &ast::Crate) {
-    if sess.target.target.options.allow_asm { return; }
+    if sess.target.target.options.allow_asm {
+        return;
+    }
 
-    visit::walk_crate(&mut CheckNoAsm { sess: sess, }, krate);
+    visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate);
 }
 
 #[derive(Copy, Clone)]
@@ -32,9 +34,13 @@ struct CheckNoAsm<'a> {
 impl<'a> Visitor for CheckNoAsm<'a> {
     fn visit_expr(&mut self, e: &ast::Expr) {
         match e.node {
-            ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
-                                                     "asm! is unsupported on this target"),
-            _ => {},
+            ast::ExprKind::InlineAsm(_) => {
+                span_err!(self.sess,
+                          e.span,
+                          E0472,
+                          "asm! is unsupported on this target")
+            }
+            _ => {}
         }
         visit::walk_expr(self, e)
     }
index d0938ad09a0da1bced4e17ef57d5c1c1096c97fe..8b2943a33c006aaced7fd7cee377a241ff187467 100644 (file)
 
 use rustc::dep_graph::DepNode;
 use rustc::hir::map as ast_map;
-use rustc::session::{Session, CompileResult};
+use rustc::session::{CompileResult, Session};
 use rustc::hir::def::{Def, DefMap};
 use rustc::util::nodemap::NodeMap;
 
-use syntax::{ast};
+use syntax::ast;
 use syntax::feature_gate::{GateIssue, emit_feature_err};
 use syntax_pos::Span;
 use rustc::hir::intravisit::{self, Visitor};
@@ -41,18 +41,17 @@ fn visit_item(&mut self, it: &'ast hir::Item) {
         match it.node {
             hir::ItemStatic(..) |
             hir::ItemConst(..) => {
-                let mut recursion_visitor =
-                    CheckItemRecursionVisitor::new(self, &it.span);
+                let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span);
                 recursion_visitor.visit_item(it);
-            },
+            }
             hir::ItemEnum(ref enum_def, ref generics) => {
                 // We could process the whole enum, but handling the variants
                 // with discriminant expressions one by one gives more specific,
                 // less redundant output.
                 for variant in &enum_def.variants {
                     if let Some(_) = variant.node.disr_expr {
-                        let mut recursion_visitor =
-                            CheckItemRecursionVisitor::new(self, &variant.span);
+                        let mut recursion_visitor = CheckItemRecursionVisitor::new(self,
+                                                                                   &variant.span);
                         recursion_visitor.populate_enum_discriminants(enum_def);
                         recursion_visitor.visit_variant(variant, generics, it.id);
                     }
@@ -67,8 +66,7 @@ fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
         match ti.node {
             hir::ConstTraitItem(_, ref default) => {
                 if let Some(_) = *default {
-                    let mut recursion_visitor =
-                        CheckItemRecursionVisitor::new(self, &ti.span);
+                    let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ti.span);
                     recursion_visitor.visit_trait_item(ti);
                 }
             }
@@ -80,8 +78,7 @@ fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
     fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
         match ii.node {
             hir::ImplItemKind::Const(..) => {
-                let mut recursion_visitor =
-                    CheckItemRecursionVisitor::new(self, &ii.span);
+                let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
                 recursion_visitor.visit_impl_item(ii);
             }
             _ => {}
@@ -117,7 +114,8 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
 }
 
 impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
-    fn new(v: &'a CheckCrateVisitor<'a, 'ast>, span: &'a Span)
+    fn new(v: &'a CheckCrateVisitor<'a, 'ast>,
+           span: &'a Span)
            -> CheckItemRecursionVisitor<'a, 'ast> {
         CheckItemRecursionVisitor {
             root_span: span,
@@ -129,7 +127,8 @@ fn new(v: &'a CheckCrateVisitor<'a, 'ast>, span: &'a Span)
         }
     }
     fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
-          where F: Fn(&mut Self) {
+        where F: Fn(&mut Self)
+    {
         if self.idstack.iter().any(|&x| x == id) {
             let any_static = self.idstack.iter().any(|&x| {
                 if let ast_map::NodeItem(item) = self.ast_map.get(x) {
@@ -146,7 +145,9 @@ fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
                 if !self.sess.features.borrow().static_recursion {
                     emit_feature_err(&self.sess.parse_sess.span_diagnostic,
                                      "static_recursion",
-                                     *self.root_span, GateIssue::Language, "recursive static");
+                                     *self.root_span,
+                                     GateIssue::Language,
+                                     "recursive static");
                 }
             } else {
                 span_err!(self.sess, *self.root_span, E0265, "recursive constant");
@@ -170,7 +171,9 @@ fn populate_enum_discriminants(&self, enum_definition: &'ast hir::EnumDef) {
         // has no variants.
         let mut discriminant_map = self.discriminant_map.borrow_mut();
         match enum_definition.variants.first() {
-            None => { return; }
+            None => {
+                return;
+            }
             Some(variant) if discriminant_map.contains_key(&variant.node.data.id()) => {
                 return;
             }
@@ -203,14 +206,19 @@ fn visit_item(&mut self, it: &'ast hir::Item) {
         self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
     }
 
-    fn visit_enum_def(&mut self, enum_definition: &'ast hir::EnumDef,
-                      generics: &'ast hir::Generics, item_id: ast::NodeId, _: Span) {
+    fn visit_enum_def(&mut self,
+                      enum_definition: &'ast hir::EnumDef,
+                      generics: &'ast hir::Generics,
+                      item_id: ast::NodeId,
+                      _: Span) {
         self.populate_enum_discriminants(enum_definition);
         intravisit::walk_enum_def(self, enum_definition, generics, item_id);
     }
 
-    fn visit_variant(&mut self, variant: &'ast hir::Variant,
-                     _: &'ast hir::Generics, _: ast::NodeId) {
+    fn visit_variant(&mut self,
+                     variant: &'ast hir::Variant,
+                     _: &'ast hir::Generics,
+                     _: ast::NodeId) {
         let variant_id = variant.node.data.id();
         let maybe_expr;
         if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
@@ -246,18 +254,14 @@ fn visit_expr(&mut self, e: &'ast hir::Expr) {
                     Some(Def::Const(def_id)) => {
                         if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
                             match self.ast_map.get(node_id) {
-                                ast_map::NodeItem(item) =>
-                                    self.visit_item(item),
-                                ast_map::NodeTraitItem(item) =>
-                                    self.visit_trait_item(item),
-                                ast_map::NodeImplItem(item) =>
-                                    self.visit_impl_item(item),
-                                ast_map::NodeForeignItem(_) => {},
+                                ast_map::NodeItem(item) => self.visit_item(item),
+                                ast_map::NodeTraitItem(item) => self.visit_trait_item(item),
+                                ast_map::NodeImplItem(item) => self.visit_impl_item(item),
+                                ast_map::NodeForeignItem(_) => {}
                                 _ => {
-                                    span_bug!(
-                                        e.span,
-                                        "expected item, found {}",
-                                        self.ast_map.node_to_string(node_id));
+                                    span_bug!(e.span,
+                                              "expected item, found {}",
+                                              self.ast_map.node_to_string(node_id));
                                 }
                             }
                         }
@@ -268,9 +272,9 @@ fn visit_expr(&mut self, e: &'ast hir::Expr) {
                     // might be (if any).
                     Some(Def::Variant(enum_id, variant_id)) => {
                         if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
-                            if let hir::ItemEnum(ref enum_def, ref generics) =
-                                self.ast_map.expect_item(enum_node_id).node
-                            {
+                            if let hir::ItemEnum(ref enum_def, ref generics) = self.ast_map
+                                .expect_item(enum_node_id)
+                                .node {
                                 self.populate_enum_discriminants(enum_def);
                                 let enum_id = self.ast_map.as_local_node_id(enum_id).unwrap();
                                 let variant_id = self.ast_map.as_local_node_id(variant_id).unwrap();
@@ -283,10 +287,10 @@ fn visit_expr(&mut self, e: &'ast hir::Expr) {
                             }
                         }
                     }
-                    _ => ()
+                    _ => (),
                 }
-            },
-            _ => ()
+            }
+            _ => (),
         }
         intravisit::walk_expr(self, e);
     }