From 08f8faedd0e30f45762afbb8d4873f7041e7462c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 2 Dec 2018 03:35:55 +0300 Subject: syntax: Rename some keywords `CrateRoot` -> `PathRoot`, `::` doesn't necessarily mean crate root now `SelfValue` -> `SelfLower`, `SelfType` -> `SelfUpper`, both `self` and `Self` can be used in type and value namespaces now --- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/expand.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cacec867cf1..63e9744d770 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -625,7 +625,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_path(self.path_ident(span, id)) } fn expr_self(&self, span: Span) -> P { - self.expr_ident(span, keywords::SelfValue.ident()) + self.expr_ident(span, keywords::SelfLower.ident()) } fn expr_binary(&self, sp: Span, op: ast::BinOpKind, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 68a96293891..67f3dc1bb52 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -204,7 +204,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat { path_str.push_str("::"); } - if segment.ident.name != keywords::CrateRoot.name() && + if segment.ident.name != keywords::PathRoot.name() && segment.ident.name != keywords::DollarCrate.name() { path_str.push_str(&segment.ident.as_str()) -- cgit 1.4.1-3-g733a5 From d415844f5e82944dc1907ff4b66f9f74fcbaf6ff Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 2 Dec 2018 03:59:25 +0300 Subject: syntax: Remove `#[non_exhaustive]` from `Edition` `Edition` is not a public API, we want users to break when a new edition is added --- src/librustc/ich/impls_syntax.rs | 12 ++++-------- src/librustc/ty/context.rs | 6 ------ src/libsyntax/ext/tt/quoted.rs | 1 - src/libsyntax_pos/edition.rs | 1 - src/libsyntax_pos/hygiene.rs | 4 ++-- 5 files changed, 6 insertions(+), 18 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index b629fb820b3..b9ed0fcd4f3 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -134,14 +134,10 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability { const_stability }); -impl<'a> HashStable> -for ::syntax::edition::Edition { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - } -} +impl_stable_hash_for!(enum ::syntax::edition::Edition { + Edition2015, + Edition2018, +}); impl<'a> HashStable> for ::syntax::attr::StabilityLevel { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 7862a72433a..f0411924131 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1493,12 +1493,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { BorrowckMode::Ast => match self.sess.edition() { Edition::Edition2015 => BorrowckMode::Ast, Edition::Edition2018 => BorrowckMode::Migrate, - - // For now, future editions mean Migrate. (But it - // would make a lot of sense for it to be changed to - // `BorrowckMode::Mir`, depending on how we plan to - // time the forcing of full migration to NLL.) - _ => BorrowckMode::Migrate, }, } } diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index edc431be369..a7415e845ca 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -444,7 +444,6 @@ where macro_node_id, ), Edition::Edition2018 => parse_sep_and_kleene_op_2018(input, span, sess, features, attrs), - _ => unimplemented!(), } } diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 5819cd7f480..d57078ce914 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -13,7 +13,6 @@ use std::str::FromStr; /// The edition of the compiler (RFC 2052) #[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] -#[non_exhaustive] pub enum Edition { // editions must be kept in order, oldest to newest diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index bc52a3e1c7c..074687fc726 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -17,7 +17,7 @@ use GLOBALS; use Span; -use edition::Edition; +use edition::{Edition, DEFAULT_EDITION}; use symbol::Symbol; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -217,7 +217,7 @@ impl HygieneData { opaque_and_semitransparent: SyntaxContext(0), }], markings: FxHashMap::default(), - default_edition: Edition::Edition2015, + default_edition: DEFAULT_EDITION, } } -- cgit 1.4.1-3-g733a5 From d08f7dcdca861f46bedf8a37af135a7a46633540 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 2 Dec 2018 15:15:42 +0300 Subject: Address review comments --- src/libsyntax/ast.rs | 13 +------------ src/libsyntax/ext/build.rs | 16 +++++++--------- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax_pos/symbol.rs | 8 ++++---- 4 files changed, 14 insertions(+), 27 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b681ed454e2..87225711871 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -105,17 +105,6 @@ impl Path { } } - // Make a "crate root" segment for this path unless it already has it - // or starts with something like `self`/`super`/`$crate`/etc. - pub fn make_root(&self) -> Option { - if let Some(ident) = self.segments.get(0).map(|seg| seg.ident) { - if ident.is_path_segment_keyword() { - return None; - } - } - Some(PathSegment::crate_root(self.span.shrink_to_lo())) - } - pub fn is_global(&self) -> bool { !self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name() } @@ -144,7 +133,7 @@ impl PathSegment { pub fn from_ident(ident: Ident) -> Self { PathSegment { ident, id: DUMMY_NODE_ID, args: None } } - pub fn crate_root(span: Span) -> Self { + pub fn path_root(span: Span) -> Self { PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span)) } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 63e9744d770..5770f6bb8a2 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -318,9 +318,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { args: Vec, bindings: Vec ) -> ast::Path { + assert!(!idents.is_empty()); + let add_root = global && !idents[0].is_path_segment_keyword(); + let mut segments = Vec::with_capacity(idents.len() + add_root as usize); + if add_root { + segments.push(ast::PathSegment::path_root(span)); + } let last_ident = idents.pop().unwrap(); - let mut segments: Vec = vec![]; - segments.extend(idents.into_iter().map(|ident| { ast::PathSegment::from_ident(ident.with_span_pos(span)) })); @@ -334,13 +338,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, args, }); - let mut path = ast::Path { span, segments }; - if global { - if let Some(seg) = path.make_root() { - path.segments.insert(0, seg); - } - } - path + ast::Path { span, segments } } /// Constructs a qualified path. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 56d42e6e964..8165c0e44c4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2082,7 +2082,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); let mod_sep_ctxt = self.span.ctxt(); if self.eat(&token::ModSep) { - segments.push(PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); + segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); } self.parse_path_segments(&mut segments, style, enable_warning)?; @@ -7685,7 +7685,7 @@ impl<'a> Parser<'a> { let mod_sep_ctxt = self.span.ctxt(); if self.eat(&token::ModSep) { prefix.segments.push( - PathSegment::crate_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)) + PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)) ); } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 0b8ef60f363..4f2eb74c072 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -353,7 +353,7 @@ declare_keywords! { (2, DollarCrate, "$crate") (3, Underscore, "_") - // Keywords used in the language. + // Keywords that are used in stable Rust. (4, As, "as") (5, Box, "box") (6, Break, "break") @@ -391,7 +391,7 @@ declare_keywords! { (38, Where, "where") (39, While, "while") - // Keywords reserved for future use. + // Keywords that are used in unstable Rust or reserved for future use. (40, Abstract, "abstract") (41, Become, "become") (42, Do, "do") @@ -404,10 +404,10 @@ declare_keywords! { (49, Virtual, "virtual") (50, Yield, "yield") - // Edition-specific keywords used in the language. + // Edition-specific keywords that are used in stable Rust. (51, Dyn, "dyn") // >= 2018 Edition only - // Edition-specific keywords reserved for future use. + // Edition-specific keywords that are used in unstable Rust or reserved for future use. (52, Async, "async") // >= 2018 Edition only (53, Try, "try") // >= 2018 Edition only -- cgit 1.4.1-3-g733a5