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