Skip to content

Commit dc457c6

Browse files
committed
syntax: move GLOBALS to attr module
1 parent 9b4823d commit dc457c6

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

src/librustc_expand/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16641664
}
16651665

16661666
let meta = attr::mk_list_item(Ident::with_dummy_span(sym::doc), items);
1667-
*at = attr::Attribute {
1667+
*at = ast::Attribute {
16681668
kind: ast::AttrKind::Normal(AttrItem {
16691669
path: meta.path,
16701670
args: meta.kind.mac_args(meta.span),

src/librustc_interface/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Compiler {
6565

6666
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
6767
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
68-
syntax::with_default_globals(move || {
68+
syntax::attr::with_default_globals(move || {
6969
let cfg = cfgspecs
7070
.into_iter()
7171
.map(|s| {

src/librustc_interface/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn spawn_thread_pool<F: FnOnce() -> R + Send, R: Send>(
146146
crate::callbacks::setup_callbacks();
147147

148148
scoped_thread(cfg, || {
149-
syntax::with_globals(edition, || {
149+
syntax::attr::with_globals(edition, || {
150150
ty::tls::GCX_PTR.set(&Lock::new(0), || {
151151
if let Some(stderr) = stderr {
152152
io::set_panic(Some(box Sink(stderr.clone())));

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::path::PathBuf;
1818
use std::process::{self, Command, Stdio};
1919
use std::str;
2020
use syntax::ast;
21-
use syntax::with_globals;
21+
use syntax::attr::with_globals;
2222
use tempfile::Builder as TempFileBuilder;
2323
use testing;
2424

src/libsyntax/attr/mod.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
33
mod builtin;
44

5-
pub use crate::ast::Attribute;
65
pub use builtin::*;
76
pub use IntType::*;
87
pub use ReprAttr::*;
98
pub use StabilityLevel::*;
109

1110
use crate::ast;
12-
use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Ident, Name, Path, PathSegment};
11+
use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute};
1312
use crate::ast::{Expr, GenericParam, Item, Lit, LitKind, Local, Stmt, StmtKind};
13+
use crate::ast::{Ident, Name, Path, PathSegment};
1414
use crate::ast::{MacArgs, MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
1515
use crate::mut_visit::visit_clobber;
1616
use crate::ptr::P;
1717
use crate::token::{self, Token};
1818
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
19-
use crate::GLOBALS;
2019

20+
use rustc_data_structures::sync::Lock;
21+
use rustc_index::bit_set::GrowableBitSet;
22+
use rustc_span::edition::{Edition, DEFAULT_EDITION};
2123
use rustc_span::source_map::{BytePos, Spanned};
2224
use rustc_span::symbol::{sym, Symbol};
2325
use rustc_span::Span;
@@ -26,6 +28,35 @@ use log::debug;
2628
use std::iter;
2729
use std::ops::DerefMut;
2830

31+
pub struct Globals {
32+
used_attrs: Lock<GrowableBitSet<AttrId>>,
33+
known_attrs: Lock<GrowableBitSet<AttrId>>,
34+
rustc_span_globals: rustc_span::Globals,
35+
}
36+
37+
impl Globals {
38+
fn new(edition: Edition) -> Globals {
39+
Globals {
40+
// We have no idea how many attributes there will be, so just
41+
// initiate the vectors with 0 bits. We'll grow them as necessary.
42+
used_attrs: Lock::new(GrowableBitSet::new_empty()),
43+
known_attrs: Lock::new(GrowableBitSet::new_empty()),
44+
rustc_span_globals: rustc_span::Globals::new(edition),
45+
}
46+
}
47+
}
48+
49+
pub fn with_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
50+
let globals = Globals::new(edition);
51+
GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
52+
}
53+
54+
pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
55+
with_globals(DEFAULT_EDITION, f)
56+
}
57+
58+
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
59+
2960
pub fn mark_used(attr: &Attribute) {
3061
debug!("marking {:?} as used", attr);
3162
GLOBALS.with(|globals| {

src/libsyntax/lib.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
#![feature(unicode_internals)]
1818
#![recursion_limit = "256"]
1919

20-
use ast::AttrId;
21-
use rustc_data_structures::sync::Lock;
22-
use rustc_index::bit_set::GrowableBitSet;
23-
use rustc_span::edition::{Edition, DEFAULT_EDITION};
24-
2520
#[macro_export]
2621
macro_rules! unwrap_or {
2722
($opt:expr, $default:expr) => {
@@ -32,35 +27,6 @@ macro_rules! unwrap_or {
3227
};
3328
}
3429

35-
pub struct Globals {
36-
used_attrs: Lock<GrowableBitSet<AttrId>>,
37-
known_attrs: Lock<GrowableBitSet<AttrId>>,
38-
rustc_span_globals: rustc_span::Globals,
39-
}
40-
41-
impl Globals {
42-
fn new(edition: Edition) -> Globals {
43-
Globals {
44-
// We have no idea how many attributes there will be, so just
45-
// initiate the vectors with 0 bits. We'll grow them as necessary.
46-
used_attrs: Lock::new(GrowableBitSet::new_empty()),
47-
known_attrs: Lock::new(GrowableBitSet::new_empty()),
48-
rustc_span_globals: rustc_span::Globals::new(edition),
49-
}
50-
}
51-
}
52-
53-
pub fn with_globals<R>(edition: Edition, f: impl FnOnce() -> R) -> R {
54-
let globals = Globals::new(edition);
55-
GLOBALS.set(&globals, || rustc_span::GLOBALS.set(&globals.rustc_span_globals, f))
56-
}
57-
58-
pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R {
59-
with_globals(DEFAULT_EDITION, f)
60-
}
61-
62-
scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
63-
6430
pub mod util {
6531
pub mod classify;
6632
pub mod comments;

0 commit comments

Comments
 (0)