about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/attr.rs4
-rw-r--r--src/libsyntax/parse/lexer/mod.rs8
-rw-r--r--src/libsyntax/parse/mod.rs230
-rw-r--r--src/libsyntax/parse/parser.rs10
-rw-r--r--src/libsyntax/parse/token.rs10
5 files changed, 43 insertions, 219 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs
index 9919d910fbc..4d59f64bb6b 100644
--- a/src/libsyntax/parse/attr.rs
+++ b/src/libsyntax/parse/attr.rs
@@ -16,7 +16,7 @@ use parse::token::{self, Nonterminal};
 use parse::parser::{Parser, TokenType, PathStyle};
 use tokenstream::TokenStream;
 
-#[derive(PartialEq, Eq, Debug)]
+#[derive(Debug)]
 enum InnerAttributeParsePolicy<'a> {
     Permitted,
     NotPermitted { reason: &'a str },
@@ -94,7 +94,7 @@ impl<'a> Parser<'a> {
                 let lo = self.span;
                 self.bump();
 
-                if inner_parse_policy == InnerAttributeParsePolicy::Permitted {
+                if let InnerAttributeParsePolicy::Permitted = inner_parse_policy {
                     self.expected_tokens.push(TokenType::Token(token::Not));
                 }
                 let style = if self.token == token::Not {
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index dcc71e78778..bf790e6143a 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -26,7 +26,7 @@ pub mod comments;
 mod tokentrees;
 mod unicode_chars;
 
-#[derive(Clone, PartialEq, Eq, Debug)]
+#[derive(Clone, Debug)]
 pub struct TokenAndSpan {
     pub tok: token::Token,
     pub sp: Span,
@@ -1842,7 +1842,8 @@ mod tests {
                 tok: token::Ident(id, false),
                 sp: Span::new(BytePos(21), BytePos(23), NO_EXPANSION),
             };
-            assert_eq!(tok1, tok2);
+            assert_eq!(tok1.tok, tok2.tok);
+            assert_eq!(tok1.sp, tok2.sp);
             assert_eq!(string_reader.next_token().tok, token::Whitespace);
             // the 'main' id is already read:
             assert_eq!(string_reader.pos.clone(), BytePos(28));
@@ -1852,7 +1853,8 @@ mod tests {
                 tok: mk_ident("main"),
                 sp: Span::new(BytePos(24), BytePos(28), NO_EXPANSION),
             };
-            assert_eq!(tok3, tok4);
+            assert_eq!(tok3.tok, tok4.tok);
+            assert_eq!(tok3.sp, tok4.sp);
             // the lparen is already read:
             assert_eq!(string_reader.pos.clone(), BytePos(29))
         })
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index c443f240780..1754e5f1b9a 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -673,22 +673,40 @@ fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)
     })
 }
 
+/// `SeqSep` : a sequence separator (token)
+/// and whether a trailing separator is allowed.
+pub struct SeqSep {
+    pub sep: Option<token::Token>,
+    pub trailing_sep_allowed: bool,
+}
+
+impl SeqSep {
+    pub fn trailing_allowed(t: token::Token) -> SeqSep {
+        SeqSep {
+            sep: Some(t),
+            trailing_sep_allowed: true,
+        }
+    }
+
+    pub fn none() -> SeqSep {
+        SeqSep {
+            sep: None,
+            trailing_sep_allowed: false,
+        }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
-    use syntax_pos::{self, Span, BytePos, Pos, NO_EXPANSION};
-    use codemap::{respan, Spanned};
+    use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION};
     use ast::{self, Ident, PatKind};
-    use rustc_target::spec::abi::Abi;
     use attr::first_attr_value_str_by_name;
     use parse;
-    use parse::parser::Parser;
     use print::pprust::item_to_string;
-    use ptr::P;
     use tokenstream::{self, TokenTree};
-    use util::parser_testing::{string_to_stream, string_to_parser};
-    use util::parser_testing::{string_to_expr, string_to_item, string_to_stmt};
-    use util::ThinVec;
+    use util::parser_testing::string_to_stream;
+    use util::parser_testing::{string_to_expr, string_to_item};
     use with_globals;
 
     // produce a syntax_pos::span
@@ -696,42 +714,6 @@ mod tests {
         Span::new(BytePos(a), BytePos(b), NO_EXPANSION)
     }
 
-    fn str2seg(s: &str, lo: u32, hi: u32) -> ast::PathSegment {
-        ast::PathSegment::from_ident(Ident::new(Symbol::intern(s), sp(lo, hi)))
-    }
-
-    #[test] fn path_exprs_1() {
-        with_globals(|| {
-            assert!(string_to_expr("a".to_string()) ==
-                    P(ast::Expr{
-                        id: ast::DUMMY_NODE_ID,
-                        node: ast::ExprKind::Path(None, ast::Path {
-                            span: sp(0, 1),
-                            segments: vec![str2seg("a", 0, 1)],
-                        }),
-                        span: sp(0, 1),
-                        attrs: ThinVec::new(),
-                    }))
-        })
-    }
-
-    #[test] fn path_exprs_2 () {
-        with_globals(|| {
-            assert!(string_to_expr("::a::b".to_string()) ==
-                    P(ast::Expr {
-                        id: ast::DUMMY_NODE_ID,
-                        node: ast::ExprKind::Path(None, ast::Path {
-                            span: sp(0, 6),
-                            segments: vec![ast::PathSegment::crate_root(sp(0, 0)),
-                                        str2seg("a", 2, 3),
-                                        str2seg("b", 5, 6)]
-                        }),
-                        span: sp(0, 6),
-                        attrs: ThinVec::new(),
-                    }))
-        })
-    }
-
     #[should_panic]
     #[test] fn bad_path_expr_1() {
         with_globals(|| {
@@ -832,143 +814,6 @@ mod tests {
         })
     }
 
