@@ -12,7 +12,7 @@ use crate::{
12
12
ConstId , ExternCrateId , FunctionId , HasModule , ImplId , ItemContainerId , ItemLoc , Lookup ,
13
13
Macro2Id , MacroRulesId , ProcMacroId , StaticId , TraitAliasId , TraitId , TypeAliasId ,
14
14
db:: DefDatabase ,
15
- item_tree:: { self , FnFlags , ModItem } ,
15
+ item_tree:: { self , FnFlags , ModItem , StaticFlags } ,
16
16
nameres:: proc_macro:: { ProcMacroKind , parse_macro_name_and_helper_attrs} ,
17
17
path:: ImportAlias ,
18
18
type_ref:: { TraitRef , TypeBound , TypeRefId , TypesMap } ,
@@ -27,9 +27,8 @@ pub struct FunctionData {
27
27
pub visibility : RawVisibility ,
28
28
pub abi : Option < Symbol > ,
29
29
pub legacy_const_generics_indices : Option < Box < Box < [ u32 ] > > > ,
30
- pub rustc_allow_incoherent_impl : bool ,
31
30
pub types_map : Arc < TypesMap > ,
32
- flags : FnFlags ,
31
+ pub flags : FnFlags ,
33
32
}
34
33
35
34
impl FunctionData {
@@ -72,7 +71,9 @@ impl FunctionData {
72
71
}
73
72
74
73
let attrs = item_tree. attrs ( db, krate, ModItem :: from ( loc. id . value ) . into ( ) ) ;
75
- let rustc_allow_incoherent_impl = attrs. by_key ( & sym:: rustc_allow_incoherent_impl) . exists ( ) ;
74
+ if attrs. by_key ( & sym:: rustc_allow_incoherent_impl) . exists ( ) {
75
+ flags |= FnFlags :: RUSTC_ALLOW_INCOHERENT_IMPL ;
76
+ }
76
77
if flags. contains ( FnFlags :: HAS_UNSAFE_KW )
77
78
&& attrs. by_key ( & sym:: rustc_deprecated_safe_2024) . exists ( )
78
79
{
@@ -101,67 +102,103 @@ impl FunctionData {
101
102
legacy_const_generics_indices : attrs. rustc_legacy_const_generics ( ) ,
102
103
types_map : func. types_map . clone ( ) ,
103
104
flags,
104
- rustc_allow_incoherent_impl,
105
105
} )
106
106
}
107
107
108
+ #[ inline]
108
109
pub fn has_body ( & self ) -> bool {
109
110
self . flags . contains ( FnFlags :: HAS_BODY )
110
111
}
111
112
112
113
/// True if the first param is `self`. This is relevant to decide whether this
113
114
/// can be called as a method.
115
+ #[ inline]
114
116
pub fn has_self_param ( & self ) -> bool {
115
117
self . flags . contains ( FnFlags :: HAS_SELF_PARAM )
116
118
}
117
119
120
+ #[ inline]
118
121
pub fn is_default ( & self ) -> bool {
119
122
self . flags . contains ( FnFlags :: HAS_DEFAULT_KW )
120
123
}
121
124
125
+ #[ inline]
122
126
pub fn is_const ( & self ) -> bool {
123
127
self . flags . contains ( FnFlags :: HAS_CONST_KW )
124
128
}
125
129
130
+ #[ inline]
126
131
pub fn is_async ( & self ) -> bool {
127
132
self . flags . contains ( FnFlags :: HAS_ASYNC_KW )
128
133
}
129
134
135
+ #[ inline]
130
136
pub fn is_unsafe ( & self ) -> bool {
131
137
self . flags . contains ( FnFlags :: HAS_UNSAFE_KW )
132
138
}
133
139
140
+ #[ inline]
134
141
pub fn is_deprecated_safe_2024 ( & self ) -> bool {
135
142
self . flags . contains ( FnFlags :: DEPRECATED_SAFE_2024 )
136
143
}
137
144
145
+ #[ inline]
138
146
pub fn is_safe ( & self ) -> bool {
139
147
self . flags . contains ( FnFlags :: HAS_SAFE_KW )
140
148
}
141
149
150
+ #[ inline]
142
151
pub fn is_varargs ( & self ) -> bool {
143
152
self . flags . contains ( FnFlags :: IS_VARARGS )
144
153
}
145
154
155
+ #[ inline]
146
156
pub fn has_target_feature ( & self ) -> bool {
147
157
self . flags . contains ( FnFlags :: HAS_TARGET_FEATURE )
148
158
}
159
+
160
+ #[ inline]
161
+ pub fn rustc_allow_incoherent_impl ( & self ) -> bool {
162
+ self . flags . contains ( FnFlags :: RUSTC_ALLOW_INCOHERENT_IMPL )
163
+ }
149
164
}
150
165
151
166
#[ derive( Debug , Clone , PartialEq , Eq ) ]
152
167
pub struct TypeAliasData {
153
168
pub name : Name ,
154
169
pub type_ref : Option < TypeRefId > ,
155
170
pub visibility : RawVisibility ,
156
- pub is_extern : bool ,
157
- pub rustc_has_incoherent_inherent_impls : bool ,
158
- pub rustc_allow_incoherent_impl : bool ,
171
+ pub flags : TypeAliasFlags ,
159
172
/// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
160
173
pub bounds : Box < [ TypeBound ] > ,
161
174
pub types_map : Arc < TypesMap > ,
162
175
}
163
176
177
+ bitflags:: bitflags! {
178
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
179
+ pub struct TypeAliasFlags : u8 {
180
+ const IS_EXTERN = 1 << 0 ;
181
+ const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 1 ;
182
+ const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 2 ;
183
+ }
184
+ }
185
+
164
186
impl TypeAliasData {
187
+ #[ inline]
188
+ pub fn is_extern ( & self ) -> bool {
189
+ self . flags . contains ( TypeAliasFlags :: IS_EXTERN )
190
+ }
191
+
192
+ #[ inline]
193
+ pub fn rustc_has_incoherent_inherent_impls ( & self ) -> bool {
194
+ self . flags . contains ( TypeAliasFlags :: RUSTC_HAS_INCOHERENT_INHERENT_IMPLS )
195
+ }
196
+
197
+ #[ inline]
198
+ pub fn rustc_allow_incoherent_impl ( & self ) -> bool {
199
+ self . flags . contains ( TypeAliasFlags :: RUSTC_ALLOW_INCOHERENT_IMPL )
200
+ }
201
+
165
202
pub ( crate ) fn type_alias_data_query (
166
203
db : & dyn DefDatabase ,
167
204
typ : TypeAliasId ,
@@ -180,17 +217,24 @@ impl TypeAliasData {
180
217
loc. container . module ( db) . krate ( ) ,
181
218
ModItem :: from ( loc. id . value ) . into ( ) ,
182
219
) ;
183
- let rustc_has_incoherent_inherent_impls =
184
- attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) ;
185
- let rustc_allow_incoherent_impl = attrs. by_key ( & sym:: rustc_allow_incoherent_impl) . exists ( ) ;
220
+
221
+ let mut flags = TypeAliasFlags :: empty ( ) ;
222
+
223
+ if matches ! ( loc. container, ItemContainerId :: ExternBlockId ( _) ) {
224
+ flags |= TypeAliasFlags :: IS_EXTERN ;
225
+ }
226
+ if attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) {
227
+ flags |= TypeAliasFlags :: RUSTC_HAS_INCOHERENT_INHERENT_IMPLS ;
228
+ }
229
+ if attrs. by_key ( & sym:: rustc_allow_incoherent_impl) . exists ( ) {
230
+ flags |= TypeAliasFlags :: RUSTC_ALLOW_INCOHERENT_IMPL ;
231
+ }
186
232
187
233
Arc :: new ( TypeAliasData {
188
234
name : typ. name . clone ( ) ,
189
235
type_ref : typ. type_ref ,
190
236
visibility,
191
- is_extern : matches ! ( loc. container, ItemContainerId :: ExternBlockId ( _) ) ,
192
- rustc_has_incoherent_inherent_impls,
193
- rustc_allow_incoherent_impl,
237
+ flags,
194
238
bounds : typ. bounds . clone ( ) ,
195
239
types_map : typ. types_map . clone ( ) ,
196
240
} )
@@ -199,7 +243,7 @@ impl TypeAliasData {
199
243
200
244
bitflags:: bitflags! {
201
245
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
202
- pub struct TraitFlags : u8 {
246
+ pub struct TraitFlags : u16 {
203
247
const IS_AUTO = 1 << 0 ;
204
248
const IS_UNSAFE = 1 << 1 ;
205
249
const IS_FUNDAMENTAL = 1 << 2 ;
@@ -332,9 +376,9 @@ impl Macro2Data {
332
376
let loc = makro. lookup ( db) ;
333
377
let item_tree = loc. id . item_tree ( db) ;
334
378
let makro = & item_tree[ loc. id . value ] ;
379
+ let attrs = item_tree. attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) ) ;
335
380
336
- let helpers = item_tree
337
- . attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) )
381
+ let helpers = attrs
338
382
. by_key ( & sym:: rustc_builtin_macro)
339
383
. tt_values ( )
340
384
. next ( )
@@ -362,11 +406,9 @@ impl MacroRulesData {
362
406
let loc = makro. lookup ( db) ;
363
407
let item_tree = loc. id . item_tree ( db) ;
364
408
let makro = & item_tree[ loc. id . value ] ;
409
+ let attrs = item_tree. attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) ) ;
365
410
366
- let macro_export = item_tree
367
- . attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) )
368
- . by_key ( & sym:: macro_export)
369
- . exists ( ) ;
411
+ let macro_export = attrs. by_key ( & sym:: macro_export) . exists ( ) ;
370
412
371
413
Arc :: new ( MacroRulesData { name : makro. name . clone ( ) , macro_export } )
372
414
}
@@ -387,11 +429,9 @@ impl ProcMacroData {
387
429
let loc = makro. lookup ( db) ;
388
430
let item_tree = loc. id . item_tree ( db) ;
389
431
let makro = & item_tree[ loc. id . value ] ;
432
+ let attrs = item_tree. attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) ) ;
390
433
391
- let ( name, helpers) = if let Some ( def) = item_tree
392
- . attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) )
393
- . parse_proc_macro_decl ( & makro. name )
394
- {
434
+ let ( name, helpers) = if let Some ( def) = attrs. parse_proc_macro_decl ( & makro. name ) {
395
435
(
396
436
def. name ,
397
437
match def. kind {
@@ -404,6 +444,7 @@ impl ProcMacroData {
404
444
stdx:: never!( "proc macro declaration is not a proc macro" ) ;
405
445
( makro. name . clone ( ) , None )
406
446
} ;
447
+
407
448
Arc :: new ( ProcMacroData { name, helpers } )
408
449
}
409
450
}
@@ -450,9 +491,16 @@ pub struct ConstData {
450
491
pub name : Option < Name > ,
451
492
pub type_ref : TypeRefId ,
452
493
pub visibility : RawVisibility ,
453
- pub rustc_allow_incoherent_impl : bool ,
454
- pub has_body : bool ,
455
494
pub types_map : Arc < TypesMap > ,
495
+ pub flags : ConstFlags ,
496
+ }
497
+
498
+ bitflags:: bitflags! {
499
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
500
+ pub struct ConstFlags : u8 {
501
+ const RUSTC_ALLOW_INCOHERENT_IMPL = 1 << 0 ;
502
+ const HAS_BODY = 1 << 1 ;
503
+ }
456
504
}
457
505
458
506
impl ConstData {
@@ -465,33 +513,47 @@ impl ConstData {
465
513
} else {
466
514
item_tree[ konst. visibility ] . clone ( )
467
515
} ;
516
+ let attrs = item_tree. attrs (
517
+ db,
518
+ loc. container . module ( db) . krate ( ) ,
519
+ ModItem :: from ( loc. id . value ) . into ( ) ,
520
+ ) ;
468
521
469
- let rustc_allow_incoherent_impl = item_tree
470
- . attrs ( db, loc. container . module ( db) . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) )
471
- . by_key ( & sym:: rustc_allow_incoherent_impl)
472
- . exists ( ) ;
522
+ let mut flags = ConstFlags :: empty ( ) ;
523
+ if attrs. by_key ( & sym:: rustc_allow_incoherent_impl) . exists ( ) {
524
+ flags |= ConstFlags :: RUSTC_ALLOW_INCOHERENT_IMPL ;
525
+ }
526
+ if konst. has_body {
527
+ flags |= ConstFlags :: HAS_BODY ;
528
+ }
473
529
474
530
Arc :: new ( ConstData {
475
531
name : konst. name . clone ( ) ,
476
532
type_ref : konst. type_ref ,
477
533
visibility,
478
- rustc_allow_incoherent_impl,
479
- has_body : konst. has_body ,
534
+ flags,
480
535
types_map : konst. types_map . clone ( ) ,
481
536
} )
482
537
}
538
+
539
+ #[ inline]
540
+ pub fn rustc_allow_incoherent_impl ( & self ) -> bool {
541
+ self . flags . contains ( ConstFlags :: RUSTC_ALLOW_INCOHERENT_IMPL )
542
+ }
543
+
544
+ #[ inline]
545
+ pub fn has_body ( & self ) -> bool {
546
+ self . flags . contains ( ConstFlags :: HAS_BODY )
547
+ }
483
548
}
484
549
485
550
#[ derive( Debug , Clone , PartialEq , Eq ) ]
486
551
pub struct StaticData {
487
552
pub name : Name ,
488
553
pub type_ref : TypeRefId ,
489
554
pub visibility : RawVisibility ,
490
- pub mutable : bool ,
491
- pub is_extern : bool ,
492
- pub has_safe_kw : bool ,
493
- pub has_unsafe_kw : bool ,
494
555
pub types_map : Arc < TypesMap > ,
556
+ pub flags : StaticFlags ,
495
557
}
496
558
497
559
impl StaticData {
@@ -500,17 +562,39 @@ impl StaticData {
500
562
let item_tree = loc. id . item_tree ( db) ;
501
563
let statik = & item_tree[ loc. id . value ] ;
502
564
565
+ let mut flags = statik. flags ;
566
+ if matches ! ( loc. container, ItemContainerId :: ExternBlockId ( _) ) {
567
+ flags |= StaticFlags :: IS_EXTERN ;
568
+ }
569
+
503
570
Arc :: new ( StaticData {
504
571
name : statik. name . clone ( ) ,
505
572
type_ref : statik. type_ref ,
506
573
visibility : item_tree[ statik. visibility ] . clone ( ) ,
507
- mutable : statik. mutable ,
508
- is_extern : matches ! ( loc. container, ItemContainerId :: ExternBlockId ( _) ) ,
509
- has_safe_kw : statik. has_safe_kw ,
510
- has_unsafe_kw : statik. has_unsafe_kw ,
574
+ flags,
511
575
types_map : statik. types_map . clone ( ) ,
512
576
} )
513
577
}
578
+
579
+ #[ inline]
580
+ pub fn is_extern ( & self ) -> bool {
581
+ self . flags . contains ( StaticFlags :: IS_EXTERN )
582
+ }
583
+
584
+ #[ inline]
585
+ pub fn mutable ( & self ) -> bool {
586
+ self . flags . contains ( StaticFlags :: MUTABLE )
587
+ }
588
+
589
+ #[ inline]
590
+ pub fn has_safe_kw ( & self ) -> bool {
591
+ self . flags . contains ( StaticFlags :: HAS_SAFE_KW )
592
+ }
593
+
594
+ #[ inline]
595
+ pub fn has_unsafe_kw ( & self ) -> bool {
596
+ self . flags . contains ( StaticFlags :: HAS_UNSAFE_KW )
597
+ }
514
598
}
515
599
516
600
fn trait_vis ( db : & dyn DefDatabase , trait_id : TraitId ) -> RawVisibility {
0 commit comments