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