-    #[test] fn ret_expr() {
-        with_globals(|| {
-            assert!(string_to_expr("return d".to_string()) ==
-                    P(ast::Expr{
-                        id: ast::DUMMY_NODE_ID,
-                        node:ast::ExprKind::Ret(Some(P(ast::Expr{
-                            id: ast::DUMMY_NODE_ID,
-                            node:ast::ExprKind::Path(None, ast::Path{
-                                span: sp(7, 8),
-                                segments: vec![str2seg("d", 7, 8)],
-                            }),
-                            span:sp(7,8),
-                            attrs: ThinVec::new(),
-                        }))),
-                        span:sp(0,8),
-                        attrs: ThinVec::new(),
-                    }))
-        })
-    }
-
-    #[test] fn parse_stmt_1 () {
-        with_globals(|| {
-            assert!(string_to_stmt("b;".to_string()) ==
-                    Some(ast::Stmt {
-                        node: ast::StmtKind::Expr(P(ast::Expr {
-                            id: ast::DUMMY_NODE_ID,
-                            node: ast::ExprKind::Path(None, ast::Path {
-                                span:sp(0,1),
-                                segments: vec![str2seg("b", 0, 1)],
-                                }),
-                            span: sp(0,1),
-                            attrs: ThinVec::new()})),
-                        id: ast::DUMMY_NODE_ID,
-                        span: sp(0,1)}))
-        })
-    }
-
-    fn parser_done(p: Parser){
-        assert_eq!(p.token.clone(), token::Eof);
-    }
-
-    #[test] fn parse_ident_pat () {
-        with_globals(|| {
-            let sess = ParseSess::new(FilePathMapping::empty());
-            let mut parser = string_to_parser(&sess, "b".to_string());
-            assert!(panictry!(parser.parse_pat())
-                    == P(ast::Pat{
-                    id: ast::DUMMY_NODE_ID,
-                    node: PatKind::Ident(ast::BindingMode::ByValue(ast::Mutability::Immutable),
-                                         Ident::new(Symbol::intern("b"), sp(0, 1)),
-                                         None),
-                    span: sp(0,1)}));
-            parser_done(parser);
-        })
-    }
-
-    // check the contents of the tt manually:
-    #[test] fn parse_fundecl () {
-        with_globals(|| {
-            // this test depends on the intern order of "fn" and "i32"
-            let item = string_to_item("fn a (b : i32) { b; }".to_string()).map(|m| {
-                m.map(|mut m| {
-                    m.tokens = None;
-                    m
-                })
-            });
-            assert_eq!(item,
-                    Some(
-                        P(ast::Item{ident:Ident::from_str("a"),
-                                attrs:Vec::new(),
-                                id: ast::DUMMY_NODE_ID,
-                                tokens: None,
-                                node: ast::ItemKind::Fn(P(ast::FnDecl {
-                                    inputs: vec![ast::Arg{
-                                        ty: P(ast::Ty{id: ast::DUMMY_NODE_ID,
-                                                    node: ast::TyKind::Path(None, ast::Path{
-                                            span:sp(10,13),
-                                            segments: vec![str2seg("i32", 10, 13)],
-                                            }),
-                                            span:sp(10,13)
-                                        }),
-                                        pat: P(ast::Pat {
-                                            id: ast::DUMMY_NODE_ID,
-                                            node: PatKind::Ident(
-                                                ast::BindingMode::ByValue(
-                                                    ast::Mutability::Immutable),
-                                                Ident::new(Symbol::intern("b"), sp(6, 7)),
-                                                None
-                                            ),
-                                            span: sp(6,7)
-                                        }),
-                                            id: ast::DUMMY_NODE_ID
-                                        }],
-                                    output: ast::FunctionRetTy::Default(sp(15, 15)),
-                                    variadic: false
-                                }),
-                                        ast::FnHeader {
-                                            unsafety: ast::Unsafety::Normal,
-                                            asyncness: ast::IsAsync::NotAsync,
-                                            constness: Spanned {
-                                                span: sp(0,2),
-                                                node: ast::Constness::NotConst,
-                                            },
-                                            abi: Abi::Rust,
-                                        },
-                                        ast::Generics{
-                                            params: Vec::new(),
-                                            where_clause: ast::WhereClause {
-                                                id: ast::DUMMY_NODE_ID,
-                                                predicates: Vec::new(),
-                                                span: syntax_pos::DUMMY_SP,
-                                            },
-                                            span: syntax_pos::DUMMY_SP,
-                                        },
-                                        P(ast::Block {
-                                            stmts: vec![ast::Stmt {
-                                                node: ast::StmtKind::Semi(P(ast::Expr{
-                                                    id: ast::DUMMY_NODE_ID,
-                                                    node: ast::ExprKind::Path(None,
-                                                        ast::Path{
-                                                            span:sp(17,18),
-                                                            segments: vec![str2seg("b", 17, 18)],
-                                                        }),
-                                                    span: sp(17,18),
-                                                    attrs: ThinVec::new()})),
-                                                id: ast::DUMMY_NODE_ID,
-                                                span: sp(17,19)}],
-                                            id: ast::DUMMY_NODE_ID,
-                                            rules: ast::BlockCheckMode::Default, // no idea
-                                            span: sp(15,21),
-                                            recovered: false,
-                                        })),
-                                vis: respan(sp(0, 0), ast::VisibilityKind::Inherited),
-                                span: sp(0,21)})));
-        })
-    }
-
     #[test] fn parse_use() {
         with_globals(|| {
             let use_s = "use foo::bar::baz;";
@@ -1133,26 +978,3 @@ mod tests {
         });
     }
 }
