From ee5b1e15aa689b801bc7b2f7ee6508549a043f56 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 23 Apr 2018 01:44:19 +0300 Subject: Move definition of `Edition` from libsyntax to libsyntax_pos --- src/libsyntax_pos/edition.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++ src/libsyntax_pos/lib.rs | 2 ++ 2 files changed, 84 insertions(+) create mode 100644 src/libsyntax_pos/edition.rs (limited to 'src/libsyntax_pos') diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs new file mode 100644 index 00000000000..c98b54581f3 --- /dev/null +++ b/src/libsyntax_pos/edition.rs @@ -0,0 +1,82 @@ +// Copyright 2018 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. + +use std::fmt; +use std::str::FromStr; + +/// The edition of the compiler (RFC 2052) +#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)] +#[non_exhaustive] +pub enum Edition { + // editions must be kept in order, newest to oldest + + /// The 2015 edition + Edition2015, + /// The 2018 edition + Edition2018, + + // when adding new editions, be sure to update: + // + // - Update the `ALL_EDITIONS` const + // - Update the EDITION_NAME_LIST const + // - add a `rust_####()` function to the session + // - update the enum in Cargo's sources as well +} + +// must be in order from oldest to newest +pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018]; + +pub const EDITION_NAME_LIST: &'static str = "2015|2018"; + +pub const DEFAULT_EDITION: Edition = Edition::Edition2015; + +impl fmt::Display for Edition { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match *self { + Edition::Edition2015 => "2015", + Edition::Edition2018 => "2018", + }; + write!(f, "{}", s) + } +} + +impl Edition { + pub fn lint_name(&self) -> &'static str { + match *self { + Edition::Edition2015 => "rust_2015_compatibility", + Edition::Edition2018 => "rust_2018_compatibility", + } + } + + pub fn feature_name(&self) -> &'static str { + match *self { + Edition::Edition2015 => "rust_2015_preview", + Edition::Edition2018 => "rust_2018_preview", + } + } + + pub fn is_stable(&self) -> bool { + match *self { + Edition::Edition2015 => true, + Edition::Edition2018 => false, + } + } +} + +impl FromStr for Edition { + type Err = (); + fn from_str(s: &str) -> Result { + match s { + "2015" => Ok(Edition::Edition2015), + "2018" => Ok(Edition::Edition2018), + _ => Err(()) + } + } +} diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index d30d3d78ca5..d2e768dda3c 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -20,6 +20,7 @@ #![feature(const_fn)] #![feature(custom_attribute)] +#![feature(non_exhaustive)] #![feature(optin_builtin_traits)] #![allow(unused_attributes)] #![feature(specialization)] @@ -48,6 +49,7 @@ extern crate serialize as rustc_serialize; // used by deriving extern crate unicode_width; +pub mod edition; pub mod hygiene; pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, NameAndSpan, CompilerDesugaringKind}; -- cgit 1.4.1-3-g733a5 From 640884bad0199e80a7701469a3d0eae0977b5998 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 28 Apr 2018 02:08:16 +0300 Subject: Add edition to expansion info --- src/librustc/hir/lowering.rs | 1 + src/librustc/ich/impls_syntax.rs | 10 ++++++++++ src/librustc_allocator/expand.rs | 3 ++- src/librustc_driver/lib.rs | 3 ++- src/libsyntax/ext/derive.rs | 3 ++- src/libsyntax/ext/expand.rs | 7 ++++++- src/libsyntax/std_inject.rs | 3 ++- src/libsyntax/test.rs | 3 ++- src/libsyntax_ext/proc_macro_registrar.rs | 3 ++- src/libsyntax_pos/edition.rs | 2 +- src/libsyntax_pos/hygiene.rs | 13 +++++++++++++ 11 files changed, 43 insertions(+), 8 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 0f4871954d6..45d429612a1 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -593,6 +593,7 @@ impl<'a> LoweringContext<'a> { span: Some(span), allow_internal_unstable: true, allow_internal_unsafe: false, + edition: codemap::hygiene::default_edition(), }, }); span.with_ctxt(SyntaxContext::empty().apply_mark(mark)) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index f56d701b028..3a37c1c18c8 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -131,6 +131,15 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability { rustc_const_unstable }); +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<'a> HashStable> for ::syntax::attr::StabilityLevel { fn hash_stable(&self, @@ -389,6 +398,7 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan { format, allow_internal_unstable, allow_internal_unsafe, + edition, span }); diff --git a/src/librustc_allocator/expand.rs b/src/librustc_allocator/expand.rs index de8814d3d6a..497d5fdcac7 100644 --- a/src/librustc_allocator/expand.rs +++ b/src/librustc_allocator/expand.rs @@ -21,7 +21,7 @@ use syntax::ext::base::ExtCtxt; use syntax::ext::base::Resolver; use syntax::ext::build::AstBuilder; use syntax::ext::expand::ExpansionConfig; -use syntax::ext::hygiene::{Mark, SyntaxContext}; +use syntax::ext::hygiene::{self, Mark, SyntaxContext}; use syntax::fold::{self, Folder}; use syntax::parse::ParseSess; use syntax::ptr::P; @@ -86,6 +86,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { span: None, allow_internal_unstable: true, allow_internal_unsafe: false, + edition: hygiene::default_edition(), }, }); let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 0b4b090f1f0..2f89814032e 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -108,7 +108,7 @@ use syntax::ast; use syntax::codemap::{CodeMap, FileLoader, RealFileLoader}; use syntax::feature_gate::{GatedCfg, UnstableFeatures}; use syntax::parse::{self, PResult}; -use syntax_pos::{DUMMY_SP, MultiSpan, FileName}; +use syntax_pos::{hygiene, DUMMY_SP, MultiSpan, FileName}; #[cfg(test)] mod test; @@ -466,6 +466,7 @@ pub fn run_compiler<'a>(args: &[String], }; let (sopts, cfg) = config::build_session_options_and_crate_config(&matches); + hygiene::set_default_edition(sopts.edition); driver::spawn_thread_pool(sopts, |sopts| { run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest) diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 6bf166dfe95..0b6a7e1c4f4 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -10,7 +10,7 @@ use attr::HasAttrs; use ast; -use codemap::{ExpnInfo, NameAndSpan, ExpnFormat}; +use codemap::{hygiene, ExpnInfo, NameAndSpan, ExpnFormat}; use ext::base::ExtCtxt; use ext::build::AstBuilder; use parse::parser::PathStyle; @@ -65,6 +65,7 @@ pub fn add_derived_markers(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path] span: None, allow_internal_unstable: true, allow_internal_unsafe: false, + edition: hygiene::default_edition(), }, }); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 584b9455a93..1cf0a7077c2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -16,7 +16,7 @@ use config::{is_test_or_bench, StripUnconfigured}; use errors::FatalError; use ext::base::*; use ext::derive::{add_derived_markers, collect_derives}; -use ext::hygiene::{Mark, SyntaxContext}; +use ext::hygiene::{self, Mark, SyntaxContext}; use ext::placeholders::{placeholder, PlaceholderExpander}; use feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err}; use fold; @@ -502,6 +502,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { span: None, allow_internal_unstable: false, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }); @@ -642,6 +643,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { span: def_site_span, allow_internal_unstable, allow_internal_unsafe, + edition: hygiene::default_edition(), }, }); Ok(()) @@ -688,6 +690,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { span: tt_span, allow_internal_unstable, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }); @@ -728,6 +731,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // FIXME probably want to follow macro_rules macros here. allow_internal_unstable: false, allow_internal_unsafe: false, + edition: hygiene::default_edition(), }, }); @@ -802,6 +806,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { span: None, allow_internal_unstable: false, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }; diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 53dc19ba37d..e9cd7adb9c1 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -14,7 +14,7 @@ use std::cell::Cell; use ext::hygiene::{Mark, SyntaxContext}; use symbol::{Symbol, keywords}; use syntax_pos::{DUMMY_SP, Span}; -use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, respan}; +use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan}; use ptr::P; use tokenstream::TokenStream; @@ -30,6 +30,7 @@ fn ignored_span(sp: Span) -> Span { span: None, allow_internal_unstable: true, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }); sp.with_ctxt(SyntaxContext::empty().apply_mark(mark)) diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 1734692f9e7..1dfd48a24c3 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -29,7 +29,7 @@ use entry::{self, EntryPointType}; use ext::base::{ExtCtxt, Resolver}; use ext::build::AstBuilder; use ext::expand::ExpansionConfig; -use ext::hygiene::{Mark, SyntaxContext}; +use ext::hygiene::{self, Mark, SyntaxContext}; use fold::Folder; use feature_gate::Features; use util::move_map::MoveMap; @@ -300,6 +300,7 @@ fn generate_test_harness(sess: &ParseSess, span: None, allow_internal_unstable: true, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }); diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index d684e8b4ffe..3593165023a 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -14,7 +14,7 @@ use errors; use syntax::ast::{self, Ident, NodeId}; use syntax::attr; -use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, respan}; +use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::ext::expand::ExpansionConfig; @@ -369,6 +369,7 @@ fn mk_registrar(cx: &mut ExtCtxt, span: None, allow_internal_unstable: true, allow_internal_unsafe: false, + edition: hygiene::default_edition(), } }); let span = DUMMY_SP.apply_mark(mark); diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index c98b54581f3..18446c10996 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -12,7 +12,7 @@ use std::fmt; use std::str::FromStr; /// The edition of the compiler (RFC 2052) -#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)] +#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug, RustcEncodable, RustcDecodable)] #[non_exhaustive] pub enum Edition { // editions must be kept in order, newest to oldest diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index be031ea98c9..1365ac396ff 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -17,6 +17,7 @@ use GLOBALS; use Span; +use edition::Edition; use symbol::{Ident, Symbol}; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -151,6 +152,7 @@ pub struct HygieneData { syntax_contexts: Vec, markings: HashMap<(SyntaxContext, Mark), SyntaxContext>, gensym_to_ctxt: HashMap, + default_edition: Edition, } impl HygieneData { @@ -168,6 +170,7 @@ impl HygieneData { }], markings: HashMap::new(), gensym_to_ctxt: HashMap::new(), + default_edition: Edition::Edition2015, } } @@ -176,6 +179,14 @@ impl HygieneData { } } +pub fn default_edition() -> Edition { + HygieneData::with(|data| data.default_edition) +} + +pub fn set_default_edition(edition: Edition) { + HygieneData::with(|data| data.default_edition = edition); +} + pub fn clear_markings() { HygieneData::with(|data| data.markings = HashMap::new()); } @@ -443,6 +454,8 @@ pub struct NameAndSpan { /// Whether the macro is allowed to use `unsafe` internally /// even if the user crate has `#![forbid(unsafe_code)]`. pub allow_internal_unsafe: bool, + /// Edition of the crate in which the macro is defined. + pub edition: Edition, /// The span of the macro definition itself. The macro may not /// have a sensible definition span (e.g. something defined /// completely inside libsyntax) in which case this is None. -- cgit 1.4.1-3-g733a5 From f89e3562450b4fddd36b536087d782c934dd6477 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 29 Apr 2018 02:20:46 +0300 Subject: Add two keywords specific to editions 2015 and 2018 respectively --- src/libsyntax/parse/token.rs | 9 +++++++-- src/libsyntax_pos/symbol.rs | 18 +++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a1c056cbb2c..cbafad253b8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -15,13 +15,14 @@ pub use self::Lit::*; pub use self::Token::*; use ast::{self}; +use edition::Edition; use parse::ParseSess; use print::pprust; use ptr::P; use serialize::{Decodable, Decoder, Encodable, Encoder}; use symbol::keywords; use syntax::parse::parse_stream_from_source_str; -use syntax_pos::{self, Span, FileName}; +use syntax_pos::{self, hygiene, Span, FileName}; use tokenstream::{TokenStream, TokenTree}; use tokenstream; @@ -168,7 +169,11 @@ pub fn is_used_keyword(id: ast::Ident) -> bool { /// Returns `true` if the token is a keyword reserved for possible future use. pub fn is_unused_keyword(id: ast::Ident) -> bool { - id.name >= keywords::Abstract.name() && id.name <= keywords::Yield.name() + let edition = || id.span.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(), + |einfo| einfo.callee.edition); + id.name >= keywords::Abstract.name() && id.name <= keywords::Yield.name() || + id.name == keywords::Proc.name() && edition() == Edition::Edition2015 || + id.name == keywords::Async.name() && edition() == Edition::Edition2018 } /// Returns `true` if the token is either a special identifier or a keyword. diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 2258ed12779..b3687d2962c 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -383,16 +383,20 @@ declare_keywords! { (53, Virtual, "virtual") (54, Yield, "yield") + // Edition-specific keywords reserved for future use. + (55, Async, "async") // >= 2018 Edition Only + (56, Proc, "proc") // <= 2015 Edition Only + // Special lifetime names - (55, UnderscoreLifetime, "'_") - (56, StaticLifetime, "'static") + (57, UnderscoreLifetime, "'_") + (58, StaticLifetime, "'static") // Weak keywords, have special meaning only in specific contexts. - (57, Auto, "auto") - (58, Catch, "catch") - (59, Default, "default") - (60, Dyn, "dyn") - (61, Union, "union") + (59, Auto, "auto") + (60, Catch, "catch") + (61, Default, "default") + (62, Dyn, "dyn") + (63, Union, "union") } // If an interner exists, return it. Otherwise, prepare a fresh one. -- cgit 1.4.1-3-g733a5 From c4352ff198e4725393f4f6fbadab7312b30b538c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 13 May 2018 16:14:43 +0300 Subject: Turn some functions from `token.rs` into methods on `Ident` --- src/librustc/hir/print.rs | 4 +-- src/librustc_passes/ast_validation.rs | 6 ++-- src/librustc_resolve/lib.rs | 3 +- src/librustc_resolve/resolve_imports.rs | 7 ++-- src/libsyntax/ast.rs | 3 +- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/token.rs | 57 ++++----------------------------- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax_pos/lib.rs | 6 ++++ src/libsyntax_pos/symbol.rs | 57 ++++++++++++++++++++++++++++++++- 10 files changed, 80 insertions(+), 67 deletions(-) (limited to 'src/libsyntax_pos') diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9cd9e0dce54..940a68e8ce5 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -13,7 +13,7 @@ pub use self::AnnNode::*; use rustc_target::spec::abi::Abi; use syntax::ast; use syntax::codemap::{CodeMap, Spanned}; -use syntax::parse::{token, ParseSess}; +use syntax::parse::ParseSess; use syntax::parse::lexer::comments; use syntax::print::pp::{self, Breaks}; use syntax::print::pp::Breaks::{Consistent, Inconsistent}; @@ -1559,7 +1559,7 @@ impl<'a> State<'a> { } pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> { - if token::is_raw_guess(ast::Ident::with_empty_ctxt(name)) { + if name.to_ident().is_raw_guess() { self.s.word(&format!("r#{}", name))?; } else { self.s.word(&name.as_str())?; diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 4789e2e50ca..4f239a0868e 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -21,7 +21,6 @@ use rustc::session::Session; use syntax::ast::*; use syntax::attr; use syntax::codemap::Spanned; -use syntax::parse::token; use syntax::symbol::keywords; use syntax::visit::{self, Visitor}; use syntax_pos::Span; @@ -40,14 +39,13 @@ impl<'a> AstValidator<'a> { let valid_names = [keywords::UnderscoreLifetime.name(), keywords::StaticLifetime.name(), keywords::Invalid.name()]; - if !valid_names.contains(&ident.name) && - token::is_reserved_ident(ident.without_first_quote()) { + if !valid_names.contains(&ident.name) && ident.without_first_quote().is_reserved() { self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names"); } } fn check_label(&self, ident: Ident) { - if token::is_reserved_ident(ident.without_first_quote()) { + if ident.without_first_quote().is_reserved() { self.err_handler() .span_err(ident.span, &format!("invalid label name `{}`", ident.name)); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 5a5f5ce2e38..e13e6bc6b74 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -58,7 +58,6 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; use syntax::feature_gate::{feature_err, GateIssue}; -use syntax::parse::token; use syntax::ptr::P; use syntax_pos::{Span, DUMMY_SP, MultiSpan}; @@ -3274,7 +3273,7 @@ impl<'a> Resolver<'a> { // `$crate::a::b` module = Some(self.resolve_crate_root(ident.span.ctxt(), true)); continue - } else if i == 1 && !token::is_path_segment_keyword(ident) { + } else if i == 1 && !ident.is_path_segment_keyword() { let prev_name = path[0].name; if prev_name == keywords::Extern.name() || prev_name == keywords::CrateRoot.name() && diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 09c421fba47..16d5d3fa043 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -27,7 +27,6 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet}; use syntax::ast::{Ident, Name, NodeId}; use syntax::ext::base::Determinacy::{self, Determined, Undetermined}; use syntax::ext::hygiene::Mark; -use syntax::parse::token; use syntax::symbol::keywords; use syntax::util::lev_distance::find_best_match_for_name; use syntax_pos::Span; @@ -667,7 +666,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } else { Some(self.resolve_crate_root(source.span.ctxt().modern(), false)) } - } else if is_extern && !token::is_path_segment_keyword(source) { + } else if is_extern && !source.is_path_segment_keyword() { let crate_id = self.resolver.crate_loader.process_use_extern( source.name, @@ -715,8 +714,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } PathResult::Failed(span, msg, true) => { let (mut self_path, mut self_result) = (module_path.clone(), None); - let is_special = |ident| token::is_path_segment_keyword(ident) && - ident.name != keywords::CrateRoot.name(); + let is_special = |ident: Ident| ident.is_path_segment_keyword() && + ident.name != keywords::CrateRoot.name(); if !self_path.is_empty() && !is_special(self_path[0]) && !(self_path.len() > 1 && is_special(self_path[1])) { self_path[0].name = keywords::SelfValue.name(); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2b6635ec783..1817726d6a1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -107,8 +107,7 @@ impl Path { // 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 ::parse::token::is_path_segment_keyword(ident) && - ident.name != keywords::Crate.name() { + if ident.is_path_segment_keyword() && ident.name != keywords::Crate.name() { return None; } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 3e22598043a..7bef9e34d5a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1149,7 +1149,7 @@ impl<'a> StringReader<'a> { return Ok(self.with_str_from(start, |string| { // FIXME: perform NFKC normalization here. (Issue #2253) let ident = self.mk_ident(string); - if is_raw_ident && (token::is_path_segment_keyword(ident) || + if is_raw_ident && (ident.is_path_segment_keyword() || ident.name == keywords::Underscore.name()) { self.fatal_span_(raw_start, self.pos, &format!("`r#{}` is not currently supported.", ident.name) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index cbafad253b8..5575614a4d4 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -15,14 +15,13 @@ pub use self::Lit::*; pub use self::Token::*; use ast::{self}; -use edition::Edition; use parse::ParseSess; use print::pprust; use ptr::P; use serialize::{Decodable, Decoder, Encodable, Encoder}; use symbol::keywords; use syntax::parse::parse_stream_from_source_str; -use syntax_pos::{self, hygiene, Span, FileName}; +use syntax_pos::{self, Span, FileName}; use tokenstream::{TokenStream, TokenTree}; use tokenstream; @@ -139,48 +138,6 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool { ].contains(&ident.name) } -pub fn is_path_segment_keyword(id: ast::Ident) -> bool { - id.name == keywords::Super.name() || - id.name == keywords::SelfValue.name() || - id.name == keywords::SelfType.name() || - id.name == keywords::Extern.name() || - id.name == keywords::Crate.name() || - id.name == keywords::CrateRoot.name() || - id.name == keywords::DollarCrate.name() -} - -// We see this identifier in a normal identifier position, like variable name or a type. -// How was it written originally? Did it use the raw form? Let's try to guess. -pub fn is_raw_guess(ident: ast::Ident) -> bool { - ident.name != keywords::Invalid.name() && - is_reserved_ident(ident) && !is_path_segment_keyword(ident) -} - -// Returns true for reserved identifiers used internally for elided lifetimes, -// unnamed method parameters, crate root module, error recovery etc. -pub fn is_special_ident(id: ast::Ident) -> bool { - id.name <= keywords::Underscore.name() -} - -/// Returns `true` if the token is a keyword used in the language. -pub fn is_used_keyword(id: ast::Ident) -> bool { - id.name >= keywords::As.name() && id.name <= keywords::While.name() -} - -/// Returns `true` if the token is a keyword reserved for possible future use. -pub fn is_unused_keyword(id: ast::Ident) -> bool { - let edition = || id.span.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(), - |einfo| einfo.callee.edition); - id.name >= keywords::Abstract.name() && id.name <= keywords::Yield.name() || - id.name == keywords::Proc.name() && edition() == Edition::Edition2015 || - id.name == keywords::Async.name() && edition() == Edition::Edition2018 -} - -/// Returns `true` if the token is either a special identifier or a keyword. -pub fn is_reserved_ident(id: ast::Ident) -> bool { - is_special_ident(id) || is_used_keyword(id) || is_unused_keyword(id) -} - #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug)] pub enum Token { /* Expression-operator symbols. */ @@ -256,7 +213,7 @@ impl Token { /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary. pub fn from_ast_ident(ident: ast::Ident) -> Token { - Ident(ident, is_raw_guess(ident)) + Ident(ident, ident.is_raw_guess()) } /// Returns `true` if the token starts with '>'. @@ -436,7 +393,7 @@ impl Token { pub fn is_path_segment_keyword(&self) -> bool { match self.ident() { - Some((id, false)) => is_path_segment_keyword(id), + Some((id, false)) => id.is_path_segment_keyword(), _ => false, } } @@ -445,7 +402,7 @@ impl Token { // unnamed method parameters, crate root module, error recovery etc. pub fn is_special_ident(&self) -> bool { match self.ident() { - Some((id, false)) => is_special_ident(id), + Some((id, false)) => id.is_special(), _ => false, } } @@ -453,7 +410,7 @@ impl Token { /// Returns `true` if the token is a keyword used in the language. pub fn is_used_keyword(&self) -> bool { match self.ident() { - Some((id, false)) => is_used_keyword(id), + Some((id, false)) => id.is_used_keyword(), _ => false, } } @@ -461,7 +418,7 @@ impl Token { /// Returns `true` if the token is a keyword reserved for possible future use. pub fn is_unused_keyword(&self) -> bool { match self.ident() { - Some((id, false)) => is_unused_keyword(id), + Some((id, false)) => id.is_unused_keyword(), _ => false, } } @@ -469,7 +426,7 @@ impl Token { /// Returns `true` if the token is either a special identifier or a keyword. pub fn is_reserved_ident(&self) -> bool { match self.ident() { - Some((id, false)) => is_reserved_ident(id), + Some((id, false)) => id.is_reserved(), _ => false, } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a700799cde5..17f83a09c77 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2374,7 +2374,7 @@ impl<'a> State<'a> { } pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> { - if token::is_raw_guess(ident) { + if ident.is_raw_guess() { self.s.word(&format!("r#{}", ident))?; } else { self.s.word(&ident.name.as_str())?; diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index d2e768dda3c..e2656e2236e 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -300,6 +300,12 @@ impl Span { self.ctxt().outer().expn_info().map(|i| i.call_site) } + /// Edition of the crate from which this span came. + pub fn edition(self) -> edition::Edition { + self.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(), + |einfo| einfo.callee.edition) + } + /// Return the source callee. /// /// Returns None if the supplied span has no expansion trace, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index b3687d2962c..35c94457e6e 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -12,6 +12,7 @@ //! allows bidirectional lookup; i.e. given a value, one can easily find the //! type, and vice versa. +use edition::Edition; use hygiene::SyntaxContext; use {Span, DUMMY_SP, GLOBALS}; @@ -318,7 +319,7 @@ macro_rules! declare_keywords {( // NB: leaving holes in the ident table is bad! a different ident will get // interned with the id from the hole, but it will be between the min and max // of the reserved words, and thus tagged as "reserved". -// After modifying this list adjust `is_special_ident`, `is_used_keyword`/`is_unused_keyword`, +// After modifying this list adjust `is_special`, `is_used_keyword`/`is_unused_keyword`, // this should be rarely necessary though if the keywords are kept in alphabetic order. declare_keywords! { // Special reserved identifiers used internally for elided lifetimes, @@ -399,6 +400,60 @@ declare_keywords! { (63, Union, "union") } +impl Symbol { + fn is_unused_keyword_2015(self) -> bool { + self == keywords::Proc.name() + } + + fn is_unused_keyword_2018(self) -> bool { + self == keywords::Async.name() + } +} + +impl Ident { + // Returns true for reserved identifiers used internally for elided lifetimes, + // unnamed method parameters, crate root module, error recovery etc. + pub fn is_special(self) -> bool { + self.name <= keywords::Underscore.name() + } + + /// Returns `true` if the token is a keyword used in the language. + pub fn is_used_keyword(self) -> bool { + self.name >= keywords::As.name() && self.name <= keywords::While.name() + } + + /// Returns `true` if the token is a keyword reserved for possible future use. + pub fn is_unused_keyword(self) -> bool { + // Note: `span.edition()` is relatively expensive, don't call it unless necessary. + self.name >= keywords::Abstract.name() && self.name <= keywords::Yield.name() || + self.name.is_unused_keyword_2015() && self.span.edition() == Edition::Edition2015 || + self.name.is_unused_keyword_2018() && self.span.edition() == Edition::Edition2018 + } + + /// Returns `true` if the token is either a special identifier or a keyword. + pub fn is_reserved(self) -> bool { + self.is_special() || self.is_used_keyword() || self.is_unused_keyword() + } + + /// A keyword or reserved identifier that can be used as a path segment. + pub fn is_path_segment_keyword(self) -> bool { + self.name == keywords::Super.name() || + self.name == keywords::SelfValue.name() || + self.name == keywords::SelfType.name() || + self.name == keywords::Extern.name() || + self.name == keywords::Crate.name() || + self.name == keywords::CrateRoot.name() || + self.name == keywords::DollarCrate.name() + } + + // We see this identifier in a normal identifier position, like variable name or a type. + // How was it written originally? Did it use the raw form? Let's try to guess. + pub fn is_raw_guess(self) -> bool { + self.name != keywords::Invalid.name() && + self.is_reserved() && !self.is_path_segment_keyword() + } +} + // If an interner exists, return it. Otherwise, prepare a fresh one. #[inline] fn with_interner T>(f: F) -> T { -- cgit 1.4.1-3-g733a5 From dae5f05f430455f7d6dfdce6bc5ccf7a10f8b2df Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 13 May 2018 16:35:52 +0300 Subject: Remove the `proc` keyword again --- src/libsyntax_pos/symbol.rs | 20 +++++------- .../run-pass/auxiliary/edition-kw-macro-2015.rs | 27 ---------------- .../run-pass/auxiliary/edition-kw-macro-2018.rs | 27 ---------------- src/test/run-pass/edition-keywords-2015-2015.rs | 26 ---------------- src/test/run-pass/edition-keywords-2015-2018.rs | 26 ---------------- src/test/run-pass/edition-keywords-2018-2015.rs | 26 ---------------- src/test/run-pass/edition-keywords-2018-2018.rs | 26 ---------------- src/test/ui/auxiliary/edition-kw-macro-2015.rs | 27 ---------------- src/test/ui/auxiliary/edition-kw-macro-2018.rs | 27 ---------------- .../ui/edition-keywords-2015-2015-expansion.rs | 10 ++---- .../ui/edition-keywords-2015-2015-expansion.stderr | 10 ------ src/test/ui/edition-keywords-2015-2015-parsing.rs | 17 ---------- .../ui/edition-keywords-2015-2015-parsing.stderr | 36 ++-------------------- .../ui/edition-keywords-2015-2018-expansion.rs | 9 ------ .../ui/edition-keywords-2015-2018-expansion.stderr | 2 +- src/test/ui/edition-keywords-2015-2018-parsing.rs | 17 ---------- .../ui/edition-keywords-2015-2018-parsing.stderr | 36 ++-------------------- .../ui/edition-keywords-2018-2015-expansion.rs | 10 ++---- .../ui/edition-keywords-2018-2015-expansion.stderr | 10 ------ src/test/ui/edition-keywords-2018-2015-parsing.rs | 17 ---------- .../ui/edition-keywords-2018-2015-parsing.stderr | 24 ++++----------- .../ui/edition-keywords-2018-2018-expansion.rs | 9 ------ .../ui/edition-keywords-2018-2018-expansion.stderr | 2 +- src/test/ui/edition-keywords-2018-2018-parsing.rs | 17 ---------- .../ui/edition-keywords-2018-2018-parsing.stderr | 24 ++++----------- 25 files changed, 31 insertions(+), 451 deletions(-) delete mode 100644 src/test/ui/edition-keywords-2015-2015-expansion.stderr delete mode 100644 src/test/ui/edition-keywords-2018-2015-expansion.stderr (limited to 'src/libsyntax_pos') diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 35c94457e6e..a08f9b2e54a 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -386,25 +386,20 @@ declare_keywords! { // Edition-specific keywords reserved for future use. (55, Async, "async") // >= 2018 Edition Only - (56, Proc, "proc") // <= 2015 Edition Only // Special lifetime names - (57, UnderscoreLifetime, "'_") - (58, StaticLifetime, "'static") + (56, UnderscoreLifetime, "'_") + (57, StaticLifetime, "'static") // Weak keywords, have special meaning only in specific contexts. - (59, Auto, "auto") - (60, Catch, "catch") - (61, Default, "default") - (62, Dyn, "dyn") - (63, Union, "union") + (58, Auto, "auto") + (59, Catch, "catch") + (60, Default, "default") + (61, Dyn, "dyn") + (62, Union, "union") } impl Symbol { - fn is_unused_keyword_2015(self) -> bool { - self == keywords::Proc.name() - } - fn is_unused_keyword_2018(self) -> bool { self == keywords::Async.name() } @@ -426,7 +421,6 @@ impl Ident { pub fn is_unused_keyword(self) -> bool { // Note: `span.edition()` is relatively expensive, don't call it unless necessary. self.name >= keywords::Abstract.name() && self.name <= keywords::Yield.name() || - self.name.is_unused_keyword_2015() && self.span.edition() == Edition::Edition2015 || self.name.is_unused_keyword_2018() && self.span.edition() == Edition::Edition2018 } diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs index 1dc0562a9f0..9127c8e350a 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2015.rs @@ -12,7 +12,6 @@ #![feature(raw_identifiers)] -// `async` #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) @@ -37,29 +36,3 @@ macro_rules! consumes_async_raw { macro_rules! passes_ident { ($i: ident) => ($i) } - -// `proc` -#[macro_export] -macro_rules! produces_proc { - () => (pub fn proc() {}) -} - -#[macro_export] -macro_rules! produces_proc_raw { - () => (pub fn r#proc() {}) -} - -#[macro_export] -macro_rules! consumes_proc { - (proc) => (1) -} - -#[macro_export] -macro_rules! consumes_proc_raw { - (r#proc) => (1) -} - -#[macro_export] -macro_rules! passes_ident { - ($i: ident) => ($i) -} diff --git a/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs b/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs index fb018a36231..4fef77d67ea 100644 --- a/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs +++ b/src/test/run-pass/auxiliary/edition-kw-macro-2018.rs @@ -12,7 +12,6 @@ #![feature(raw_identifiers)] -// `async` #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) @@ -37,29 +36,3 @@ macro_rules! consumes_async_raw { macro_rules! passes_ident { ($i: ident) => ($i) } - -// `proc` -#[macro_export] -macro_rules! produces_proc { - () => (pub fn proc() {}) -} - -#[macro_export] -macro_rules! produces_proc_raw { - () => (pub fn r#proc() {}) -} - -#[macro_export] -macro_rules! consumes_proc { - (proc) => (1) -} - -#[macro_export] -macro_rules! consumes_proc_raw { - (r#proc) => (1) -} - -#[macro_export] -macro_rules! passes_ident { - ($i: ident) => ($i) -} diff --git a/src/test/run-pass/edition-keywords-2015-2015.rs b/src/test/run-pass/edition-keywords-2015-2015.rs index b66d35cfc37..41480bb978e 100644 --- a/src/test/run-pass/edition-keywords-2015-2015.rs +++ b/src/test/run-pass/edition-keywords-2015-2015.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2015; -// `async` pub fn check_async() { let mut async = 1; // OK let mut r#async = 1; // OK @@ -41,29 +40,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -pub fn check_proc() { - // let mut proc = 1; // ERROR, reserved - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - // r#proc = consumes_proc!(r#proc); // ERROR, not a match - // r#proc = consumes_proc_raw!(proc); // ERROR, not a match - r#proc = consumes_proc_raw!(r#proc); // OK - - // if passes_ident!(proc) == 1 {} // ERROR, reserved - if passes_ident!(r#proc) == 1 {} // OK - // one_proc::proc(); // ERROR, reserved - // one_proc::r#proc(); // ERROR, unresolved name - // two_proc::proc(); // ERROR, reserved - two_proc::r#proc(); // OK -} - -mod one_proc { - // produces_proc! {} // ERROR, reserved -} -mod two_proc { - produces_proc_raw! {} // OK -} - fn main() {} diff --git a/src/test/run-pass/edition-keywords-2015-2018.rs b/src/test/run-pass/edition-keywords-2015-2018.rs index ae208342772..78835d51063 100644 --- a/src/test/run-pass/edition-keywords-2015-2018.rs +++ b/src/test/run-pass/edition-keywords-2015-2018.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `async` pub fn check_async() { let mut async = 1; // OK let mut r#async = 1; // OK @@ -41,29 +40,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -pub fn check_proc() { - // let mut proc = 1; // ERROR, reserved - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - // r#proc = consumes_proc!(r#proc); // ERROR, not a match - // r#proc = consumes_proc_raw!(proc); // ERROR, not a match - r#proc = consumes_proc_raw!(r#proc); // OK - - // if passes_ident!(proc) == 1 {} // ERROR, reserved - if passes_ident!(r#proc) == 1 {} // OK - // one_proc::proc(); // ERROR, reserved - one_proc::r#proc(); // OK - // two_proc::proc(); // ERROR, reserved - two_proc::r#proc(); // OK -} - -mod one_proc { - produces_proc! {} // OK -} -mod two_proc { - produces_proc_raw! {} // OK -} - fn main() {} diff --git a/src/test/run-pass/edition-keywords-2018-2015.rs b/src/test/run-pass/edition-keywords-2018-2015.rs index b70ccd6b0f4..46d5f222cbb 100644 --- a/src/test/run-pass/edition-keywords-2018-2015.rs +++ b/src/test/run-pass/edition-keywords-2018-2015.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2015; -// `async` pub fn check_async() { // let mut async = 1; // ERROR, reserved let mut r#async = 1; // OK @@ -41,29 +40,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -pub fn check_proc() { - let mut proc = 1; // OK - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - // r#proc = consumes_proc!(r#proc); // ERROR, not a match - // r#proc = consumes_proc_raw!(proc); // ERROR, not a match - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} // OK - if passes_ident!(r#proc) == 1 {} // OK - // one_proc::proc(); // ERROR, unresolved name - // one_proc::r#proc(); // ERROR, unresolved name - two_proc::proc(); // OK - two_proc::r#proc(); // OK -} - -mod one_proc { - // produces_proc! {} // ERROR, reserved -} -mod two_proc { - produces_proc_raw! {} // OK -} - fn main() {} diff --git a/src/test/run-pass/edition-keywords-2018-2018.rs b/src/test/run-pass/edition-keywords-2018-2018.rs index e3da165eb35..06482988937 100644 --- a/src/test/run-pass/edition-keywords-2018-2018.rs +++ b/src/test/run-pass/edition-keywords-2018-2018.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `async` pub fn check_async() { // let mut async = 1; // ERROR, reserved let mut r#async = 1; // OK @@ -41,29 +40,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -pub fn check_proc() { - let mut proc = 1; // OK - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - // r#proc = consumes_proc!(r#proc); // ERROR, not a match - // r#proc = consumes_proc_raw!(proc); // ERROR, not a match - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} // OK - if passes_ident!(r#proc) == 1 {} // OK - one_proc::proc(); // OK - one_proc::r#proc(); // OK - two_proc::proc(); // OK - two_proc::r#proc(); // OK -} - -mod one_proc { - produces_proc! {} // OK -} -mod two_proc { - produces_proc_raw! {} // OK -} - fn main() {} diff --git a/src/test/ui/auxiliary/edition-kw-macro-2015.rs b/src/test/ui/auxiliary/edition-kw-macro-2015.rs index 1dc0562a9f0..9127c8e350a 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2015.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2015.rs @@ -12,7 +12,6 @@ #![feature(raw_identifiers)] -// `async` #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) @@ -37,29 +36,3 @@ macro_rules! consumes_async_raw { macro_rules! passes_ident { ($i: ident) => ($i) } - -// `proc` -#[macro_export] -macro_rules! produces_proc { - () => (pub fn proc() {}) -} - -#[macro_export] -macro_rules! produces_proc_raw { - () => (pub fn r#proc() {}) -} - -#[macro_export] -macro_rules! consumes_proc { - (proc) => (1) -} - -#[macro_export] -macro_rules! consumes_proc_raw { - (r#proc) => (1) -} - -#[macro_export] -macro_rules! passes_ident { - ($i: ident) => ($i) -} diff --git a/src/test/ui/auxiliary/edition-kw-macro-2018.rs b/src/test/ui/auxiliary/edition-kw-macro-2018.rs index fb018a36231..4fef77d67ea 100644 --- a/src/test/ui/auxiliary/edition-kw-macro-2018.rs +++ b/src/test/ui/auxiliary/edition-kw-macro-2018.rs @@ -12,7 +12,6 @@ #![feature(raw_identifiers)] -// `async` #[macro_export] macro_rules! produces_async { () => (pub fn async() {}) @@ -37,29 +36,3 @@ macro_rules! consumes_async_raw { macro_rules! passes_ident { ($i: ident) => ($i) } - -// `proc` -#[macro_export] -macro_rules! produces_proc { - () => (pub fn proc() {}) -} - -#[macro_export] -macro_rules! produces_proc_raw { - () => (pub fn r#proc() {}) -} - -#[macro_export] -macro_rules! consumes_proc { - (proc) => (1) -} - -#[macro_export] -macro_rules! consumes_proc_raw { - (r#proc) => (1) -} - -#[macro_export] -macro_rules! passes_ident { - ($i: ident) => ($i) -} diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.rs b/src/test/ui/edition-keywords-2015-2015-expansion.rs index 13d95e6751e..b8a1994a105 100644 --- a/src/test/ui/edition-keywords-2015-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2015-expansion.rs @@ -10,13 +10,13 @@ // compile-flags: --edition=2015 // aux-build:edition-kw-macro-2015.rs +// compile-pass #![feature(raw_identifiers)] #[macro_use] extern crate edition_kw_macro_2015; -// `async` mod one_async { produces_async! {} // OK } @@ -24,10 +24,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -mod one_proc { - produces_proc! {} // ERROR expected identifier, found reserved keyword `proc` -} -mod two_proc { - produces_proc_raw! {} // OK -} +fn main() {} diff --git a/src/test/ui/edition-keywords-2015-2015-expansion.stderr b/src/test/ui/edition-keywords-2015-2015-expansion.stderr deleted file mode 100644 index dd4a35c1f05..00000000000 --- a/src/test/ui/edition-keywords-2015-2015-expansion.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2015-expansion.rs:29:5 - | -LL | produces_proc! {} // ERROR expected identifier, found reserved keyword `proc` - | ^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword - | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) - -error: aborting due to previous error - diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.rs b/src/test/ui/edition-keywords-2015-2015-parsing.rs index 1f8390796d3..1fb91ca006c 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2015-parsing.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2015; -// `async` pub fn check_async() { let mut async = 1; // OK let mut r#async = 1; // OK @@ -31,19 +30,3 @@ pub fn check_async() { module::async(); // OK module::r#async(); // OK } - -// `proc` -pub fn check_proc() { - let mut proc = 1; //~ ERROR expected identifier, found reserved keyword `proc` - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} //~ ERROR expected expression, found reserved keyword `proc` - if passes_ident!(r#proc) == 1 {} // OK - module::proc(); //~ ERROR expected identifier, found reserved keyword `proc` - module::r#proc(); // OK -} diff --git a/src/test/ui/edition-keywords-2015-2015-parsing.stderr b/src/test/ui/edition-keywords-2015-2015-parsing.stderr index c40de006edc..5b6fd3e1c9c 100644 --- a/src/test/ui/edition-keywords-2015-2015-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2015-parsing.stderr @@ -1,44 +1,14 @@ -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2015-parsing.rs:37:13 - | -LL | let mut proc = 1; //~ ERROR expected identifier, found reserved keyword `proc` - | ^^^^ expected identifier, found reserved keyword - -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2015-parsing.rs:47:13 - | -LL | module::proc(); //~ ERROR expected identifier, found reserved keyword `proc` - | ^^^^ expected identifier, found reserved keyword - error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:25:31 + --> $DIR/edition-keywords-2015-2015-parsing.rs:24:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2015-parsing.rs:26:35 + --> $DIR/edition-keywords-2015-2015-parsing.rs:25:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ -error: no rules expected the token `r#proc` - --> $DIR/edition-keywords-2015-2015-parsing.rs:41:29 - | -LL | r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - | ^^^^^^ - -error: no rules expected the token `proc` - --> $DIR/edition-keywords-2015-2015-parsing.rs:42:33 - | -LL | r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - | ^^^^ - -error: expected expression, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2015-parsing.rs:45:22 - | -LL | if passes_ident!(proc) == 1 {} //~ ERROR expected expression, found reserved keyword `proc` - | ^^^^ expected expression - -error: aborting due to 7 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.rs b/src/test/ui/edition-keywords-2015-2018-expansion.rs index 59117184686..bc14c104c49 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2015-2018-expansion.rs @@ -16,18 +16,9 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `async` mod one_async { produces_async! {} // ERROR expected identifier, found reserved keyword } mod two_async { produces_async_raw! {} // OK } - -// `proc` -mod one_proc { - produces_proc! {} // OK -} -mod two_proc { - produces_proc_raw! {} // OK -} diff --git a/src/test/ui/edition-keywords-2015-2018-expansion.stderr b/src/test/ui/edition-keywords-2015-2018-expansion.stderr index a1716efb537..13c4ee82537 100644 --- a/src/test/ui/edition-keywords-2015-2018-expansion.stderr +++ b/src/test/ui/edition-keywords-2015-2018-expansion.stderr @@ -1,5 +1,5 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2015-2018-expansion.rs:21:5 + --> $DIR/edition-keywords-2015-2018-expansion.rs:20:5 | LL | produces_async! {} // ERROR expected identifier, found reserved keyword | ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.rs b/src/test/ui/edition-keywords-2015-2018-parsing.rs index 6405a94f842..0b680eb16c7 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2015-2018-parsing.rs @@ -16,7 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `async` pub fn check_async() { let mut async = 1; // OK let mut r#async = 1; // OK @@ -31,19 +30,3 @@ pub fn check_async() { module::async(); // OK module::r#async(); // OK } - -// `proc` -pub fn check_proc() { - let mut proc = 1; //~ ERROR expected identifier, found reserved keyword `proc` - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} //~ ERROR expected expression, found reserved keyword `proc` - if passes_ident!(r#proc) == 1 {} // OK - module::proc(); //~ ERROR expected identifier, found reserved keyword `proc` - module::r#proc(); // OK -} diff --git a/src/test/ui/edition-keywords-2015-2018-parsing.stderr b/src/test/ui/edition-keywords-2015-2018-parsing.stderr index 3510f898025..60cfbce3ff0 100644 --- a/src/test/ui/edition-keywords-2015-2018-parsing.stderr +++ b/src/test/ui/edition-keywords-2015-2018-parsing.stderr @@ -1,44 +1,14 @@ -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2018-parsing.rs:37:13 - | -LL | let mut proc = 1; //~ ERROR expected identifier, found reserved keyword `proc` - | ^^^^ expected identifier, found reserved keyword - -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2018-parsing.rs:47:13 - | -LL | module::proc(); //~ ERROR expected identifier, found reserved keyword `proc` - | ^^^^ expected identifier, found reserved keyword - error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:25:31 + --> $DIR/edition-keywords-2015-2018-parsing.rs:24:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2015-2018-parsing.rs:26:35 + --> $DIR/edition-keywords-2015-2018-parsing.rs:25:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ -error: no rules expected the token `r#proc` - --> $DIR/edition-keywords-2015-2018-parsing.rs:41:29 - | -LL | r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - | ^^^^^^ - -error: no rules expected the token `proc` - --> $DIR/edition-keywords-2015-2018-parsing.rs:42:33 - | -LL | r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - | ^^^^ - -error: expected expression, found reserved keyword `proc` - --> $DIR/edition-keywords-2015-2018-parsing.rs:45:22 - | -LL | if passes_ident!(proc) == 1 {} //~ ERROR expected expression, found reserved keyword `proc` - | ^^^^ expected expression - -error: aborting due to 7 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/edition-keywords-2018-2015-expansion.rs b/src/test/ui/edition-keywords-2018-2015-expansion.rs index 04de1018f15..6f85f427eb0 100644 --- a/src/test/ui/edition-keywords-2018-2015-expansion.rs +++ b/src/test/ui/edition-keywords-2018-2015-expansion.rs @@ -10,13 +10,13 @@ // compile-flags: --edition=2018 // aux-build:edition-kw-macro-2015.rs +// compile-pass #![feature(raw_identifiers)] #[macro_use] extern crate edition_kw_macro_2015; -// `async` mod one_async { produces_async! {} // OK } @@ -24,10 +24,4 @@ mod two_async { produces_async_raw! {} // OK } -// `proc` -mod one_proc { - produces_proc! {} // ERROR expected identifier, found reserved keyword -} -mod two_proc { - produces_proc_raw! {} // OK -} +fn main() {} diff --git a/src/test/ui/edition-keywords-2018-2015-expansion.stderr b/src/test/ui/edition-keywords-2018-2015-expansion.stderr deleted file mode 100644 index 320022e526a..00000000000 --- a/src/test/ui/edition-keywords-2018-2015-expansion.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: expected identifier, found reserved keyword `proc` - --> $DIR/edition-keywords-2018-2015-expansion.rs:29:5 - | -LL | produces_proc! {} // ERROR expected identifier, found reserved keyword - | ^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword - | - = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) - -error: aborting due to previous error - diff --git a/src/test/ui/edition-keywords-2018-2015-parsing.rs b/src/test/ui/edition-keywords-2018-2015-parsing.rs index 26a503d642d..29c5ea41f1f 100644 --- a/src/test/ui/edition-keywords-2018-2015-parsing.rs +++ b/src/test/ui/edition-keywords-2018-2015-parsing.rs @@ -16,23 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2015; -// `proc` -pub fn check_proc() { - let mut proc = 1; // OK - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} // OK - if passes_ident!(r#proc) == 1 {} // OK - module::proc(); // OK - module::r#proc(); // OK -} - -// `async` pub fn check_async() { let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async` let mut r#async = 1; // OK diff --git a/src/test/ui/edition-keywords-2018-2015-parsing.stderr b/src/test/ui/edition-keywords-2018-2015-parsing.stderr index d39d5a8a901..0b3ca57bfab 100644 --- a/src/test/ui/edition-keywords-2018-2015-parsing.stderr +++ b/src/test/ui/edition-keywords-2018-2015-parsing.stderr @@ -1,44 +1,32 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:37:13 + --> $DIR/edition-keywords-2018-2015-parsing.rs:20:13 | LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async` | ^^^^^ expected identifier, found reserved keyword error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:47:13 + --> $DIR/edition-keywords-2018-2015-parsing.rs:30:13 | LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async` | ^^^^^ expected identifier, found reserved keyword -error: no rules expected the token `r#proc` - --> $DIR/edition-keywords-2018-2015-parsing.rs:25:29 - | -LL | r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - | ^^^^^^ - -error: no rules expected the token `proc` - --> $DIR/edition-keywords-2018-2015-parsing.rs:26:33 - | -LL | r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - | ^^^^ - error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:41:31 + --> $DIR/edition-keywords-2018-2015-parsing.rs:24:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:42:35 + --> $DIR/edition-keywords-2018-2015-parsing.rs:25:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ error: expected expression, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2015-parsing.rs:45:22 + --> $DIR/edition-keywords-2018-2015-parsing.rs:28:22 | LL | if passes_ident!(async) == 1 {} //~ ERROR expected expression, found reserved keyword `async` | ^^^^^ expected expression -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors diff --git a/src/test/ui/edition-keywords-2018-2018-expansion.rs b/src/test/ui/edition-keywords-2018-2018-expansion.rs index 55732da8bc0..ef7f63e225c 100644 --- a/src/test/ui/edition-keywords-2018-2018-expansion.rs +++ b/src/test/ui/edition-keywords-2018-2018-expansion.rs @@ -16,18 +16,9 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `async` mod one_async { produces_async! {} // ERROR expected identifier, found reserved keyword `async` } mod two_async { produces_async_raw! {} // OK } - -// `proc` -mod one_proc { - produces_proc! {} // OK -} -mod two_proc { - produces_proc_raw! {} // OK -} diff --git a/src/test/ui/edition-keywords-2018-2018-expansion.stderr b/src/test/ui/edition-keywords-2018-2018-expansion.stderr index 236409c9628..cd51030fd28 100644 --- a/src/test/ui/edition-keywords-2018-2018-expansion.stderr +++ b/src/test/ui/edition-keywords-2018-2018-expansion.stderr @@ -1,5 +1,5 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2018-expansion.rs:21:5 + --> $DIR/edition-keywords-2018-2018-expansion.rs:20:5 | LL | produces_async! {} // ERROR expected identifier, found reserved keyword `async` | ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword diff --git a/src/test/ui/edition-keywords-2018-2018-parsing.rs b/src/test/ui/edition-keywords-2018-2018-parsing.rs index 7fc7450d5b2..a94808eb224 100644 --- a/src/test/ui/edition-keywords-2018-2018-parsing.rs +++ b/src/test/ui/edition-keywords-2018-2018-parsing.rs @@ -16,23 +16,6 @@ #[macro_use] extern crate edition_kw_macro_2018; -// `proc` -pub fn check_proc() { - let mut proc = 1; // OK - let mut r#proc = 1; // OK - - r#proc = consumes_proc!(proc); // OK - r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - r#proc = consumes_proc_raw!(r#proc); // OK - - if passes_ident!(proc) == 1 {} // OK - if passes_ident!(r#proc) == 1 {} // OK - module::proc(); // OK - module::r#proc(); // OK -} - -// `async` pub fn check_async() { let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async` let mut r#async = 1; // OK diff --git a/src/test/ui/edition-keywords-2018-2018-parsing.stderr b/src/test/ui/edition-keywords-2018-2018-parsing.stderr index fba1ec6d18a..1b18d8a39be 100644 --- a/src/test/ui/edition-keywords-2018-2018-parsing.stderr +++ b/src/test/ui/edition-keywords-2018-2018-parsing.stderr @@ -1,44 +1,32 @@ error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:37:13 + --> $DIR/edition-keywords-2018-2018-parsing.rs:20:13 | LL | let mut async = 1; //~ ERROR expected identifier, found reserved keyword `async` | ^^^^^ expected identifier, found reserved keyword error: expected identifier, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:47:13 + --> $DIR/edition-keywords-2018-2018-parsing.rs:30:13 | LL | module::async(); //~ ERROR expected identifier, found reserved keyword `async` | ^^^^^ expected identifier, found reserved keyword -error: no rules expected the token `r#proc` - --> $DIR/edition-keywords-2018-2018-parsing.rs:25:29 - | -LL | r#proc = consumes_proc!(r#proc); //~ ERROR no rules expected the token `r#proc` - | ^^^^^^ - -error: no rules expected the token `proc` - --> $DIR/edition-keywords-2018-2018-parsing.rs:26:33 - | -LL | r#proc = consumes_proc_raw!(proc); //~ ERROR no rules expected the token `proc` - | ^^^^ - error: no rules expected the token `r#async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:41:31 + --> $DIR/edition-keywords-2018-2018-parsing.rs:24:31 | LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async` | ^^^^^^^ error: no rules expected the token `async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:42:35 + --> $DIR/edition-keywords-2018-2018-parsing.rs:25:35 | LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ error: expected expression, found reserved keyword `async` - --> $DIR/edition-keywords-2018-2018-parsing.rs:45:22 + --> $DIR/edition-keywords-2018-2018-parsing.rs:28:22 | LL | if passes_ident!(async) == 1 {} //~ ERROR expected expression, found reserved keyword `async` | ^^^^^ expected expression -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors -- cgit 1.4.1-3-g733a5