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