@@ -855,39 +855,42 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
855855 _ => span_bug ! ( item. span, "trait_def_of_item invoked on non-trait" ) ,
856856 } ;
857857
858+ let attrs = tcx. get_all_attrs ( def_id) ;
858859 // Only regular traits can be const.
859- let constness = if !is_alias && tcx . has_attr ( def_id , sym :: const_trait ) {
860+ let constness = if !is_alias && find_attr ! ( attrs , AttributeKind :: ConstTrait ( _ ) ) {
860861 hir:: Constness :: Const
861862 } else {
862863 hir:: Constness :: NotConst
863864 } ;
864865
865- let paren_sugar = tcx . has_attr ( def_id , sym:: rustc_paren_sugar) ;
866+ let paren_sugar = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: rustc_paren_sugar) ) ;
866867 if paren_sugar && !tcx. features ( ) . unboxed_closures ( ) {
867868 tcx. dcx ( ) . emit_err ( errors:: ParenSugarAttribute { span : item. span } ) ;
868869 }
869870
870871 // Only regular traits can be marker.
871- let is_marker = !is_alias && tcx . has_attr ( def_id , sym:: marker) ;
872+ let is_marker = !is_alias && attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: marker) ) ;
872873
873- let rustc_coinductive = tcx . has_attr ( def_id , sym:: rustc_coinductive) ;
874- let is_fundamental = tcx . has_attr ( def_id , sym:: fundamental) ;
874+ let rustc_coinductive = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: rustc_coinductive) ) ;
875+ let is_fundamental = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: fundamental) ) ;
875876
876877 let [ skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr ! (
877- tcx . get_all_attrs ( def_id ) ,
878- AttributeKind :: SkipDuringMethodDispatch { array, boxed_slice, span: _ } => [ * array, * boxed_slice]
878+ attrs ,
879+ AttributeKind :: SkipDuringMethodDispatch { array, boxed_slice, span: _ } => [ * array, * boxed_slice]
879880 )
880881 . unwrap_or ( [ false ; 2 ] ) ;
881882
882- let specialization_kind = if tcx. has_attr ( def_id, sym:: rustc_unsafe_specialization_marker) {
883- ty:: trait_def:: TraitSpecializationKind :: Marker
884- } else if tcx. has_attr ( def_id, sym:: rustc_specialization_trait) {
885- ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable
886- } else {
887- ty:: trait_def:: TraitSpecializationKind :: None
888- } ;
889- let must_implement_one_of = tcx
890- . get_attr ( def_id, sym:: rustc_must_implement_one_of)
883+ let specialization_kind =
884+ if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_unsafe_specialization_marker) ) {
885+ ty:: trait_def:: TraitSpecializationKind :: Marker
886+ } else if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_specialization_trait) ) {
887+ ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable
888+ } else {
889+ ty:: trait_def:: TraitSpecializationKind :: None
890+ } ;
891+ let must_implement_one_of = attrs
892+ . iter ( )
893+ . find ( |attr| attr. has_name ( sym:: rustc_must_implement_one_of) )
891894 // Check that there are at least 2 arguments of `#[rustc_must_implement_one_of]`
892895 // and that they are all identifiers
893896 . and_then ( |attr| match attr. meta_item_list ( ) {
@@ -961,8 +964,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
961964 no_dups. then_some ( list)
962965 } ) ;
963966
964- let deny_explicit_impl = tcx. has_attr ( def_id, sym:: rustc_deny_explicit_impl) ;
965- let implement_via_object = !tcx. has_attr ( def_id, sym:: rustc_do_not_implement_via_object) ;
967+ let deny_explicit_impl = attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_deny_explicit_impl) ) ;
968+ let implement_via_object =
969+ !attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_do_not_implement_via_object) ) ;
966970
967971 ty:: TraitDef {
968972 def_id : def_id. to_def_id ( ) ,
0 commit comments