@@ -227,20 +227,24 @@ impl TypeAliasData {
227227 }
228228}
229229
230+ bitflags:: bitflags! {
231+ #[ derive( Debug , Clone , Copy , Eq , PartialEq , Default ) ]
232+ pub struct TraitFlags : u8 {
233+ const IS_AUTO = 1 << 0 ;
234+ const IS_UNSAFE = 1 << 1 ;
235+ const IS_FUNDAMENTAL = 1 << 2 ;
236+ const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 3 ;
237+ const SKIP_ARRAY_DURING_METHOD_DISPATCH = 1 << 4 ;
238+ const SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH = 1 << 5 ;
239+ }
240+ }
241+
230242#[ derive( Debug , Clone , PartialEq , Eq ) ]
231243pub struct TraitData {
232244 pub name : Name ,
233245 pub items : Vec < ( Name , AssocItemId ) > ,
234- pub is_auto : bool ,
235- pub is_unsafe : bool ,
236- pub rustc_has_incoherent_inherent_impls : bool ,
237- pub skip_array_during_method_dispatch : bool ,
238- pub skip_boxed_slice_during_method_dispatch : bool ,
239- pub fundamental : bool ,
246+ pub flags : TraitFlags ,
240247 pub visibility : RawVisibility ,
241- /// Whether the trait has `#[rust_skip_array_during_method_dispatch]`. `hir_ty` will ignore
242- /// method calls to this trait's methods when the receiver is an array and the crate edition is
243- /// 2015 or 2018.
244248 // box it as the vec is usually empty anyways
245249 pub macro_calls : Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ,
246250}
@@ -259,10 +263,24 @@ impl TraitData {
259263 let item_tree = tree_id. item_tree ( db) ;
260264 let tr_def = & item_tree[ tree_id. value ] ;
261265 let name = tr_def. name . clone ( ) ;
262- let is_auto = tr_def. is_auto ;
263- let is_unsafe = tr_def. is_unsafe ;
264266 let visibility = item_tree[ tr_def. visibility ] . clone ( ) ;
265267 let attrs = item_tree. attrs ( db, module_id. krate ( ) , ModItem :: from ( tree_id. value ) . into ( ) ) ;
268+
269+ let mut flags = TraitFlags :: empty ( ) ;
270+
271+ if tr_def. is_auto {
272+ flags |= TraitFlags :: IS_AUTO ;
273+ }
274+ if tr_def. is_unsafe {
275+ flags |= TraitFlags :: IS_UNSAFE ;
276+ }
277+ if attrs. by_key ( & sym:: fundamental) . exists ( ) {
278+ flags |= TraitFlags :: IS_FUNDAMENTAL ;
279+ }
280+ if attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) {
281+ flags |= TraitFlags :: RUSTC_HAS_INCOHERENT_INHERENT_IMPLS ;
282+ }
283+
266284 let mut skip_array_during_method_dispatch =
267285 attrs. by_key ( & sym:: rustc_skip_array_during_method_dispatch) . exists ( ) ;
268286 let mut skip_boxed_slice_during_method_dispatch = false ;
@@ -274,27 +292,21 @@ impl TraitData {
274292 }
275293 }
276294 }
277- let rustc_has_incoherent_inherent_impls =
278- attrs. by_key ( & sym:: rustc_has_incoherent_inherent_impls) . exists ( ) ;
279- let fundamental = attrs. by_key ( & sym:: fundamental) . exists ( ) ;
295+
296+ if skip_array_during_method_dispatch {
297+ flags |= TraitFlags :: SKIP_ARRAY_DURING_METHOD_DISPATCH ;
298+ }
299+ if skip_boxed_slice_during_method_dispatch {
300+ flags |= TraitFlags :: SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH ;
301+ }
302+
280303 let mut collector =
281304 AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
282305 collector. collect ( & item_tree, tree_id. tree_id ( ) , & tr_def. items ) ;
283306 let ( items, macro_calls, diagnostics) = collector. finish ( ) ;
284307
285308 (
286- Arc :: new ( TraitData {
287- name,
288- macro_calls,
289- items,
290- is_auto,
291- is_unsafe,
292- visibility,
293- skip_array_during_method_dispatch,
294- skip_boxed_slice_during_method_dispatch,
295- rustc_has_incoherent_inherent_impls,
296- fundamental,
297- } ) ,
309+ Arc :: new ( TraitData { name, macro_calls, items, visibility, flags } ) ,
298310 DefDiagnostics :: new ( diagnostics) ,
299311 )
300312 }
0 commit comments