]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Check paths in visibilities for type parameters
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 18 Apr 2016 21:42:18 +0000 (00:42 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 24 Apr 2016 17:59:44 +0000 (20:59 +0300)
syntax: Merge PathParsingMode::NoTypesAllowed and PathParsingMode::ImportPrefix
syntax: Rename PathParsingMode and its variants to better express their purpose
syntax: Remove obsolete error message about 'self lifetime
syntax: Remove ALLOW_MODULE_PATHS workaround
syntax/resolve: Adjust some error messages
resolve: Compare unhygienic (not renamed) names with keywords::Invalid, invalid identifiers may appear to be valid after renaming

14 files changed:
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/lib.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/quote.rs
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/feature_gate.rs
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/parser.rs
src/test/compile-fail/import-ty-params.rs
src/test/compile-fail/privacy/restricted/ty-params.rs [new file with mode: 0644]
src/test/compile-fail/self_type_keyword.rs
src/test/parse-fail/issue-10412.rs
src/test/parse-fail/lifetime-no-keyword.rs
src/test/parse-fail/lifetime-obsoleted-self.rs [deleted file]

index f92673b781e322010c60719e1f78a9095587ad90..ed473da19176b3c1378eff1301c705b7f5335ad4 100644 (file)
@@ -112,15 +112,14 @@ fn sanity_check_import(&self, view_path: &hir::ViewPath, id: NodeId) {
             !segment.parameters.bindings().is_empty()
         });
         if found_param {
-            self.session.span_err(path.span,
-                                  "type or lifetime parameter is found in import path");
+            self.session.span_err(path.span, "type or lifetime parameters in import path");
         }
 
         // Checking for special identifiers in path
         // 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.ident.name || first == keywords::SelfValue.ident.name {
