@@ -229,20 +229,24 @@ impl TypeAliasData {
229
229
}
230
230
}
231
231
232
+ bitflags:: bitflags! {
233
+ #[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
234
+ pub struct TraitFlags : u8 {
235
+ const IS_AUTO = 1 << 0 ;
236
+ const IS_UNSAFE = 1 << 1 ;
237
+ const IS_FUNDAMENTAL = 1 << 2 ;
238
+ const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 3 ;
239
+ const SKIP_ARRAY_DURING_METHOD_DISPATCH = 1 << 4 ;
240
+ const SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH = 1 << 5 ;
241
+ }
242
+ }
243
+
232
244
#[ derive( Debug , Clone , PartialEq , Eq ) ]
233
245
pub struct TraitData {
234
246
pub name : Name ,
235
247
pub items : Vec < ( Name , AssocItemId ) > ,
236
- pub is_auto : bool ,
237
- pub is_unsafe : bool ,
238
- pub rustc_has_incoherent_inherent_impls : bool ,
239
- pub skip_array_during_method_dispatch : bool ,
240
- pub skip_boxed_slice_during_method_dispatch : bool ,
241
- pub fundamental : bool ,
248
+ pub flags : TraitFlags ,
242
249
pub visibility : RawVisibility ,
243
- /// Whether the trait has `#[rust_skip_array_during_method_dispatch]`. `hir_ty` will ignore
244
- /// method calls to this trait's methods when the receiver is an array and the crate edition is
245
- /// 2015 or 2018.
246
250
// box it as the vec is usually empty anyways
247
251
pub macro_calls : Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ,
248
252
}
@@ -261,10 +265,24 @@ impl TraitData {
261
265
let item_tree = tree_id. item_tree ( db) ;
262
266
let tr_def = & item_tree[ tree_id. value ] ;
263
267
let name = tr_def. name . clone ( ) ;
264
- let is_auto = tr_def. is_auto ;
265
- let is_unsafe = tr_def. is_unsafe ;
266
268
let visibility = item_tree[ tr_def. visibility ] . clone ( ) ;
267
269
let attrs = item_tree. attrs ( db, module_id. krate ( ) , ModItem :: from ( tree_id. value ) . into ( ) ) ;
270
+
271
+ let mut flags = TraitFlags :: empty ( ) ;
272
+
273
+ if tr_def. is_auto {
274
+ flags |= TraitFlags :: IS_AUTO ;
275
+ }
276
+ if tr_def. is_unsafe {
277
+ flags |= TraitFlags :: IS_UNSAFE ;
278
+ }
279
+ if attrs. by_key ( & sym:: fundamental) . exists ( ) {
280
+ flags |= TraitFlags :: IS_FUNDAMENTAL ;
281
+ }
282
+ if attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) {
283
+ flags |= TraitFlags :: RUSTC_HAS_INCOHERENT_INHERENT_IMPLS ;
284
+ }
285
+
268
286
let mut skip_array_during_method_dispatch =
269
287
attrs. by_key ( & sym:: rustc_skip_array_during_method_dispatch) . exists ( ) ;
270
288
let mut skip_boxed_slice_during_method_dispatch = false ;
@@ -276,27 +294,21 @@ impl TraitData {
276
294
}
277
295
}
278
296
}
279
- let rustc_has_incoherent_inherent_impls =
280
- attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) ;
281
- let fundamental = attrs. by_key ( & sym:: fundamental) . exists ( ) ;
297
+
298
+ if skip_array_during_method_dispatch {
299
+ flags |= TraitFlags :: SKIP_ARRAY_DURING_METHOD_DISPATCH ;
300
+ }
301
+ if skip_boxed_slice_during_method_dispatch {
302
+ flags |= TraitFlags :: SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH ;
303
+ }
304
+
282
305
let mut collector =
283
306
AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
284
307
collector. collect ( & item_tree, tree_id. tree_id ( ) , & tr_def. items ) ;
285
308
let ( items, macro_calls, diagnostics) = collector. finish ( ) ;
286
309
287
310
(
288
- Arc :: new ( TraitData {
289
- name,
290
- macro_calls,
291
- items,
292
- is_auto,
293
- is_unsafe,
294
- visibility,
295
- skip_array_during_method_dispatch,
296
- skip_boxed_slice_during_method_dispatch,
297
- rustc_has_incoherent_inherent_impls,
298
- fundamental,
299
- } ) ,
311
+ Arc :: new ( TraitData { name, macro_calls, items, visibility, flags } ) ,
300
312
DefDiagnostics :: new ( diagnostics) ,
301
313
)
302
314
}
0 commit comments