@@ -2610,7 +2610,6 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind>
26102610
26112611fn from_target_feature (
26122612 tcx : TyCtxt < ' _ > ,
2613- id : DefId ,
26142613 attr : & ast:: Attribute ,
26152614 supported_target_features : & FxHashMap < String , Option < Symbol > > ,
26162615 target_features : & mut Vec < Symbol > ,
@@ -2679,7 +2678,7 @@ fn from_target_feature(
26792678 Some ( name) => bug ! ( "unknown target feature gate {}" , name) ,
26802679 None => true ,
26812680 } ;
2682- if !allowed && id . is_local ( ) {
2681+ if !allowed {
26832682 feature_err (
26842683 & tcx. sess . parse_sess ,
26852684 feature_gate. unwrap ( ) ,
@@ -2693,7 +2692,7 @@ fn from_target_feature(
26932692 }
26942693}
26952694
2696- fn linkage_by_name ( tcx : TyCtxt < ' _ > , def_id : DefId , name : & str ) -> Linkage {
2695+ fn linkage_by_name ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , name : & str ) -> Linkage {
26972696 use rustc_middle:: mir:: mono:: Linkage :: * ;
26982697
26992698 // Use the names from src/llvm/docs/LangRef.rst here. Most types are only
@@ -2716,36 +2715,28 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Linkage {
27162715 "private" => Private ,
27172716 "weak" => WeakAny ,
27182717 "weak_odr" => WeakODR ,
2719- _ => {
2720- let span = tcx. hir ( ) . span_if_local ( def_id) ;
2721- if let Some ( span) = span {
2722- tcx. sess . span_fatal ( span, "invalid linkage specified" )
2723- } else {
2724- tcx. sess . fatal ( & format ! ( "invalid linkage specified: {}" , name) )
2725- }
2726- }
2718+ _ => tcx. sess . span_fatal ( tcx. def_span ( def_id) , "invalid linkage specified" ) ,
27272719 }
27282720}
2729-
2730- fn codegen_fn_attrs ( tcx : TyCtxt < ' _ > , id : DefId ) -> CodegenFnAttrs {
2731- let attrs = tcx. get_attrs ( id) ;
2732-
2721+ fn codegen_fn_attrs ( tcx : TyCtxt < ' _ > , did : DefId ) -> CodegenFnAttrs {
2722+ let did = did. expect_local ( ) ;
2723+ let attrs = tcx. hir ( ) . attrs ( tcx. hir ( ) . local_def_id_to_hir_id ( did) ) ;
27332724 let mut codegen_fn_attrs = CodegenFnAttrs :: new ( ) ;
2734- if tcx. should_inherit_track_caller ( id ) {
2725+ if tcx. should_inherit_track_caller ( did ) {
27352726 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: TRACK_CALLER ;
27362727 }
27372728
27382729 // With -Z panic-in-drop=abort, drop_in_place never unwinds.
27392730 if tcx. sess . opts . debugging_opts . panic_in_drop == PanicStrategy :: Abort {
2740- if Some ( id ) == tcx. lang_items ( ) . drop_in_place_fn ( ) {
2731+ if Some ( did . to_def_id ( ) ) == tcx. lang_items ( ) . drop_in_place_fn ( ) {
27412732 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NEVER_UNWIND ;
27422733 }
27432734 }
27442735
27452736 // The panic_no_unwind function called by TerminatorKind::Abort will never
27462737 // unwind. If the panic handler that it invokes unwind then it will simply
27472738 // call the panic handler again.
2748- if Some ( id ) == tcx. lang_items ( ) . panic_no_unwind ( ) {
2739+ if Some ( did . to_def_id ( ) ) == tcx. lang_items ( ) . panic_no_unwind ( ) {
27492740 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NEVER_UNWIND ;
27502741 }
27512742
@@ -2760,7 +2751,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27602751 } else if attr. has_name ( sym:: rustc_allocator) {
27612752 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: ALLOCATOR ;
27622753 } else if attr. has_name ( sym:: ffi_returns_twice) {
2763- if tcx. is_foreign_item ( id ) {
2754+ if tcx. is_foreign_item ( did ) {
27642755 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: FFI_RETURNS_TWICE ;
27652756 } else {
27662757 // `#[ffi_returns_twice]` is only allowed `extern fn`s.
@@ -2773,7 +2764,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27732764 . emit ( ) ;
27742765 }
27752766 } else if attr. has_name ( sym:: ffi_pure) {
2776- if tcx. is_foreign_item ( id ) {
2767+ if tcx. is_foreign_item ( did ) {
27772768 if attrs. iter ( ) . any ( |a| a. has_name ( sym:: ffi_const) ) {
27782769 // `#[ffi_const]` functions cannot be `#[ffi_pure]`
27792770 struct_span_err ! (
@@ -2797,7 +2788,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27972788 . emit ( ) ;
27982789 }
27992790 } else if attr. has_name ( sym:: ffi_const) {
2800- if tcx. is_foreign_item ( id ) {
2791+ if tcx. is_foreign_item ( did ) {
28012792 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: FFI_CONST ;
28022793 } else {
28032794 // `#[ffi_const]` is only allowed on foreign functions
@@ -2857,7 +2848,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
28572848 None => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: USED ,
28582849 }
28592850 } else if attr. has_name ( sym:: cmse_nonsecure_entry) {
2860- if !matches ! ( tcx. fn_sig( id ) . abi( ) , abi:: Abi :: C { .. } ) {
2851+ if !matches ! ( tcx. fn_sig( did ) . abi( ) , abi:: Abi :: C { .. } ) {
28612852 struct_span_err ! (
28622853 tcx. sess,
28632854 attr. span,
@@ -2874,11 +2865,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
28742865 } else if attr. has_name ( sym:: thread_local) {
28752866 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: THREAD_LOCAL ;
28762867 } else if attr. has_name ( sym:: track_caller) {
2877- if !tcx. is_closure ( id ) && tcx. fn_sig ( id ) . abi ( ) != abi:: Abi :: Rust {
2868+ if !tcx. is_closure ( did . to_def_id ( ) ) && tcx. fn_sig ( did ) . abi ( ) != abi:: Abi :: Rust {
28782869 struct_span_err ! ( tcx. sess, attr. span, E0737 , "`#[track_caller]` requires Rust ABI" )
28792870 . emit ( ) ;
28802871 }
2881- if tcx. is_closure ( id ) && !tcx. features ( ) . closure_track_caller {
2872+ if tcx. is_closure ( did . to_def_id ( ) ) && !tcx. features ( ) . closure_track_caller {
28822873 feature_err (
28832874 & tcx. sess . parse_sess ,
28842875 sym:: closure_track_caller,
@@ -2904,7 +2895,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29042895 codegen_fn_attrs. export_name = Some ( s) ;
29052896 }
29062897 } else if attr. has_name ( sym:: target_feature) {
2907- if !tcx. is_closure ( id) && tcx. fn_sig ( id) . unsafety ( ) == hir:: Unsafety :: Normal {
2898+ if !tcx. is_closure ( did. to_def_id ( ) )
2899+ && tcx. fn_sig ( did) . unsafety ( ) == hir:: Unsafety :: Normal
2900+ {
29082901 if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
29092902 // The `#[target_feature]` attribute is allowed on
29102903 // WebAssembly targets on all functions, including safe
@@ -2930,22 +2923,21 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
29302923 attr. span ,
29312924 "`#[target_feature(..)]` can only be applied to `unsafe` functions" ,
29322925 ) ;
2933- err. span_label ( tcx. def_span ( id ) , "not an `unsafe` function" ) ;
2926+ err. span_label ( tcx. def_span ( did ) , "not an `unsafe` function" ) ;
29342927 err. emit ( ) ;
2935- } else if let Some ( local_id ) = id . as_local ( ) {
2936- check_target_feature_trait_unsafe ( tcx, local_id , attr. span ) ;
2928+ } else {
2929+ check_target_feature_trait_unsafe ( tcx, did , attr. span ) ;
29372930 }
29382931 }
29392932 from_target_feature (
29402933 tcx,
2941- id,
29422934 attr,
29432935 supported_target_features,
29442936 & mut codegen_fn_attrs. target_features ,
29452937 ) ;
29462938 } else if attr. has_name ( sym:: linkage) {
29472939 if let Some ( val) = attr. value_str ( ) {
2948- codegen_fn_attrs. linkage = Some ( linkage_by_name ( tcx, id , val. as_str ( ) ) ) ;
2940+ codegen_fn_attrs. linkage = Some ( linkage_by_name ( tcx, did , val. as_str ( ) ) ) ;
29492941 }
29502942 } else if attr. has_name ( sym:: link_section) {
29512943 if let Some ( val) = attr. value_str ( ) {
@@ -3161,8 +3153,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
31613153 } ) ;
31623154
31633155 // #73631: closures inherit `#[target_feature]` annotations
3164- if tcx. features ( ) . target_feature_11 && tcx. is_closure ( id ) {
3165- let owner_id = tcx. parent ( id ) ;
3156+ if tcx. features ( ) . target_feature_11 && tcx. is_closure ( did . to_def_id ( ) ) {
3157+ let owner_id = tcx. parent ( did . to_def_id ( ) ) ;
31663158 codegen_fn_attrs
31673159 . target_features
31683160 . extend ( tcx. codegen_fn_attrs ( owner_id) . target_features . iter ( ) . copied ( ) )
@@ -3187,7 +3179,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
31873179 if !codegen_fn_attrs. no_sanitize . is_empty ( ) {
31883180 if codegen_fn_attrs. inline == InlineAttr :: Always {
31893181 if let ( Some ( no_sanitize_span) , Some ( inline_span) ) = ( no_sanitize_span, inline_span) {
3190- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( id . expect_local ( ) ) ;
3182+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( did ) ;
31913183 tcx. struct_span_lint_hir (
31923184 lint:: builtin:: INLINE_NO_SANITIZE ,
31933185 hir_id,
@@ -3207,7 +3199,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
32073199 // strippable by the linker.
32083200 //
32093201 // Additionally weak lang items have predetermined symbol names.
3210- if tcx. is_weak_lang_item ( id ) {
3202+ if tcx. is_weak_lang_item ( did . to_def_id ( ) ) {
32113203 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ;
32123204 }
32133205 if let Some ( name) = weak_lang_items:: link_name ( attrs) {
0 commit comments