@@ -852,39 +852,42 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
852852 _ => span_bug ! ( item. span, "trait_def_of_item invoked on non-trait" ) ,
853853 } ;
854854
855+ let attrs = tcx. get_all_attrs ( def_id) ;
855856 // Only regular traits can be const.
856- let constness = if !is_alias && tcx . has_attr ( def_id , sym :: const_trait ) {
857+ let constness = if !is_alias && find_attr ! ( attrs , AttributeKind :: ConstTrait ( _ ) ) {
857858 hir:: Constness :: Const
858859 } else {
859860 hir:: Constness :: NotConst
860861 } ;
861862
862- let paren_sugar = tcx . has_attr ( def_id , sym:: rustc_paren_sugar) ;
863+ let paren_sugar = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: rustc_paren_sugar) ) ;
863864 if paren_sugar && !tcx. features ( ) . unboxed_closures ( ) {
864865 tcx. dcx ( ) . emit_err ( errors:: ParenSugarAttribute { span : item. span } ) ;
865866 }
866867
867868 // Only regular traits can be marker.
868- let is_marker = !is_alias && tcx . has_attr ( def_id , sym:: marker) ;
869+ let is_marker = !is_alias && attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: marker) ) ;
869870
870- let rustc_coinductive = tcx . has_attr ( def_id , sym:: rustc_coinductive) ;
871- let is_fundamental = tcx . has_attr ( def_id , sym:: fundamental) ;
871+ let rustc_coinductive = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: rustc_coinductive) ) ;
872+ let is_fundamental = attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: fundamental) ) ;
872873
873874 let [ skip_array_during_method_dispatch, skip_boxed_slice_during_method_dispatch] = find_attr ! (
874- tcx . get_all_attrs ( def_id ) ,
875- AttributeKind :: SkipDuringMethodDispatch { array, boxed_slice, span: _ } => [ * array, * boxed_slice]
875+ attrs ,
876+ AttributeKind :: SkipDuringMethodDispatch { array, boxed_slice, span: _ } => [ * array, * boxed_slice]
876877 )
877878 . unwrap_or ( [ false ; 2 ] ) ;
878879
879- let specialization_kind = if tcx. has_attr ( def_id, sym:: rustc_unsafe_specialization_marker) {
880- ty:: trait_def:: TraitSpecializationKind :: Marker
881- } else if tcx. has_attr ( def_id, sym:: rustc_specialization_trait) {
882- ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable
883- } else {
884- ty:: trait_def:: TraitSpecializationKind :: None
885- } ;
886- let must_implement_one_of = tcx
887- . get_attr ( def_id, sym:: rustc_must_implement_one_of)
880+ let specialization_kind =
881+ if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_unsafe_specialization_marker) ) {
882+ ty:: trait_def:: TraitSpecializationKind :: Marker
883+ } else if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_specialization_trait) ) {
884+ ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable
885+ } else {
886+ ty:: trait_def:: TraitSpecializationKind :: None
887+ } ;
888+ let must_implement_one_of = attrs
889+ . iter ( )
890+ . find ( |attr| attr. has_name ( sym:: rustc_must_implement_one_of) )
888891 // Check that there are at least 2 arguments of `#[rustc_must_implement_one_of]`
889892 // and that they are all identifiers
890893 . and_then ( |attr| match attr. meta_item_list ( ) {
@@ -958,8 +961,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
958961 no_dups. then_some ( list)
959962 } ) ;
960963
961- let deny_explicit_impl = tcx. has_attr ( def_id, sym:: rustc_deny_explicit_impl) ;
962- let implement_via_object = !tcx. has_attr ( def_id, sym:: rustc_do_not_implement_via_object) ;
964+ let deny_explicit_impl = attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_deny_explicit_impl) ) ;
965+ let implement_via_object =
966+ !attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: rustc_do_not_implement_via_object) ) ;
963967
964968 ty:: TraitDef {
965969 def_id : def_id. to_def_id ( ) ,
0 commit comments