From 546c052d225d41cd31f610e87a20f15cd0fa8e3c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Apr 2016 04:12:02 +0300 Subject: syntax: Get rid of token::IdentStyle --- src/libsyntax/parse/lexer/mod.rs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/libsyntax/parse/lexer') diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index a5cb5c7117e..265a432ae82 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1039,11 +1039,7 @@ impl<'a> StringReader<'a> { token::Underscore } else { // FIXME: perform NFKC normalization here. (Issue #2253) - if self.curr_is(':') && self.nextch_is(':') { - token::Ident(str_to_ident(string), token::ModName) - } else { - token::Ident(str_to_ident(string), token::Plain) - } + token::Ident(str_to_ident(string)) } }); } @@ -1231,8 +1227,7 @@ impl<'a> StringReader<'a> { let keyword_checking_ident = self.with_str_from(start, |lifetime_name| { str_to_ident(lifetime_name) }); - let keyword_checking_token = &token::Ident(keyword_checking_ident, - token::Plain); + 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, @@ -1687,7 +1682,7 @@ mod tests { assert_eq!(string_reader.next_token().tok, token::Whitespace); let tok1 = string_reader.next_token(); let tok2 = TokenAndSpan { - tok: token::Ident(id, token::Plain), + tok: token::Ident(id), sp: Span { lo: BytePos(21), hi: BytePos(23), @@ -1701,7 +1696,7 @@ mod tests { // read another token: let tok3 = string_reader.next_token(); let tok4 = TokenAndSpan { - tok: token::Ident(str_to_ident("main"), token::Plain), + tok: token::Ident(str_to_ident("main")), sp: Span { lo: BytePos(24), hi: BytePos(28), @@ -1722,8 +1717,8 @@ mod tests { } // make the identifier by looking up the string in the interner - fn mk_ident(id: &str, style: token::IdentStyle) -> token::Token { - token::Ident(str_to_ident(id), style) + fn mk_ident(id: &str) -> token::Token { + token::Ident(str_to_ident(id)) } #[test] @@ -1731,9 +1726,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a b".to_string()), - vec![mk_ident("a", token::Plain), - token::Whitespace, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::Whitespace, mk_ident("b")]); } #[test] @@ -1741,9 +1734,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a::b".to_string()), - vec![mk_ident("a", token::ModName), - token::ModSep, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::ModSep, mk_ident("b")]); } #[test] @@ -1751,10 +1742,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a ::b".to_string()), - vec![mk_ident("a", token::Plain), - token::Whitespace, - token::ModSep, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::Whitespace, token::ModSep, mk_ident("b")]); } #[test] @@ -1762,10 +1750,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a:: b".to_string()), - vec![mk_ident("a", token::ModName), - token::ModSep, - token::Whitespace, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::ModSep, token::Whitespace, mk_ident("b")]); } #[test] -- cgit 1.4.1-3-g733a5 From 6c44bea64435fd3859439a6ecab7758855a13f07 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 19 Apr 2016 00:42:18 +0300 Subject: syntax: Check paths in visibilities for type parameters 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 --- src/librustc_resolve/build_reduced_graph.rs | 5 +- src/librustc_resolve/lib.rs | 10 +- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/ext/quote.rs | 11 +- src/libsyntax/ext/tt/macro_parser.rs | 4 +- src/libsyntax/feature_gate.rs | 14 ++- src/libsyntax/parse/lexer/mod.rs | 14 +-- src/libsyntax/parse/parser.rs | 121 ++++++++++----------- src/test/compile-fail/import-ty-params.rs | 2 +- .../compile-fail/privacy/restricted/ty-params.rs | 20 ++++ src/test/compile-fail/self_type_keyword.rs | 2 +- src/test/parse-fail/issue-10412.rs | 14 +-- src/test/parse-fail/lifetime-no-keyword.rs | 3 +- src/test/parse-fail/lifetime-obsoleted-self.rs | 15 --- 14 files changed, 121 insertions(+), 116 deletions(-) create mode 100644 src/test/compile-fail/privacy/restricted/ty-params.rs delete mode 100644 src/test/parse-fail/lifetime-obsoleted-self.rs (limited to 'src/libsyntax/parse/lexer') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index f92673b781e..ed473da1917 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -112,15 +112,14 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> { !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) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index bc09cfdb583..293b4de71fa 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -62,7 +62,7 @@ use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy}; 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { namespace: Namespace, record_used: bool) -> Option { - 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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); 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); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index dd6e9a1e4a6..001db0b13ca 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 9734b49ba7c..ee9a197ce56 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -13,7 +13,7 @@ use codemap::Span; 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 { 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 { - 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 { cx.expr_path(cx.path_global(sp, idents)) } -fn mk_parser_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { - 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 { + 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)) } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 8b33bbd3700..89ecf02ee4c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -85,7 +85,7 @@ use codemap; 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())), _ => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index d8352430eb9..c77671d89f8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1168,7 +1168,19 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { 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"); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 265a432ae82..2eda13adcb5 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -13,8 +13,7 @@ use codemap::{BytePos, CharPos, CodeMap, Pos, Span}; 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 @@ impl<'a> StringReader<'a> { }); 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); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3eec497c331..a4d2c5b6110 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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::common::SeqSep; 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; @@ -69,26 +67,24 @@ bitflags! { 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 >); -/// 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` - LifetimeAndTypesWithoutColons, + /// before the type parameters; e.g. `foo::bar<'a>::Baz`, 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::` - LifetimeAndTypesWithColons, + /// the type parameters; e.g. `foo::bar::<'a>::Baz::`, used in expressions or patterns. + Expr, } /// How to parse a bound, whether to allow bound modifiers such as `?`. @@ -292,7 +288,7 @@ impl TokenType { 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 @@ impl<'a> Parser<'a> { } 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 @@ impl<'a> Parser<'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 @@ impl<'a> Parser<'a> { } 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 @@ impl<'a> Parser<'a> { } 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 @@ impl<'a> Parser<'a> { } 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 @@ impl<'a> Parser<'a> { /// /// `::a` /// `::F::a::` - 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { /// 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 @@ impl<'a> Parser<'a> { // 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 @@ impl<'a> Parser<'a> { } } - /// 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> { let mut segments = Vec::new(); loop { @@ -1924,7 +1919,7 @@ impl<'a> Parser<'a> { }); // 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 @@ impl<'a> Parser<'a> { _ => { 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 @@ impl<'a> Parser<'a> { } 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { _ => 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { _ => { // 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { /// Parse a::B 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { /// 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 @@ impl<'a> Parser<'a> { }; Ok(self.mk_item(lo, last_span.hi, - special_idents::Invalid, + keywords::Invalid.ident(), ItemKind::ForeignMod(m), visibility, attrs)) @@ -5730,7 +5723,7 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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 @@ impl<'a> Parser<'a> { 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(); diff --git a/src/test/compile-fail/import-ty-params.rs b/src/test/compile-fail/import-ty-params.rs index 66d4d6d0621..7344f31535f 100644 --- a/src/test/compile-fail/import-ty-params.rs +++ b/src/test/compile-fail/import-ty-params.rs @@ -20,6 +20,6 @@ macro_rules! import { ($p: path) => (use $p;); } -import! { a::b::c::S } //~ERROR type or lifetime parameter is found in import path +import! { a::b::c::S } //~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 index 00000000000..04d8e983304 --- /dev/null +++ b/src/test/compile-fail/privacy/restricted/ty-params.rs @@ -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 or the MIT license +// , 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); +m!{ S } //~ ERROR type or lifetime parameters in visibility path + +fn main() {} diff --git a/src/test/compile-fail/self_type_keyword.rs b/src/test/compile-fail/self_type_keyword.rs index b28f48bb105..b9c9d7a389b 100644 --- a/src/test/compile-fail/self_type_keyword.rs +++ b/src/test/compile-fail/self_type_keyword.rs @@ -14,7 +14,7 @@ struct Self; //~^ 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; diff --git a/src/test/parse-fail/issue-10412.rs b/src/test/parse-fail/issue-10412.rs index b75e7b12bbd..fc2598d1e9d 100644 --- a/src/test/parse-fail/issue-10412.rs +++ b/src/test/parse-fail/issue-10412.rs @@ -11,17 +11,17 @@ // 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 ; //~ 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 ; //~ ERROR lifetimes cannot use keyword names + fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names } -impl<'self> Serializable for &'self str { //~ ERROR no longer a special lifetime - //~^ ERROR no longer a special lifetime - fn serialize(val : &'self str) -> Vec { //~ ERROR no longer a special lifetime +impl<'self> Serializable for &'self str { //~ ERROR lifetimes cannot use keyword names + //~^ ERROR lifetimes cannot use keyword names + fn serialize(val : &'self str) -> Vec { //~ 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" } } diff --git a/src/test/parse-fail/lifetime-no-keyword.rs b/src/test/parse-fail/lifetime-no-keyword.rs index 84b02e6ba09..9ca81d9918e 100644 --- a/src/test/parse-fail/lifetime-no-keyword.rs +++ b/src/test/parse-fail/lifetime-no-keyword.rs @@ -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 index e8b76750eb9..00000000000 --- a/src/test/parse-fail/lifetime-obsoleted-self.rs +++ /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 or the MIT license -// , 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() { } -- cgit 1.4.1-3-g733a5