@@ -229,20 +229,24 @@ impl TypeAliasData {
229229 }
230230}
231231
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+
232244#[ derive( Debug , Clone , PartialEq , Eq ) ]
233245pub struct TraitData {
234246 pub name : Name ,
235247 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 ,
242249 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.
246250 // box it as the vec is usually empty anyways
247251 pub macro_calls : Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ,
248252}
@@ -261,10 +265,24 @@ impl TraitData {
261265 let item_tree = tree_id. item_tree ( db) ;
262266 let tr_def = & item_tree[ tree_id. value ] ;
263267 let name = tr_def. name . clone ( ) ;
264- let is_auto = tr_def. is_auto ;
265- let is_unsafe = tr_def. is_unsafe ;
266268 let visibility = item_tree[ tr_def. visibility ] . clone ( ) ;
267269 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+
268286 let mut skip_array_during_method_dispatch =
269287 attrs. by_key ( & sym:: rustc_skip_array_during_method_dispatch) . exists ( ) ;
270288 let mut skip_boxed_slice_during_method_dispatch = false ;
@@ -276,27 +294,21 @@ impl TraitData {
276294 }
277295 }
278296 }
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+
282305 let mut collector =
283306 AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
284307 collector. collect ( & item_tree, tree_id. tree_id ( ) , & tr_def. items ) ;
285308 let ( items, macro_calls, diagnostics) = collector. finish ( ) ;
286309
287310 (
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 } ) ,
300312 DefDiagnostics :: new ( diagnostics) ,
301313 )
302314 }
0 commit comments