-
-/// `SeqSep` : a sequence separator (token)
-/// and whether a trailing separator is allowed.
-pub struct SeqSep {
-    pub sep: Option<token::Token>,
-    pub trailing_sep_allowed: bool,
-}
-
-impl SeqSep {
-    pub fn trailing_allowed(t: token::Token) -> SeqSep {
-        SeqSep {
-            sep: Some(t),
-            trailing_sep_allowed: true,
-        }
-    }
-
-    pub fn none() -> SeqSep {
-        SeqSep {
-            sep: None,
-            trailing_sep_allowed: false,
-        }
-    }
-}
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a1b78a23b8f..62bb5fbd04f 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -95,13 +95,13 @@ pub enum PathStyle {
     Mod,
 }
 
-#[derive(Clone, Copy, Debug, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Debug)]
 enum SemiColonMode {
     Break,
     Ignore,
 }
 
-#[derive(Clone, Copy, Debug, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Debug)]
 enum BlockMode {
     Break,
     Ignore,
@@ -376,7 +376,7 @@ impl TokenCursor {
     }
 }
 
-#[derive(PartialEq, Eq, Clone)]
+#[derive(Clone, PartialEq)]
 crate enum TokenType {
     Token(token::Token),
     Keyword(keywords::Keyword),
@@ -522,7 +522,7 @@ fn dummy_arg(span: Span) -> Arg {
     Arg { ty: P(ty), pat: pat, id: ast::DUMMY_NODE_ID }
 }
 
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+#[derive(Copy, Clone, Debug)]
 enum TokenExpectType {
     Expect,
     NoExpect,
@@ -6999,7 +6999,7 @@ impl<'a> Parser<'a> {
 
         // Verify whether we have encountered a struct or method definition where the user forgot to
         // add the `struct` or `fn` keyword after writing `pub`: `pub S {}`
-        if visibility.node == VisibilityKind::Public &&
+        if visibility.node.is_pub() &&
             self.check_ident() &&
             self.look_ahead(1, |t| *t != token::Not)
         {
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 7ea047d332b..aef3beeccdf 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -30,7 +30,7 @@ use std::{cmp, fmt};
 use std::mem;
 use rustc_data_structures::sync::{Lrc, Lock};
 
-#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
 pub enum BinOpToken {
     Plus,
     Minus,
@@ -45,7 +45,7 @@ pub enum BinOpToken {
 }
 
 /// A delimiter token
-#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
 pub enum DelimToken {
     /// A round parenthesis: `(` or `)`
     Paren,
@@ -67,7 +67,7 @@ impl DelimToken {
     }
 }
 
-#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
 pub enum Lit {
     Byte(ast::Name),
     Char(ast::Name),
@@ -139,7 +139,7 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool {
     ].contains(&ident.name)
 }
 
-#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)]
+#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
 pub enum Token {
     /* Expression-operator symbols. */
     Eq,
@@ -638,7 +638,7 @@ impl Token {
     }
 }
 
-#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash)]
+#[derive(Clone, RustcEncodable, RustcDecodable)]
 /// For interpolation during macro expansion.
 pub enum Nonterminal {
     NtItem(P<ast::Item>),