+            if first == keywords::Super.name() || first == keywords::SelfValue.name() {
                 self.session.add_lint(
                     lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
                     format!("expected identifier, found keyword `{}`", first)
index bc09cfdb5837c09aa1ea85604c6b85cb0d88be66..293b4de71fac403cb809136d93aaddd00b082149 100644 (file)
@@ -62,7 +62,7 @@
 use syntax::attr::AttrMetaMethods;
 use syntax::codemap::{self, Span, Pos};
 use syntax::errors::DiagnosticBuilder;
-use syntax::parse::token::{self, keywords, special_idents};
+use syntax::parse::token::{self, keywords};
 use syntax::util::lev_distance::find_best_match_for_name;
 
 use rustc::hir::intravisit::{self, FnKind, Visitor};
@@ -1954,7 +1954,7 @@ fn with_self_rib<F>(&mut self, self_def: Def, f: F)
         let mut self_type_rib = Rib::new(NormalRibKind);
 
         // plain insert (no renaming, types are not currently hygienic....)
-        self_type_rib.bindings.insert(keywords::SelfType.ident.name, self_def);
+        self_type_rib.bindings.insert(keywords::SelfType.name(), self_def);
         self.type_ribs.push(self_type_rib);
         f(self);
         if !self.resolved {
@@ -2197,7 +2197,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                         let is_invalid_self_type_name = path.segments.len() > 0 &&
                                                         maybe_qself.is_none() &&
                                                         path.segments[0].identifier.name ==
-                                                        keywords::SelfType.ident.name;
+                                                        keywords::SelfType.name();
                         if is_invalid_self_type_name {
                             resolve_error(self,
                                           ty.span,
@@ -2641,7 +2641,7 @@ fn resolve_identifier(&mut self,
                           namespace: Namespace,
                           record_used: bool)
                           -> Option<LocalDef> {
-        if identifier.name == special_idents::Invalid.name {
+        if identifier.unhygienic_name == keywords::Invalid.name() {
             return Some(LocalDef::from_def(Def::Err));
         }
 
@@ -3073,7 +3073,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
                             });
 
                             if method_scope &&
-                                    &path_name[..] == keywords::SelfValue.ident.name.as_str() {
+                                    &path_name[..] == keywords::SelfValue.name().as_str() {
                                 resolve_error(self,
                                               expr.span,
                                               ResolutionError::SelfNotAvailableInStaticMethod);
index dd6e9a1e4a643fa9bd76708adfa84358a7c7b973..001db0b13ca59f1df980c698b124a5913870ea71 100644 (file)
@@ -1486,7 +1486,7 @@ mod tests {
     use ext::mtwt;
     use fold::Folder;
     use parse;
-    use parse::token;
+    use parse::token::{self, keywords};
     use util::parser_testing::{string_to_parser};
     use util::parser_testing::{string_to_pat, string_to_crate, strs_to_idents};
     use visit;
index 9734b49ba7ce29f653539e0851a3583414c0d86b..ee9a197ce56ccb84cc39167d1c2be5974543d5ff 100644 (file)
@@ -13,7 +13,7 @@
 use ext::base::ExtCtxt;
 use ext::base;
 use ext::build::AstBuilder;
-use parse::parser::{Parser, PathParsingMode};
+use parse::parser::{Parser, PathStyle};
 use parse::token::*;
 use parse::token;
 use ptr::P;
@@ -401,7 +401,7 @@ pub fn parse_meta_item_panic(parser: &mut Parser) -> P<ast::MetaItem> {
     panictry!(parser.parse_meta_item())
 }
 
-pub fn parse_path_panic(parser: &mut Parser, mode: PathParsingMode) -> ast::Path {
+pub fn parse_path_panic(parser: &mut Parser, mode: PathStyle) -> ast::Path {
     panictry!(parser.parse_path(mode))
 }
 
@@ -500,7 +500,7 @@ pub fn expand_quote_path(cx: &mut ExtCtxt,
                         sp: Span,
                         tts: &[TokenTree])
                         -> Box<base::MacResult+'static> {
-    let mode = mk_parser_path(cx, sp, "LifetimeAndTypesWithoutColons");
+    let mode = mk_parser_path(cx, sp, &["PathStyle", "Type"]);
     let expanded = expand_parse_call(cx, sp, "parse_path_panic", vec!(mode), tts);
     base::MacEager::expr(expanded)
 }
@@ -557,8 +557,9 @@ fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> {
     cx.expr_path(cx.path_global(sp, idents))
 }
 
-fn mk_parser_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> {
-    let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("parser"), id_ext(name));
+fn mk_parser_path(cx: &ExtCtxt, sp: Span, names: &[&str]) -> P<ast::Expr> {
+    let mut idents = vec![id_ext("syntax"), id_ext("parse"), id_ext("parser")];
+    idents.extend(names.iter().cloned().map(id_ext));
     cx.expr_path(cx.path_global(sp, idents))
 }
 
index 8b33bbd37000d0af32cc9aac23dee967475a6417..89ecf02ee4c92d6894c806919edba00f3e0951c8 100644 (file)
@@ -85,7 +85,7 @@
 use errors::FatalError;
 use parse::lexer::*; //resolve bug?
 use parse::ParseSess;
-use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
+use parse::parser::{PathStyle, Parser};
 use parse::token::{DocComment, MatchNt, SubstNt};
 use parse::token::{Token, Nonterminal};
 use parse::token;
@@ -546,7 +546,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
             }
         },
         "path" => {
-            token::NtPath(Box::new(panictry!(p.parse_path(LifetimeAndTypesWithoutColons))))
+            token::NtPath(Box::new(panictry!(p.parse_path(PathStyle::Type))))
         },
         "meta" => token::NtMeta(panictry!(p.parse_meta_item())),
         _ => {
index d8352430eb94ed3281fa1b03fa8f8e6018156fe7..c77671d89f88fc865d8ea65873c41eaf540ecdc7 100644 (file)
@@ -1168,7 +1168,19 @@ fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
     fn visit_vis(&mut self, vis: &'v ast::Visibility) {
         let span = match *vis {
             ast::Visibility::Crate(span) => span,
-            ast::Visibility::Restricted { ref path, .. } => path.span,
+            ast::Visibility::Restricted { ref path, .. } => {
+                // Check for type parameters
+                let found_param = path.segments.iter().any(|segment| {
+                    !segment.parameters.types().is_empty() ||
+                    !segment.parameters.lifetimes().is_empty() ||
+                    !segment.parameters.bindings().is_empty()
+                });
+                if found_param {
+                    self.context.span_handler.span_err(path.span, "type or lifetime parameters \
+                                                                   in visibility path");
+                }
+                path.span
+            }
             _ => return,
         };
         self.gate_feature("pub_restricted", span, "`pub(restricted)` syntax is experimental");
index 265a432ae8267536062dc56309e3c96b5d79b6c0..2eda13adcb580f6565584a7ef027907324ed8605 100644 (file)
@@ -13,8 +13,7 @@
 use codemap;
 use errors::{FatalError, Handler, DiagnosticBuilder};
 use ext::tt::transcribe::tt_next_token;
-use parse::token::str_to_ident;
-use parse::token;
+use parse::token::{self, keywords, str_to_ident};
 use str::char_at;
 use rustc_unicode::property::Pattern_White_Space;
 
@@ -1229,14 +1228,9 @@ fn next_token_inner(&mut self) -> token::Token {
                     });
                     let keyword_checking_token = &token::Ident(keyword_checking_ident);
                     let last_bpos = self.last_pos;
-                    if keyword_checking_token.is_keyword(token::keywords::SelfValue) {
-                        self.err_span_(start,
-                                       last_bpos,
-                                       "invalid lifetime name: 'self is no longer a special \
-                                        lifetime");
-                    } else if keyword_checking_token.is_any_keyword() &&
-                       !keyword_checking_token.is_keyword(token::keywords::Static) {
-                        self.err_span_(start, last_bpos, "invalid lifetime name");
+                    if keyword_checking_token.is_any_keyword() &&
+                       !keyword_checking_token.is_keyword(keywords::Static) {
+                        self.err_span_(start, last_bpos, "lifetimes cannot use keyword names");
                     }
 
                     return token::Lifetime(ident);
index 3eec497c3317c6fdddd2ccf7b2013281d1e9c62c..a4d2c5b611064d48e94b3deac78ae41fd390cd85 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-pub use self::PathParsingMode::*;
-
 use abi::{self, Abi};
 use ast::BareFnTy;
 use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
@@ -51,7 +49,7 @@
 use parse::lexer::{Reader, TokenAndSpan};
 use parse::obsolete::{ParserObsoleteMethods, ObsoleteSyntax};
 use parse::token::{self, intern, MatchNt, SubstNt, SpecialVarNt, InternedString};
-use parse::token::{keywords, special_idents, SpecialMacroVar};
+use parse::token::{keywords, SpecialMacroVar};
 use parse::{new_sub_parser_from_file, ParseSess};
 use util::parser::{AssocOp, Fixity};
 use print::pprust;
         const RESTRICTION_STMT_EXPR         = 1 << 0,
         const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1,
         const NO_NONINLINE_MOD  = 1 << 2,
-        const ALLOW_MODULE_PATHS = 1 << 3,
     }
 }
 
 type ItemInfo = (Ident, ItemKind, Option<Vec<Attribute> >);
 
-/// How to parse a path. There are four different kinds of paths, all of which
+/// How to parse a path. There are three different kinds of paths, all of which
 /// are parsed somewhat differently.
 #[derive(Copy, Clone, PartialEq)]
-pub enum PathParsingMode {
-    /// A path with no type parameters; e.g. `foo::bar::Baz`
-    NoTypesAllowed,
-    /// Same as `NoTypesAllowed`, but may end with `::{` or `::*`, which are left unparsed
-    ImportPrefix,
+pub enum PathStyle {
+    /// A path with no type parameters, e.g. `foo::bar::Baz`, used in imports or visibilities.
+    Mod,
     /// A path with a lifetime and type parameters, with no double colons
-    /// before the type parameters; e.g. `foo::bar<'a>::Baz<T>`
-    LifetimeAndTypesWithoutColons,
+    /// before the type parameters; e.g. `foo::bar<'a>::Baz<T>`, used in types.
+    /// Paths using this style can be passed into macros expecting `path` nonterminals.
+    Type,
     /// A path with a lifetime and type parameters with double colons before
-    /// the type parameters; e.g. `foo::bar::<'a>::Baz::<T>`
-    LifetimeAndTypesWithColons,
+    /// the type parameters; e.g. `foo::bar::<'a>::Baz::<T>`, used in expressions or patterns.
+    Expr,
 }
 
 /// How to parse a bound, whether to allow bound modifiers such as `?`.
@@ -292,7 +288,7 @@ fn to_string(&self) -> String {
         match *self {
             TokenType::Token(ref t) => format!("`{}`", Parser::token_to_string(t)),
             TokenType::Operator => "an operator".to_string(),
-            TokenType::Keyword(kw) => format!("`{}`", kw.ident.name),
+            TokenType::Keyword(kw) => format!("`{}`", kw.name()),
         }
     }
 }
@@ -562,7 +558,7 @@ fn interpolated_or_expr_span(&self,
     }
 
     pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
-        self.check_used_keywords();
+        self.check_strict_keywords();
         self.check_reserved_keywords();
         match self.token {
             token::Ident(i) => {
@@ -661,8 +657,8 @@ pub fn expect_keyword(&mut self, kw: keywords::Keyword) -> PResult<'a, ()> {
     }
 
     /// Signal an error if the given string is a strict keyword
-    pub fn check_used_keywords(&mut self) {
-        if self.token.is_used_keyword() {
+    pub fn check_strict_keywords(&mut self) {
+        if self.token.is_strict_keyword() {
             let token_str = self.this_token_to_string();
             let span = self.span;
             self.span_err(span,
@@ -1164,7 +1160,7 @@ pub fn parse_for_in_type(&mut self) -> PResult<'a, TyKind> {
     }
 
     pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> {
-        Ok(TyKind::Path(None, self.parse_path(LifetimeAndTypesWithoutColons)?))
+        Ok(TyKind::Path(None, self.parse_path(PathStyle::Type)?))
     }
 
     /// parse a TyKind::BareFn type:
@@ -1467,11 +1463,11 @@ pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
         } else if self.eat_lt() {
 
             let (qself, path) =
-                 self.parse_qualified_path(LifetimeAndTypesWithoutColons)?;
+                 self.parse_qualified_path(PathStyle::Type)?;
 
             TyKind::Path(Some(qself), path)
         } else if self.is_path_start() {
-            let path = self.parse_path(LifetimeAndTypesWithoutColons)?;
+            let path = self.parse_path(PathStyle::Type)?;
             if self.check(&token::Not) {
                 // MACRO INVOCATION
                 self.bump();
@@ -1556,7 +1552,7 @@ pub fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
         } else {
             debug!("parse_arg_general ident_to_pat");
             let sp = self.last_span;
-            let spanned = Spanned { span: sp, node: special_idents::Invalid };
+            let spanned = Spanned { span: sp, node: keywords::Invalid.ident() };
             P(Pat {
                 id: ast::DUMMY_NODE_ID,
                 node: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable),
@@ -1724,12 +1720,12 @@ pub fn parse_path_segment_ident(&mut self) -> PResult<'a, ast::Ident> {
     ///
     /// `<T as U>::a`
     /// `<T as U>::F::a::<S>`
-    pub fn parse_qualified_path(&mut self, mode: PathParsingMode)
+    pub fn parse_qualified_path(&mut self, mode: PathStyle)
                                 -> PResult<'a, (QSelf, ast::Path)> {
         let span = self.last_span;
         let self_type = self.parse_ty_sum()?;
         let mut path = if self.eat_keyword(keywords::As) {
-            self.parse_path(LifetimeAndTypesWithoutColons)?
+            self.parse_path(PathStyle::Type)?
         } else {
             ast::Path {
                 span: span,
@@ -1747,14 +1743,14 @@ pub fn parse_qualified_path(&mut self, mode: PathParsingMode)
         self.expect(&token::ModSep)?;
 
         let segments = match mode {
-            LifetimeAndTypesWithoutColons => {
+            PathStyle::Type => {
                 self.parse_path_segments_without_colons()?
             }
-            LifetimeAndTypesWithColons => {
+            PathStyle::Expr => {
                 self.parse_path_segments_with_colons()?
             }
-            NoTypesAllowed | ImportPrefix => {
-                self.parse_path_segments_without_types(mode == ImportPrefix)?
+            PathStyle::Mod => {
+                self.parse_path_segments_without_types()?
             }
         };
         path.segments.extend(segments);
@@ -1768,7 +1764,7 @@ pub fn parse_qualified_path(&mut self, mode: PathParsingMode)
     /// mode. The `mode` parameter determines whether lifetimes, types, and/or
     /// bounds are permitted and whether `::` must precede type parameter
     /// groups.
-    pub fn parse_path(&mut self, mode: PathParsingMode) -> PResult<'a, ast::Path> {
+    pub fn parse_path(&mut self, mode: PathStyle) -> PResult<'a, ast::Path> {
         // Check for a whole path...
         let found = match self.token {
             token::Interpolated(token::NtPath(_)) => Some(self.bump_and_get()),
@@ -1785,14 +1781,14 @@ pub fn parse_path(&mut self, mode: PathParsingMode) -> PResult<'a, ast::Path> {
         // identifier followed by an optional lifetime and a set of types.
         // A bound set is a set of type parameter bounds.
         let segments = match mode {
-            LifetimeAndTypesWithoutColons => {
+            PathStyle::Type => {
                 self.parse_path_segments_without_colons()?
             }
-            LifetimeAndTypesWithColons => {
+            PathStyle::Expr => {
                 self.parse_path_segments_with_colons()?
             }
-            NoTypesAllowed | ImportPrefix => {
-                self.parse_path_segments_without_types(mode == ImportPrefix)?
+            PathStyle::Mod => {
+                self.parse_path_segments_without_types()?
             }
         };
 
@@ -1907,10 +1903,9 @@ pub fn parse_path_segments_with_colons(&mut self) -> PResult<'a, Vec<ast::PathSe
         }
     }
 
-
     /// Examples:
     /// - `a::b::c`
-    pub fn parse_path_segments_without_types(&mut self, import_prefix: bool)
+    pub fn parse_path_segments_without_types(&mut self)
                                              -> PResult<'a, Vec<ast::PathSegment>> {
         let mut segments = Vec::new();
         loop {
@@ -1924,7 +1919,7 @@ pub fn parse_path_segments_without_types(&mut self, import_prefix: bool)
             });
 
             // If we do not see a `::` or see `::{`/`::*`, stop.
-            if !self.check(&token::ModSep) || import_prefix && self.is_import_coupler() {
+            if !self.check(&token::ModSep) || self.is_import_coupler() {
                 return Ok(segments);
             } else {
                 self.bump();
@@ -2256,7 +2251,7 @@ fn parse_bottom_expr(&mut self) -> PResult<'a, P<Expr>> {
             _ => {
                 if self.eat_lt() {
                     let (qself, path) =
-                        self.parse_qualified_path(LifetimeAndTypesWithColons)?;
+                        self.parse_qualified_path(PathStyle::Expr)?;
                     hi = path.span.hi;
                     return Ok(self.mk_expr(lo, hi, ExprKind::Path(Some(qself), path), attrs));
                 }
@@ -2338,13 +2333,13 @@ fn parse_bottom_expr(&mut self) -> PResult<'a, P<Expr>> {
                     }
                     hi = self.last_span.hi;
                 } else if self.token.is_keyword(keywords::Let) {
-                    // Catch this syntax error here, instead of in `check_used_keywords`, so
+                    // Catch this syntax error here, instead of in `check_strict_keywords`, so
                     // that we can explicitly mention that let is not to be used as an expression
                     let mut db = self.fatal("expected expression, found statement (`let`)");
                     db.note("variable declaration using `let` is a statement");
                     return Err(db);
                 } else if self.is_path_start() {
-                    let pth = self.parse_path(LifetimeAndTypesWithColons)?;
+                    let pth = self.parse_path(PathStyle::Expr)?;
 
                     // `!`, as an operator, is prefix, so we know this isn't that
                     if self.check(&token::Not) {
@@ -2621,7 +2616,7 @@ fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: BytePos) -> PResult<
                     self.span_err(self.span, &format!("unexpected token: `{}`", actual));
 
                     let dot_pos = self.last_span.hi;
-                    e = self.parse_dot_suffix(special_idents::Invalid,
+                    e = self.parse_dot_suffix(keywords::Invalid.ident(),
                                               mk_sp(dot_pos, dot_pos),
                                               e, lo)?;
                   }
@@ -2698,9 +2693,8 @@ fn parse_unquoted(&mut self) -> PResult<'a, TokenTree> {
             _ => unreachable!()
         };
         // continue by trying to parse the `:ident` after `$name`
-        if self.token == token::Colon && self.look_ahead(1, |t| t.is_ident() &&
-                                                                !t.is_used_keyword() &&
-                                                                !t.is_reserved_keyword()) {
+        if self.token == token::Colon &&
+                self.look_ahead(1, |t| t.is_ident() && !t.is_any_keyword()) {
             self.bump();
             sp = mk_sp(sp.lo, self.span.hi);
             let nt_kind = self.parse_ident()?;
@@ -3578,11 +3572,11 @@ fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> {
             let (qself, path) = if self.eat_lt() {
                 // Parse a qualified path
                 let (qself, path) =
-                    self.parse_qualified_path(LifetimeAndTypesWithColons)?;
+                    self.parse_qualified_path(PathStyle::Expr)?;
                 (Some(qself), path)
             } else {
                 // Parse an unqualified path
-                (None, self.parse_path(LifetimeAndTypesWithColons)?)
+                (None, self.parse_path(PathStyle::Expr)?)
             };
             let hi = self.last_span.hi;
             Ok(self.mk_expr(lo, hi, ExprKind::Path(qself, path), None))
@@ -3676,11 +3670,11 @@ pub fn parse_pat(&mut self) -> PResult<'a, P<Pat>> {
                     let (qself, path) = if self.eat_lt() {
                         // Parse a qualified path
                         let (qself, path) =
-                            self.parse_qualified_path(LifetimeAndTypesWithColons)?;
+                            self.parse_qualified_path(PathStyle::Expr)?;
                         (Some(qself), path)
                     } else {
                         // Parse an unqualified path
-                        (None, self.parse_path(LifetimeAndTypesWithColons)?)
+                        (None, self.parse_path(PathStyle::Expr)?)
                     };
                     match self.token {
                       token::DotDotDot => {
@@ -3943,7 +3937,7 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
             self.bump();
 
             let id = match self.token {
-                token::OpenDelim(_) => token::special_idents::Invalid, // no special identifier
+                token::OpenDelim(_) => keywords::Invalid.ident(), // no special identifier
                 _ => self.parse_ident()?,
             };
 
@@ -3955,7 +3949,7 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
                 _ => {
                     // we only expect an ident if we didn't parse one
                     // above.
-                    let ident_str = if id.name == token::special_idents::Invalid.name {
+                    let ident_str = if id.name == keywords::Invalid.name() {
                         "identifier, "
                     } else {
                         ""
@@ -3981,7 +3975,7 @@ fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option<Stmt>> {
                 MacStmtStyle::NoBraces
             };
 
-            if id.name == token::special_idents::Invalid.name {
+            if id.name == keywords::Invalid.name() {
                 let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }));
                 let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs());
                 spanned(lo, hi, stmt)
@@ -4611,10 +4605,10 @@ pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P<FnDecl>>
 
     fn expect_self_ident(&mut self) -> PResult<'a, ast::Ident> {
         match self.token {
-            token::Ident(id) if id.name == keywords::SelfValue.ident.name => {
+            token::Ident(id) if id.name == keywords::SelfValue.name() => {
                 self.bump();
                 // The hygiene context of `id` needs to be preserved here,
-                // so we can't just return `SelfValue.ident`.
+                // so we can't just return `SelfValue.ident()`.
                 Ok(id)
             },
             _ => {
@@ -4699,7 +4693,7 @@ fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>)
                     self.bump();
                 }
                 // error case, making bogus self ident:
-                SelfKind::Value(keywords::SelfValue.ident)
+                SelfKind::Value(keywords::SelfValue.ident())
             }
             token::Ident(..) => {
                 if self.token.is_keyword(keywords::SelfValue) {
@@ -4974,7 +4968,7 @@ fn parse_impl_method(&mut self, vis: &Visibility)
             if delim != token::Brace {
                 self.expect(&token::Semi)?
             }
-            Ok((token::special_idents::Invalid, vec![], ast::ImplItemKind::Macro(m)))
+            Ok((keywords::Invalid.ident(), vec![], ast::ImplItemKind::Macro(m)))
         } else {
             let (constness, unsafety, abi) = self.parse_fn_front_matter()?;
             let ident = self.parse_ident()?;
@@ -5069,7 +5063,7 @@ fn parse_item_impl(&mut self, unsafety: ast::Unsafety) -> PResult<'a, ItemInfo>
 
             self.expect(&token::OpenDelim(token::Brace))?;
             self.expect(&token::CloseDelim(token::Brace))?;
-            Ok((special_idents::Invalid,
+            Ok((keywords::Invalid.ident(),
              ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None))
         } else {
             if opt_trait.is_some() {
@@ -5085,7 +5079,7 @@ fn parse_item_impl(&mut self, unsafety: ast::Unsafety) -> PResult<'a, ItemInfo>
                 impl_items.push(self.parse_impl_item()?);
             }
 
-            Ok((special_idents::Invalid,
+            Ok((keywords::Invalid.ident(),
              ItemKind::Impl(unsafety, polarity, generics, opt_trait, ty, impl_items),
              Some(attrs)))
         }
@@ -5094,7 +5088,7 @@ fn parse_item_impl(&mut self, unsafety: ast::Unsafety) -> PResult<'a, ItemInfo>
     /// Parse a::B<String,i32>
     fn parse_trait_ref(&mut self) -> PResult<'a, TraitRef> {
         Ok(ast::TraitRef {
-            path: self.parse_path(LifetimeAndTypesWithoutColons)?,
+            path: self.parse_path(PathStyle::Type)?,
             ref_id: ast::DUMMY_NODE_ID,
         })
     }
@@ -5254,8 +5248,7 @@ fn parse_visibility(&mut self, allow_restricted: bool) -> PResult<'a, Visibility
             self.expect(&token::CloseDelim(token::Paren))?;
             Ok(Visibility::Crate(span))
         } else {
-            let path = self.with_res(Restrictions::ALLOW_MODULE_PATHS,
-                                     |this| this.parse_path(NoTypesAllowed))?;
+            let path = self.parse_path(PathStyle::Mod)?;
             self.expect(&token::CloseDelim(token::Paren))?;
             Ok(Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID })
         }
@@ -5263,7 +5256,7 @@ fn parse_visibility(&mut self, allow_restricted: bool) -> PResult<'a, Visibility
 
     /// Parse defaultness: DEFAULT or nothing
     fn parse_defaultness(&mut self) -> PResult<'a, Defaultness> {
-        if self.eat_contextual_keyword(special_idents::Default) {
+        if self.eat_contextual_keyword(keywords::Default.ident()) {
             Ok(Defaultness::Default)
         } else {
             Ok(Defaultness::Final)
@@ -5591,7 +5584,7 @@ fn parse_item_foreign_mod(&mut self,
         };
         Ok(self.mk_item(lo,
                      last_span.hi,
-                     special_idents::Invalid,
+                     keywords::Invalid.ident(),
                      ItemKind::ForeignMod(m),
                      visibility,
                      attrs))
@@ -5730,7 +5723,7 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
             let last_span = self.last_span;
             let item = self.mk_item(lo,
                                     last_span.hi,
-                                    token::special_idents::Invalid,
+                                    keywords::Invalid.ident(),
                                     item_,
                                     visibility,
                                     attrs);
@@ -6021,7 +6014,7 @@ fn parse_macro_use_or_failure(
             let id = if self.token.is_ident() {
                 self.parse_ident()?
             } else {
-                token::special_idents::Invalid // no special identifier
+                keywords::Invalid.ident() // no special identifier
             };
             // eat a matched-delimiter token tree:
             let delim = self.expect_open_delim()?;
@@ -6118,7 +6111,7 @@ fn parse_view_path(&mut self) -> PResult<'a, P<ViewPath>> {
             let items = self.parse_path_list_items()?;
             Ok(P(spanned(lo, self.span.hi, ViewPathList(prefix, items))))
         } else {
-            let prefix = self.parse_path(ImportPrefix)?;
+            let prefix = self.parse_path(PathStyle::Mod)?;
             if self.is_import_coupler() {
                 // `foo::bar::{a, b}` or `foo::bar::*`
                 self.bump();
index 66d4d6d06211da6fec00b0aeff66c7ec3db90d34..7344f31535fba42fabf4850cc312de76c1fa4ccb 100644 (file)
@@ -20,6 +20,6 @@ macro_rules! import {
     ($p: path) => (use $p;);
 }
 
-import! { a::b::c::S<u8> } //~ERROR type or lifetime parameter is found in import path
+import! { a::b::c::S<u8> } //~ERROR type or lifetime parameters in import path
 
 fn main() {}
diff --git a/src/test/compile-fail/privacy/restricted/ty-params.rs b/src/test/compile-fail/privacy/restricted/ty-params.rs
new file mode 100644 (file)
index 0000000..04d8e98
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(pub_restricted)]
+
+macro_rules! m {
+    ($p: path) => (pub($p) struct Z;)
+}
+
+struct S<T>(T);
+m!{ S<u8> } //~ ERROR type or lifetime parameters in visibility path
+
+fn main() {}
index b28f48bb1056e2f6e09588c2280582f7662cb5b7..b9c9d7a389b95dd63ef3375310fd0d454354ceed 100644 (file)
@@ -14,7 +14,7 @@
 //~^ ERROR expected identifier, found keyword `Self`
 
 struct Bar<'Self>;
-//~^ ERROR invalid lifetime name
+//~^ ERROR lifetimes cannot use keyword names
 
 pub fn main() {
     let Self = 5;
index b75e7b12bbdc906949f769a1e89619451312d01f..fc2598d1e9d2fa9a5bcbfedafcf9f9a86519d526 100644 (file)
 // compile-flags: -Z parse-only -Z continue-parse-after-error
 
 
-trait Serializable<'self, T> { //~ ERROR no longer a special lifetime
-    fn serialize(val : &'self T) -> Vec<u8> ; //~ ERROR no longer a special lifetime
-    fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR no longer a special lifetime
+trait Serializable<'self, T> { //~ ERROR lifetimes cannot use keyword names
+    fn serialize(val : &'self T) -> Vec<u8> ; //~ ERROR lifetimes cannot use keyword names
+    fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names
 }
 
-impl<'self> Serializable<str> for &'self str { //~ ERROR no longer a special lifetime
-    //~^ ERROR no longer a special lifetime
-    fn serialize(val : &'self str) -> Vec<u8> { //~ ERROR no longer a special lifetime
+impl<'self> Serializable<str> for &'self str { //~ ERROR lifetimes cannot use keyword names
+    //~^ ERROR lifetimes cannot use keyword names
+    fn serialize(val : &'self str) -> Vec<u8> { //~ ERROR lifetimes cannot use keyword names
         vec!(1)
     }
-    fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR no longer a special lifetime
+    fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR lifetimes cannot use keyword names
         "hi"
     }
 }
index 84b02e6ba096437fedefcff05fad93657bc472d4..9ca81d9918ef32c68255697f9e2a23c81a8ac9bd 100644 (file)
@@ -12,6 +12,7 @@
 
 fn foo<'a>(a: &'a isize) { }
 fn bar(a: &'static isize) { }
-fn baz(a: &'let isize) { } //~ ERROR invalid lifetime name
+fn baz(a: &'let isize) { } //~ ERROR lifetimes cannot use keyword names
+fn zab(a: &'self isize) { } //~ ERROR lifetimes cannot use keyword names
 
 fn main() { }
diff --git a/src/test/parse-fail/lifetime-obsoleted-self.rs b/src/test/parse-fail/lifetime-obsoleted-self.rs
deleted file mode 100644 (file)
index e8b7675..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-flags: -Z parse-only
-
-fn baz(a: &'self isize) { } //~ ERROR invalid lifetime name: 'self is no longer a special lifetime
-
-fn main() { }