22
33mod builtin;
44
5- pub use crate :: ast:: Attribute ;
65pub use builtin:: * ;
76pub use IntType :: * ;
87pub use ReprAttr :: * ;
98pub use StabilityLevel :: * ;
109
1110use 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 } ;
1312use crate :: ast:: { Expr , GenericParam , Item , Lit , LitKind , Local , Stmt , StmtKind } ;
13+ use crate :: ast:: { Ident , Name , Path , PathSegment } ;
1414use crate :: ast:: { MacArgs , MacDelimiter , MetaItem , MetaItemKind , NestedMetaItem } ;
1515use crate :: mut_visit:: visit_clobber;
1616use crate :: ptr:: P ;
1717use crate :: token:: { self , Token } ;
1818use 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 } ;
2123use rustc_span:: source_map:: { BytePos , Spanned } ;
2224use rustc_span:: symbol:: { sym, Symbol } ;
2325use rustc_span:: Span ;
@@ -26,6 +28,35 @@ use log::debug;
2628use std:: iter;
2729use 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+
2960pub fn mark_used ( attr : & Attribute ) {
3061 debug ! ( "marking {:?} as used" , attr) ;
3162 GLOBALS . with ( |globals| {
0 commit comments