Skip to content

Commit 74190a5

Browse files
committed
syntax_pos: Remove the duplicate global edition
It was introduced to avoid going through `hygiene_data`, but now it's read only once, when `ParseSess` is created, so going through a lock is ok.
1 parent 1a44773 commit 74190a5

File tree

4 files changed

+6
-36
lines changed

4 files changed

+6
-36
lines changed

src/libsyntax/parse/lexer/tests.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
11
use super::*;
22

3-
use crate::ast::CrateConfig;
43
use crate::symbol::Symbol;
54
use crate::source_map::{SourceMap, FilePathMapping};
6-
use crate::feature_gate::UnstableFeatures;
75
use crate::parse::token;
8-
use crate::diagnostics::plugin::ErrorMap;
96
use crate::with_default_globals;
107
use std::io;
118
use std::path::PathBuf;
12-
use syntax_pos::{BytePos, Span, edition::Edition};
13-
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
14-
use rustc_data_structures::sync::{Lock, Once};
9+
use errors::{Handler, emitter::EmitterWriter};
10+
use syntax_pos::{BytePos, Span};
1511

1612
fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
17-
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
18-
Some(sm.clone()),
19-
false,
20-
false,
21-
false);
22-
ParseSess {
23-
span_diagnostic: errors::Handler::with_emitter(true, None, Box::new(emitter)),
24-
unstable_features: UnstableFeatures::from_environment(),
25-
config: CrateConfig::default(),
26-
included_mod_stack: Lock::new(Vec::new()),
27-
source_map: sm,
28-
missing_fragment_specifiers: Lock::new(FxHashSet::default()),
29-
raw_identifier_spans: Lock::new(Vec::new()),
30-
registered_diagnostics: Lock::new(ErrorMap::new()),
31-
buffered_lints: Lock::new(vec![]),
32-
edition: Edition::from_session(),
33-
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
34-
param_attr_spans: Lock::new(Vec::new()),
35-
let_chains_spans: Lock::new(Vec::new()),
36-
async_closure_spans: Lock::new(Vec::new()),
37-
injected_crate_name: Once::new(),
38-
}
13+
let emitter = EmitterWriter::new(Box::new(io::sink()), Some(sm.clone()), false, false, false);
14+
ParseSess::with_span_handler(Handler::with_emitter(true, None, Box::new(emitter)), sm)
3915
}
4016

4117
// open a string reader for the given string

src/libsyntax/parse/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use errors::{Applicability, FatalError, Level, Handler, ColorConfig, Diagnostic,
1616
use rustc_data_structures::sync::{Lrc, Lock, Once};
1717
use syntax_pos::{Span, SourceFile, FileName, MultiSpan};
1818
use syntax_pos::edition::Edition;
19+
use syntax_pos::hygiene::ExpnId;
1920

2021
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
2122
use std::borrow::Cow;
@@ -86,7 +87,7 @@ impl ParseSess {
8687
included_mod_stack: Lock::new(vec![]),
8788
source_map,
8889
buffered_lints: Lock::new(vec![]),
89-
edition: Edition::from_session(),
90+
edition: ExpnId::root().expn_info().edition,
9091
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
9192
param_attr_spans: Lock::new(Vec::new()),
9293
let_chains_spans: Lock::new(Vec::new()),

src/libsyntax_pos/edition.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::symbol::{Symbol, sym};
22
use std::fmt;
33
use std::str::FromStr;
4-
use crate::GLOBALS;
54

65
/// The edition of the compiler (RFC 2052)
76
#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)]
@@ -39,10 +38,6 @@ impl fmt::Display for Edition {
3938
}
4039

4140
impl Edition {
42-
pub fn from_session() -> Edition {
43-
GLOBALS.with(|globals| globals.edition)
44-
}
45-
4641
pub fn lint_name(&self) -> &'static str {
4742
match *self {
4843
Edition::Edition2015 => "rust_2015_compatibility",

src/libsyntax_pos/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub struct Globals {
4949
symbol_interner: Lock<symbol::Interner>,
5050
span_interner: Lock<span_encoding::SpanInterner>,
5151
hygiene_data: Lock<hygiene::HygieneData>,
52-
edition: Edition,
5352
}
5453

5554
impl Globals {
@@ -58,7 +57,6 @@ impl Globals {
5857
symbol_interner: Lock::new(symbol::Interner::fresh()),
5958
span_interner: Lock::new(span_encoding::SpanInterner::default()),
6059
hygiene_data: Lock::new(hygiene::HygieneData::new(edition)),
61-
edition,
6260
}
6361
}
6462
}

0 commit comments

Comments
 (0)