@@ -855,39 +855,42 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
855
855
_ => span_bug ! ( item. span, "trait_def_of_item invoked on non-trait" ) ,
856
856
} ;
857
857
858
+ let attrs = tcx. get_all_attrs ( def_id) ;
858
859
// 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 ( _ ) ) {
860
861
hir:: Constness :: Const
861
862
} else {
862
863
hir:: Constness :: NotConst
863
864
} ;
864
865
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) ) ;
866
867
if paren_sugar && !tcx. features ( ) . unboxed_closures ( ) {
867
868
tcx. dcx ( ) . emit_err ( errors:: ParenSugarAttribute { span : item. span } ) ;
868
869
}
869
870
870
871
// 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) ) ;
872
873
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) ) ;
875
876
876
877
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]
879
880
)
880
881
. unwrap_or ( [ false ; 2 ] ) ;
881
882
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) )
891
894
// Check that there are at least 2 arguments of `#[rustc_must_implement_one_of]`
892
895
// and that they are all identifiers
893
896
. and_then ( |attr| match attr. meta_item_list ( ) {
@@ -961,8 +964,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
961
964
no_dups. then_some ( list)
962
965
} ) ;
963
966
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) ) ;
966
970
967
971
ty:: TraitDef {
968
972
def_id : def_id. to_def_id ( ) ,
0 commit comments