@@ -22,7 +22,6 @@ use std::ops::Bound;
2222use rustc_abi:: { ExternAbi , Size } ;
2323use rustc_ast:: Recovered ;
2424use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
25- use rustc_data_structures:: unord:: UnordMap ;
2625use rustc_errors:: {
2726 Applicability , Diag , DiagCtxtHandle , E0228 , ErrorGuaranteed , StashKey , struct_span_code_err,
2827} ;
@@ -916,84 +915,15 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
916915 } else {
917916 ty:: trait_def:: TraitSpecializationKind :: None
918917 } ;
919- let must_implement_one_of = attrs
920- . iter ( )
921- . find ( |attr| attr. has_name ( sym:: rustc_must_implement_one_of) )
922- // Check that there are at least 2 arguments of `#[rustc_must_implement_one_of]`
923- // and that they are all identifiers
924- . and_then ( |attr| match attr. meta_item_list ( ) {
925- Some ( items) if items. len ( ) < 2 => {
926- tcx. dcx ( ) . emit_err ( errors:: MustImplementOneOfAttribute { span : attr. span ( ) } ) ;
927-
928- None
929- }
930- Some ( items) => items
931- . into_iter ( )
932- . map ( |item| item. ident ( ) . ok_or ( item. span ( ) ) )
933- . collect :: < Result < Box < [ _ ] > , _ > > ( )
934- . map_err ( |span| {
935- tcx. dcx ( ) . emit_err ( errors:: MustBeNameOfAssociatedFunction { span } ) ;
936- } )
937- . ok ( )
938- . zip ( Some ( attr. span ( ) ) ) ,
939- // Error is reported by `rustc_attr!`
940- None => None ,
941- } )
942- // Check that all arguments of `#[rustc_must_implement_one_of]` reference
943- // functions in the trait with default implementations
944- . and_then ( |( list, attr_span) | {
945- let errors = list. iter ( ) . filter_map ( |ident| {
946- let item = tcx
947- . associated_items ( def_id)
948- . filter_by_name_unhygienic ( ident. name )
949- . find ( |item| item. ident ( tcx) == * ident) ;
950-
951- match item {
952- Some ( item) if matches ! ( item. kind, ty:: AssocKind :: Fn { .. } ) => {
953- if !item. defaultness ( tcx) . has_value ( ) {
954- tcx. dcx ( ) . emit_err ( errors:: FunctionNotHaveDefaultImplementation {
955- span : tcx. def_span ( item. def_id ) ,
956- note_span : attr_span,
957- } ) ;
958918
959- return Some ( ( ) ) ;
960- }
961-
962- return None ;
963- }
964- Some ( item) => {
965- tcx. dcx ( ) . emit_err ( errors:: MustImplementNotFunction {
966- span : tcx. def_span ( item. def_id ) ,
967- span_note : errors:: MustImplementNotFunctionSpanNote { span : attr_span } ,
968- note : errors:: MustImplementNotFunctionNote { } ,
969- } ) ;
970- }
971- None => {
972- tcx. dcx ( ) . emit_err ( errors:: FunctionNotFoundInTrait { span : ident. span } ) ;
973- }
974- }
975-
976- Some ( ( ) )
977- } ) ;
978-
979- ( errors. count ( ) == 0 ) . then_some ( list)
980- } )
981- // Check for duplicates
982- . and_then ( |list| {
983- let mut set: UnordMap < Symbol , Span > = Default :: default ( ) ;
984- let mut no_dups = true ;
985-
986- for ident in & * list {
987- if let Some ( dup) = set. insert ( ident. name , ident. span ) {
988- tcx. dcx ( )
989- . emit_err ( errors:: FunctionNamesDuplicated { spans : vec ! [ dup, ident. span] } ) ;
990-
991- no_dups = false ;
992- }
993- }
994-
995- no_dups. then_some ( list)
996- } ) ;
919+ let must_implement_one_of = find_attr ! (
920+ attrs,
921+ AttributeKind :: RustcMustImplementOneOf { fn_names, .. } =>
922+ fn_names
923+ . iter( )
924+ . cloned( )
925+ . collect:: <Box <[ _] >>( )
926+ ) ;
997927
998928 let deny_explicit_impl = find_attr ! ( attrs, AttributeKind :: DenyExplicitImpl ( _) ) ;
999929 let implement_via_object = !find_attr ! ( attrs, AttributeKind :: DoNotImplementViaObject ( _) ) ;
0 commit comments