about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-04-16 19:48:24 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-04-24 20:59:44 +0300
commit8dbab5121e214a08690eefdaa3ee45bb2d1bbd5e (patch)
treed210176cf841c3da5b57b53ac84805b5d92b653b /src
parente2c821d35ee5cb5211f92480a53b409b2b2c359e (diff)
downloadrust-8dbab5121e214a08690eefdaa3ee45bb2d1bbd5e.tar.gz
rust-8dbab5121e214a08690eefdaa3ee45bb2d1bbd5e.zip
syntax: Don't parse idents with `parse_path`
Lift some restrictions on type parameters in paths
Sanity check import paths for type parameters
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs2
-rw-r--r--src/libsyntax/parse/parser.rs21
2 files changed, 13 insertions, 10 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index effc751c507..f92673b781e 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -120,7 +120,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
         // prevent `self` or `super` at beginning of global path
         if path.global && path.segments.len() > 0 {
             let first = path.segments[0].identifier.name;
-            if first == keywords::Super.to_name() || first == keywords::SelfValue.to_name() {
+            if first == keywords::Super.ident.name || first == keywords::SelfValue.ident.name {
                 self.session.add_lint(
                     lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
                     format!("expected identifier, found keyword `{}`", first)
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 2c82cbcb6c6..3eec497c331 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -583,6 +583,11 @@ impl<'a> Parser<'a> {
         }
     }
 
+    fn parse_ident_into_path(&mut self) -> PResult<'a, ast::Path> {
+        let ident = self.parse_ident()?;
+        Ok(ast::Path::from_ident(self.last_span, ident))
+    }
+
     /// Check if the next token is `tok`, and return `true` if so.
     ///
     /// This method will automatically add `tok` to `expected_tokens` if `tok` is not
@@ -1462,7 +1467,7 @@ impl<'a> Parser<'a> {
         } else if self.eat_lt() {
 
             let (qself, path) =
-                 self.parse_qualified_path(NoTypesAllowed)?;
+                 self.parse_qualified_path(LifetimeAndTypesWithoutColons)?;
 
             TyKind::Path(Some(qself), path)
         } else if self.is_path_start() {
@@ -3573,7 +3578,7 @@ impl<'a> Parser<'a> {
             let (qself, path) = if self.eat_lt() {
                 // Parse a qualified path
                 let (qself, path) =
-                    self.parse_qualified_path(NoTypesAllowed)?;
+                    self.parse_qualified_path(LifetimeAndTypesWithColons)?;
                 (Some(qself), path)
             } else {
                 // Parse an unqualified path
@@ -3651,9 +3656,7 @@ impl<'a> Parser<'a> {
                     // Plain idents have some extra abilities here compared to general paths
                     if self.look_ahead(1, |t| *t == token::Not) {
                         // Parse macro invocation
-                        let ident = self.parse_ident()?;
-                        let ident_span = self.last_span;
-                        let path = ast::Path::from_ident(ident_span, ident);
+                        let path = self.parse_ident_into_path()?;
                         self.bump();
                         let delim = self.expect_open_delim()?;
                         let tts = self.parse_seq_to_end(
@@ -3673,7 +3676,7 @@ impl<'a> Parser<'a> {
                     let (qself, path) = if self.eat_lt() {
                         // Parse a qualified path
                         let (qself, path) =
-                            self.parse_qualified_path(NoTypesAllowed)?;
+                            self.parse_qualified_path(LifetimeAndTypesWithColons)?;
                         (Some(qself), path)
                     } else {
                         // Parse an unqualified path
@@ -3936,7 +3939,7 @@ impl<'a> Parser<'a> {
 
             // Potential trouble: if we allow macros with paths instead of
             // idents, we'd need to look ahead past the whole path here...
-            let pth = self.parse_path(NoTypesAllowed)?;
+            let pth = self.parse_ident_into_path()?;
             self.bump();
 
             let id = match self.token {
@@ -4956,7 +4959,7 @@ impl<'a> Parser<'a> {
             self.complain_if_pub_macro(&vis, last_span);
 
             let lo = self.span.lo;
-            let pth = self.parse_path(NoTypesAllowed)?;
+            let pth = self.parse_ident_into_path()?;
             self.expect(&token::Not)?;
 
             // eat a matched-delimiter token tree:
@@ -6009,7 +6012,7 @@ impl<'a> Parser<'a> {
             let mac_lo = self.span.lo;
 
             // item macro.
-            let pth = self.parse_path(NoTypesAllowed)?;
+            let pth = self.parse_ident_into_path()?;
             self.expect(&token::Not)?;
 
             // a 'special' identifier (like what `macro_rules!` uses)