@@ -875,11 +875,10 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
875875 // There should only be one, since we generate a new placeholder per ad macro.
876876 // FIXME(ZuseZ4): re-enable this check. Currently we add multiple, which doesn't cause harm but
877877 // looks strange e.g. under cargo-expand.
878- let attr = match attrs. len ( ) {
879- 0 => return AutoDiffAttrs :: error ( ) ,
880- 1 => attrs . get ( 0 ) . unwrap ( ) ,
878+ let attr = match & attrs[ .. ] {
879+ [ ] => return AutoDiffAttrs :: error ( ) ,
880+ [ attr ] => attr ,
881881 _ => {
882- attrs. get ( 0 ) . unwrap ( )
883882 //FIXME(ZuseZ4): re-enable this check
884883 //span_bug!(attrs[1].span, "cg_ssa: rustc_autodiff should only exist once per source");
885884 }
@@ -908,7 +907,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
908907 "ForwardFirst" => DiffMode :: ForwardFirst ,
909908 "ReverseFirst" => DiffMode :: ReverseFirst ,
910909 _ => {
911- span_bug ! ( attr . span, "rustc_autodiff attribute contains invalid mode" ) ;
910+ span_bug ! ( mode . span, "rustc_autodiff attribute contains invalid mode" ) ;
912911 }
913912 } ;
914913
@@ -921,7 +920,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
921920
922921 // Then parse it into an actual DiffActivity
923922 let Ok ( ret_activity) = DiffActivity :: from_str ( ret_symbol. as_str ( ) ) else {
924- span_bug ! ( attr . span, "invalid return activity" ) ;
923+ span_bug ! ( ret_symbol . span, "invalid return activity" ) ;
925924 } ;
926925
927926 // Now parse all the intermediate (input) activities
@@ -932,19 +931,19 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> AutoDiffAttrs {
932931 Some ( x) => x. ident ,
933932 None => {
934933 span_bug ! (
935- attr . span,
934+ arg . span( ) ,
936935 "rustc_autodiff attribute must contain the input activity"
937936 ) ;
938937 }
939938 }
940939 } else {
941- span_bug ! ( attr . span, "rustc_autodiff attribute must contain the input activity" ) ;
940+ span_bug ! ( arg . span( ) , "rustc_autodiff attribute must contain the input activity" ) ;
942941 } ;
943942
944943 match DiffActivity :: from_str ( arg_symbol. as_str ( ) ) {
945944 Ok ( arg_activity) => arg_activities. push ( arg_activity) ,
946945 Err ( _) => {
947- span_bug ! ( attr . span, "invalid input activity" ) ;
946+ span_bug ! ( arg_symbol . span, "invalid input activity" ) ;
948947 }
949948 }
950949 }
0 commit comments