about summary refs log tree commit diff
path: root/src/libsyntax/lib.rs
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-04-06 00:15:49 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-05-21 18:17:05 +0200
commita1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d (patch)
tree92928e104879c4c6aa37de8717d1c339999f35b1 /src/libsyntax/lib.rs
parent50a0defd5a93523067ef239936cc2e0755220904 (diff)
downloadrust-a1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d.tar.gz
rust-a1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d.zip
Move `edition` outside the hygiene lock and avoid accessing it
Diffstat (limited to 'src/libsyntax/lib.rs')
-rw-r--r--src/libsyntax/lib.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index db10ab7af5a..5eda975bc9e 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -29,6 +29,7 @@ use rustc_data_structures::sync::Lock;
 use rustc_data_structures::bit_set::GrowableBitSet;
 pub use rustc_data_structures::thin_vec::ThinVec;
 use ast::AttrId;
+use syntax_pos::edition::Edition;
 
 // A variant of 'try!' that panics on an Err. This is used as a crutch on the
 // way towards a non-panic!-prone parser. It should be used for fatal parsing
@@ -82,26 +83,32 @@ pub struct Globals {
 }
 
 impl Globals {
-    fn new() -> Globals {
+    fn new(edition: Edition) -> Globals {
         Globals {
             // We have no idea how many attributes their will be, so just
             // initiate the vectors with 0 bits. We'll grow them as necessary.
             used_attrs: Lock::new(GrowableBitSet::new_empty()),
             known_attrs: Lock::new(GrowableBitSet::new_empty()),
-            syntax_pos_globals: syntax_pos::Globals::new(),
+            syntax_pos_globals: syntax_pos::Globals::new(edition),
         }
     }
 }
 
-pub fn with_globals<F, R>(f: F) -> R
+pub fn with_globals<F, R>(edition: Edition, f: F) -> R
     where F: FnOnce() -> R
 {
-    let globals = Globals::new();
+    let globals = Globals::new(edition);
     GLOBALS.set(&globals, || {
         syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
     })
 }
 
+pub fn with_default_globals<F, R>(f: F) -> R
+    where F: FnOnce() -> R
+{
+    with_globals(edition::DEFAULT_EDITION, f)
+}
+
 scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
 
 #[macro_use]