diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2019-04-06 00:15:49 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2019-05-21 18:17:05 +0200 |
| commit | a1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d (patch) | |
| tree | 92928e104879c4c6aa37de8717d1c339999f35b1 /src/libsyntax_pos | |
| parent | 50a0defd5a93523067ef239936cc2e0755220904 (diff) | |
| download | rust-a1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d.tar.gz rust-a1f2dceaebd21a6f8a5f9341bf41724bb20e2a7d.zip | |
Move `edition` outside the hygiene lock and avoid accessing it
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/edition.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_pos/hygiene.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 3 |
4 files changed, 15 insertions, 15 deletions
diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 00cd00f2837..20216568426 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -1,6 +1,7 @@ use crate::symbol::{Symbol, sym}; use std::fmt; use std::str::FromStr; +use crate::GLOBALS; /// The edition of the compiler (RFC 2052) #[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] @@ -38,6 +39,10 @@ impl fmt::Display for Edition { } impl Edition { + pub fn from_session() -> Edition { + GLOBALS.with(|globals| globals.edition) + } + pub fn lint_name(&self) -> &'static str { match *self { Edition::Edition2015 => "rust_2015_compatibility", diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 1d9dc26bf60..6e787c08504 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -7,7 +7,7 @@ use crate::GLOBALS; use crate::Span; -use crate::edition::{Edition, DEFAULT_EDITION}; +use crate::edition::Edition; use crate::symbol::{keywords, Symbol}; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -174,7 +174,6 @@ crate struct HygieneData { marks: Vec<MarkData>, syntax_contexts: Vec<SyntaxContextData>, markings: FxHashMap<(SyntaxContext, Mark, Transparency), SyntaxContext>, - default_edition: Edition, } impl HygieneData { @@ -196,7 +195,6 @@ impl HygieneData { dollar_crate_name: keywords::DollarCrate.name(), }], markings: FxHashMap::default(), - default_edition: DEFAULT_EDITION, } } @@ -205,14 +203,6 @@ 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 = FxHashMap::default()); } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 39859f25f97..cb5aaf7eb88 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -26,6 +26,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder}; extern crate serialize as rustc_serialize; // used by deriving pub mod edition; +use edition::Edition; pub mod hygiene; pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind}; @@ -52,14 +53,16 @@ pub struct Globals { symbol_interner: Lock<symbol::Interner>, span_interner: Lock<span_encoding::SpanInterner>, hygiene_data: Lock<hygiene::HygieneData>, + edition: Edition, } impl Globals { - pub fn new() -> Globals { + pub fn new(edition: Edition) -> Globals { Globals { symbol_interner: Lock::new(symbol::Interner::fresh()), span_interner: Lock::new(span_encoding::SpanInterner::default()), hygiene_data: Lock::new(hygiene::HygieneData::new()), + edition, } } } @@ -356,8 +359,9 @@ impl Span { /// 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.edition) + self.ctxt().outer().expn_info().map_or_else(|| { + Edition::from_session() + }, |einfo| einfo.edition) } #[inline] diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index a07c7eb897e..e69a9a1c5cf 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -1276,6 +1276,7 @@ impl Encodable for InternedString { mod tests { use super::*; use crate::Globals; + use crate::edition; #[test] fn interner_tests() { @@ -1300,7 +1301,7 @@ mod tests { #[test] fn without_first_quote_test() { - GLOBALS.set(&Globals::new(), || { + GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || { let i = Ident::from_str("'break"); assert_eq!(i.without_first_quote().name, keywords::Break.name()); }); |
