@@ -457,6 +457,12 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
457457 err_span,
458458 ) ;
459459 }
460+
461+ fn crate_inject_span ( & self ) -> Option < Span > {
462+ self . tcx . hir_crate_items ( ( ) ) . definitions ( ) . next ( ) . and_then ( |id| {
463+ self . tcx . crate_level_attribute_injection_span ( self . tcx . local_def_id_to_hir_id ( id) )
464+ } )
465+ }
460466}
461467
462468impl < ' tcx > Visitor < ' tcx > for Checker < ' _ , ' tcx > {
@@ -799,17 +805,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
799805 feature,
800806 ..
801807 } ) => {
802- let suggestion =
803- tcx. hir_crate_items ( ( ) ) . definitions ( ) . next ( ) . and_then ( |id| {
804- tcx. crate_level_attribute_injection_span (
805- tcx. local_def_id_to_hir_id ( id) ,
806- )
807- } ) ;
808808 self . check_op ( ops:: IntrinsicUnstable {
809809 name : intrinsic. name ,
810810 feature,
811811 const_stable_indirect : is_const_stable,
812- suggestion,
812+ suggestion : self . crate_inject_span ( ) ,
813813 } ) ;
814814 }
815815 Some ( ConstStability { level : StabilityLevel :: Stable { .. } , .. } ) => {
@@ -903,18 +903,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
903903 // Even if the feature is enabled, we still need check_op to double-check
904904 // this if the callee is not safe to expose on stable.
905905 if !feature_enabled || !callee_safe_to_expose_on_stable {
906- let suggestion_span =
907- tcx. hir_crate_items ( ( ) ) . definitions ( ) . next ( ) . and_then ( |id| {
908- tcx. crate_level_attribute_injection_span (
909- tcx. local_def_id_to_hir_id ( id) ,
910- )
911- } ) ;
912906 self . check_op ( ops:: FnCallUnstable {
913907 def_id : callee,
914908 feature,
915909 feature_enabled,
916910 safe_to_expose_on_stable : callee_safe_to_expose_on_stable,
917- suggestion_span,
911+ suggestion_span : self . crate_inject_span ( ) ,
918912 } ) ;
919913 }
920914 }
0 commit comments