@@ -10,72 +10,30 @@ use crate::ptr::P;
1010use crate :: token:: { self , CommentKind , Token } ;
1111use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndJoint } ;
1212
13- use rustc_data_structures:: sync:: Lock ;
1413use rustc_index:: bit_set:: GrowableBitSet ;
15- use rustc_span:: edition:: { Edition , DEFAULT_EDITION } ;
1614use rustc_span:: source_map:: { BytePos , Spanned } ;
1715use rustc_span:: symbol:: { sym, Ident , Symbol } ;
1816use rustc_span:: Span ;
1917
20- use log:: debug;
2118use std:: iter;
2219use std:: ops:: DerefMut ;
2320
24- // Per-session global variables: this struct is stored in thread-local storage
25- // in such a way that it is accessible without any kind of handle to all
26- // threads within the compilation session, but is not accessible outside the
27- // session.
28- pub struct SessionGlobals {
29- used_attrs : Lock < GrowableBitSet < AttrId > > ,
30- known_attrs : Lock < GrowableBitSet < AttrId > > ,
31- span_session_globals : rustc_span:: SessionGlobals ,
32- }
21+ pub struct MarkedAttrs ( GrowableBitSet < AttrId > ) ;
3322
34- impl SessionGlobals {
35- fn new ( edition : Edition ) -> SessionGlobals {
36- SessionGlobals {
37- // We have no idea how many attributes there will be, so just
38- // initiate the vectors with 0 bits. We'll grow them as necessary.
39- used_attrs : Lock :: new ( GrowableBitSet :: new_empty ( ) ) ,
40- known_attrs : Lock :: new ( GrowableBitSet :: new_empty ( ) ) ,
41- span_session_globals : rustc_span:: SessionGlobals :: new ( edition) ,
42- }
23+ impl MarkedAttrs {
24+ // We have no idea how many attributes there will be, so just
25+ // initiate the vectors with 0 bits. We'll grow them as necessary.
26+ pub fn new ( ) -> Self {
27+ MarkedAttrs ( GrowableBitSet :: new_empty ( ) )
4328 }
44- }
45-
46- pub fn with_session_globals < R > ( edition : Edition , f : impl FnOnce ( ) -> R ) -> R {
47- let ast_session_globals = SessionGlobals :: new ( edition) ;
48- SESSION_GLOBALS . set ( & ast_session_globals, || {
49- rustc_span:: SESSION_GLOBALS . set ( & ast_session_globals. span_session_globals , f)
50- } )
51- }
52-
53- pub fn with_default_session_globals < R > ( f : impl FnOnce ( ) -> R ) -> R {
54- with_session_globals ( DEFAULT_EDITION , f)
55- }
5629
57- scoped_tls:: scoped_thread_local!( pub static SESSION_GLOBALS : SessionGlobals ) ;
58-
59- pub fn mark_used ( attr : & Attribute ) {
60- debug ! ( "marking {:?} as used" , attr) ;
61- SESSION_GLOBALS . with ( |session_globals| {
62- session_globals. used_attrs . lock ( ) . insert ( attr. id ) ;
63- } ) ;
64- }
65-
66- pub fn is_used ( attr : & Attribute ) -> bool {
67- SESSION_GLOBALS . with ( |session_globals| session_globals. used_attrs . lock ( ) . contains ( attr. id ) )
68- }
69-
70- pub fn mark_known ( attr : & Attribute ) {
71- debug ! ( "marking {:?} as known" , attr) ;
72- SESSION_GLOBALS . with ( |session_globals| {
73- session_globals. known_attrs . lock ( ) . insert ( attr. id ) ;
74- } ) ;
75- }
30+ pub fn mark ( & mut self , attr : & Attribute ) {
31+ self . 0 . insert ( attr. id ) ;
32+ }
7633
77- pub fn is_known ( attr : & Attribute ) -> bool {
78- SESSION_GLOBALS . with ( |session_globals| session_globals. known_attrs . lock ( ) . contains ( attr. id ) )
34+ pub fn is_marked ( & self , attr : & Attribute ) -> bool {
35+ self . 0 . contains ( attr. id )
36+ }
7937}
8038
8139pub fn is_known_lint_tool ( m_item : Ident ) -> bool {
@@ -173,21 +131,6 @@ impl Attribute {
173131 }
174132 }
175133
176- /// Returns `true` if the attribute's path matches the argument.
177- /// If it matches, then the attribute is marked as used.
178- /// Should only be used by rustc, other tools can use `has_name` instead,
179- /// because only rustc is supposed to report the `unused_attributes` lint.
180- /// `MetaItem` and `NestedMetaItem` are produced by "lowering" an `Attribute`
181- /// and don't have identity, so they only has the `has_name` method,
182- /// and you need to mark the original `Attribute` as used when necessary.
183- pub fn check_name ( & self , name : Symbol ) -> bool {
184- let matches = self . has_name ( name) ;
185- if matches {
186- mark_used ( self ) ;
187- }
188- matches
189- }
190-
191134 /// For a single-segment attribute, returns its name; otherwise, returns `None`.
192135 pub fn ident ( & self ) -> Option < Ident > {
193136 match self . kind {
@@ -418,22 +361,6 @@ pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
418361 items. iter ( ) . any ( |item| item. has_name ( name) )
419362}
420363
421- pub fn contains_name ( attrs : & [ Attribute ] , name : Symbol ) -> bool {
422- attrs. iter ( ) . any ( |item| item. check_name ( name) )
423- }
424-
425- pub fn find_by_name ( attrs : & [ Attribute ] , name : Symbol ) -> Option < & Attribute > {
426- attrs. iter ( ) . find ( |attr| attr. check_name ( name) )
427- }
428-
429- pub fn filter_by_name ( attrs : & [ Attribute ] , name : Symbol ) -> impl Iterator < Item = & Attribute > {
430- attrs. iter ( ) . filter ( move |attr| attr. check_name ( name) )
431- }
432-
433- pub fn first_attr_value_str_by_name ( attrs : & [ Attribute ] , name : Symbol ) -> Option < Symbol > {
434- attrs. iter ( ) . find ( |at| at. check_name ( name) ) . and_then ( |at| at. value_str ( ) )
435- }
436-
437364impl MetaItem {
438365 fn token_trees_and_joints ( & self ) -> Vec < TreeAndJoint > {
439366 let mut idents = vec ! [ ] ;
0 commit comments