]> git.lizzy.rs Git - rust.git/commitdiff
rustfmt syntax::parse
authorTshepang Lekhonkhobe <tshepang@gmail.com>
Wed, 27 Jan 2016 19:42:26 +0000 (21:42 +0200)
committerTshepang Lekhonkhobe <tshepang@gmail.com>
Wed, 27 Jan 2016 19:45:14 +0000 (21:45 +0200)
src/libsyntax/parse/attr.rs
src/libsyntax/parse/classify.rs
src/libsyntax/parse/common.rs

index cad9b45694b28b5bc4d144682fa1e8fd35a63b3f..96ac9b83d2f2400ceab12f5680a88de399333eb4 100644 (file)
@@ -22,26 +22,25 @@ impl<'a> Parser<'a> {
     pub fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
         let mut attrs: Vec<ast::Attribute> = Vec::new();
         loop {
-            debug!("parse_outer_attributes: self.token={:?}",
-                   self.token);
+            debug!("parse_outer_attributes: self.token={:?}", self.token);
             match self.token {
-              token::Pound => {
-                attrs.push(try!(self.parse_attribute(false)));
-              }
-              token::DocComment(s) => {
-                let attr = ::attr::mk_sugared_doc_attr(
+                token::Pound => {
+                    attrs.push(try!(self.parse_attribute(false)));
+                }
+                token::DocComment(s) => {
+                    let attr = ::attr::mk_sugared_doc_attr(
                     attr::mk_attr_id(),
                     self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)),
                     self.span.lo,
                     self.span.hi
                 );
-                if attr.node.style != ast::AttrStyle::Outer {
-                  return Err(self.fatal("expected outer comment"));
+                    if attr.node.style != ast::AttrStyle::Outer {
+                        return Err(self.fatal("expected outer comment"));
+                    }
+                    attrs.push(attr);
+                    self.bump();
                 }
-                attrs.push(attr);
-                self.bump();
-              }
-              _ => break
+                _ => break,
             }
         }
         return Ok(attrs);
@@ -53,24 +52,27 @@ pub fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
     /// attribute
     pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attribute> {
         debug!("parse_attributes: permit_inner={:?} self.token={:?}",
-               permit_inner, self.token);
+               permit_inner,
+               self.token);
         let (span, value, mut style) = match self.token {
             token::Pound => {
                 let lo = self.span.lo;
                 self.bump();
 
-                if permit_inner { self.expected_tokens.push(TokenType::Token(token::Not)); }
+                if permit_inner {
+                    self.expected_tokens.push(TokenType::Token(token::Not));
+                }
                 let style = if self.token == token::Not {
                     self.bump();
                     if !permit_inner {
                         let span = self.span;
-                        self.diagnostic().struct_span_err(span,
-                                                          "an inner attribute is not permitted in \
-                                                           this context")
-                                         .fileline_help(span,
-                                                        "place inner attribute at the top of \
-                                                         the module or block")
-                                         .emit()
+                        self.diagnostic()
+                            .struct_span_err(span,
+                                             "an inner attribute is not permitted in this context")
+                            .fileline_help(span,
+                                           "place inner attribute at the top of the module or \
+                                            block")
+                            .emit()
                     }
                     ast::AttrStyle::Inner
                 } else {
@@ -92,8 +94,9 @@ pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attrib
 
         if permit_inner && self.token == token::Semi {
             self.bump();
-            self.span_warn(span, "this inner attribute syntax is deprecated. \
-                           The new syntax is `#![foo]`, with a bang and no semicolon");
+            self.span_warn(span,
+                           "this inner attribute syntax is deprecated. The new syntax is \
+                            `#![foo]`, with a bang and no semicolon");
             style = ast::AttrStyle::Inner;
         }
 
@@ -103,8 +106,8 @@ pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, ast::Attrib
                 id: attr::mk_attr_id(),
                 style: style,
                 value: value,
-                is_sugared_doc: false
-            }
+                is_sugared_doc: false,
+            },
         })
     }
 
@@ -139,7 +142,7 @@ pub fn parse_inner_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
                         break;
                     }
                 }
-                _ => break
+                _ => break,
             }
         }
         Ok(attrs)
@@ -150,10 +153,8 @@ pub fn parse_inner_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
     /// | IDENT meta_seq
     pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
         let nt_meta = match self.token {
-            token::Interpolated(token::NtMeta(ref e)) => {
-                Some(e.clone())
-            }
-            _ => None
+            token::Interpolated(token::NtMeta(ref e)) => Some(e.clone()),
+            _ => None,
         };
 
         match nt_meta {
@@ -176,9 +177,8 @@ pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
                 match lit.node {
                     ast::LitStr(..) => {}
                     _ => {
-                        self.span_err(
-                            lit.span,
-                            "non-string literals are not allowed in meta-items");
+                        self.span_err(lit.span,
+                                      "non-string literals are not allowed in meta-items");
                     }
                 }
                 let hi = self.span.hi;
index 8b3faaaca146a9d7d512201b7f4cade3ce3fef65..1193224bdb62559e895f8c4e5d4a45dcd7bfc645 100644 (file)
 /// isn't parsed as (if true {...} else {...} | x) | 5
 pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
     match e.node {
-        ast::ExprIf(..)
-        | ast::ExprIfLet(..)
-        | ast::ExprMatch(..)
-        | ast::ExprBlock(_)
-        | ast::ExprWhile(..)
-        | ast::ExprWhileLet(..)
-        | ast::ExprLoop(..)
-        ast::ExprForLoop(..) => false,
-        _ => true
+        ast::ExprIf(..) |
+        ast::ExprIfLet(..) |
+        ast::ExprMatch(..) |
+        ast::ExprBlock(_) |
+        ast::ExprWhile(..) |
+        ast::ExprWhileLet(..) |
+        ast::ExprLoop(..) |
+        ast::ExprForLoop(..) => false,
+        _ => true,
     }
 }
 
 pub fn expr_is_simple_block(e: &ast::Expr) -> bool {
     match e.node {
         ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock,
-        _ => false
+        _ => false,
     }
 }
 
@@ -50,11 +50,11 @@ pub fn stmt_ends_with_semi(stmt: &ast::Stmt_) -> bool {
         ast::StmtDecl(ref d, _) => {
             match d.node {
                 ast::DeclLocal(_) => true,
-                ast::DeclItem(_) => false
+                ast::DeclItem(_) => false,
             }
         }
-        ast::StmtExpr(ref e, _) => { expr_requires_semi_to_be_stmt(e) }
-        ast::StmtSemi(..) => { false }
-        ast::StmtMac(..) => { false }
+        ast::StmtExpr(ref e, _) => expr_requires_semi_to_be_stmt(e),
+        ast::StmtSemi(..) => false,
+        ast::StmtMac(..) => false,
     }
 }
index a96bf1ce10b798064b2d2b6fdc24da50190ee412..060b0b5263765f8e7839edbc31c36dca09ab4365 100644 (file)
@@ -16,7 +16,7 @@
 /// and whether a trailing separator is allowed.
 pub struct SeqSep {
     pub sep: Option<token::Token>,
-    pub trailing_sep_allowed: bool
+    pub trailing_sep_allowed: bool,
 }
 
 pub fn seq_sep_trailing_allowed(t: token::Token) -> SeqSep {