@@ -2610,7 +2610,6 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind>
2610
2610
2611
2611
fn from_target_feature (
2612
2612
tcx : TyCtxt < ' _ > ,
2613
- id : DefId ,
2614
2613
attr : & ast:: Attribute ,
2615
2614
supported_target_features : & FxHashMap < String , Option < Symbol > > ,
2616
2615
target_features : & mut Vec < Symbol > ,
@@ -2679,7 +2678,7 @@ fn from_target_feature(
2679
2678
Some ( name) => bug ! ( "unknown target feature gate {}" , name) ,
2680
2679
None => true ,
2681
2680
} ;
2682
- if !allowed && id . is_local ( ) {
2681
+ if !allowed {
2683
2682
feature_err (
2684
2683
& tcx. sess . parse_sess ,
2685
2684
feature_gate. unwrap ( ) ,
@@ -2693,7 +2692,7 @@ fn from_target_feature(
2693
2692
}
2694
2693
}
2695
2694
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 {
2697
2696
use rustc_middle:: mir:: mono:: Linkage :: * ;
2698
2697
2699
2698
// 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 {
2716
2715
"private" => Private ,
2717
2716
"weak" => WeakAny ,
2718
2717
"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" ) ,
2727
2719
}
2728
2720
}
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) ) ;
2733
2724
let mut codegen_fn_attrs = CodegenFnAttrs :: new ( ) ;
2734
- if tcx. should_inherit_track_caller ( id ) {
2725
+ if tcx. should_inherit_track_caller ( did ) {
2735
2726
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: TRACK_CALLER ;
2736
2727
}
2737
2728
2738
2729
// With -Z panic-in-drop=abort, drop_in_place never unwinds.
2739
2730
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 ( ) {
2741
2732
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NEVER_UNWIND ;
2742
2733
}
2743
2734
}
2744
2735
2745
2736
// The panic_no_unwind function called by TerminatorKind::Abort will never
2746
2737
// unwind. If the panic handler that it invokes unwind then it will simply
2747
2738
// 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 ( ) {
2749
2740
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NEVER_UNWIND ;
2750
2741
}
2751
2742
@@ -2760,7 +2751,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2760
2751
} else if attr. has_name ( sym:: rustc_allocator) {
2761
2752
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: ALLOCATOR ;
2762
2753
} else if attr. has_name ( sym:: ffi_returns_twice) {
2763
- if tcx. is_foreign_item ( id ) {
2754
+ if tcx. is_foreign_item ( did ) {
2764
2755
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: FFI_RETURNS_TWICE ;
2765
2756
} else {
2766
2757
// `#[ffi_returns_twice]` is only allowed `extern fn`s.
@@ -2773,7 +2764,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2773
2764
. emit ( ) ;
2774
2765
}
2775
2766
} else if attr. has_name ( sym:: ffi_pure) {
2776
- if tcx. is_foreign_item ( id ) {
2767
+ if tcx. is_foreign_item ( did ) {
2777
2768
if attrs. iter ( ) . any ( |a| a. has_name ( sym:: ffi_const) ) {
2778
2769
// `#[ffi_const]` functions cannot be `#[ffi_pure]`
2779
2770
struct_span_err ! (
@@ -2797,7 +2788,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2797
2788
. emit ( ) ;
2798
2789
}
2799
2790
} else if attr. has_name ( sym:: ffi_const) {
2800
- if tcx. is_foreign_item ( id ) {
2791
+ if tcx. is_foreign_item ( did ) {
2801
2792
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: FFI_CONST ;
2802
2793
} else {
2803
2794
// `#[ffi_const]` is only allowed on foreign functions
@@ -2857,7 +2848,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2857
2848
None => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: USED ,
2858
2849
}
2859
2850
} 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 { .. } ) {
2861
2852
struct_span_err ! (
2862
2853
tcx. sess,
2863
2854
attr. span,
@@ -2874,11 +2865,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2874
2865
} else if attr. has_name ( sym:: thread_local) {
2875
2866
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: THREAD_LOCAL ;
2876
2867
} 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 {
2878
2869
struct_span_err ! ( tcx. sess, attr. span, E0737 , "`#[track_caller]` requires Rust ABI" )
2879
2870
. emit ( ) ;
2880
2871
}
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 {
2882
2873
feature_err (
2883
2874
& tcx. sess . parse_sess ,
2884
2875
sym:: closure_track_caller,
@@ -2904,7 +2895,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2904
2895
codegen_fn_attrs. export_name = Some ( s) ;
2905
2896
}
2906
2897
} 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
+ {
2908
2901
if tcx. sess . target . is_like_wasm || tcx. sess . opts . actually_rustdoc {
2909
2902
// The `#[target_feature]` attribute is allowed on
2910
2903
// WebAssembly targets on all functions, including safe
@@ -2930,22 +2923,21 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
2930
2923
attr. span ,
2931
2924
"`#[target_feature(..)]` can only be applied to `unsafe` functions" ,
2932
2925
) ;
2933
- err. span_label ( tcx. def_span ( id ) , "not an `unsafe` function" ) ;
2926
+ err. span_label ( tcx. def_span ( did ) , "not an `unsafe` function" ) ;
2934
2927
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 ) ;
2937
2930
}
2938
2931
}
2939
2932
from_target_feature (
2940
2933
tcx,
2941
- id,
2942
2934
attr,
2943
2935
supported_target_features,
2944
2936
& mut codegen_fn_attrs. target_features ,
2945
2937
) ;
2946
2938
} else if attr. has_name ( sym:: linkage) {
2947
2939
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 ( ) ) ) ;
2949
2941
}
2950
2942
} else if attr. has_name ( sym:: link_section) {
2951
2943
if let Some ( val) = attr. value_str ( ) {
@@ -3161,8 +3153,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
3161
3153
} ) ;
3162
3154
3163
3155
// #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 ( ) ) ;
3166
3158
codegen_fn_attrs
3167
3159
. target_features
3168
3160
. extend ( tcx. codegen_fn_attrs ( owner_id) . target_features . iter ( ) . copied ( ) )
@@ -3187,7 +3179,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
3187
3179
if !codegen_fn_attrs. no_sanitize . is_empty ( ) {
3188
3180
if codegen_fn_attrs. inline == InlineAttr :: Always {
3189
3181
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 ) ;
3191
3183
tcx. struct_span_lint_hir (
3192
3184
lint:: builtin:: INLINE_NO_SANITIZE ,
3193
3185
hir_id,
@@ -3207,7 +3199,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
3207
3199
// strippable by the linker.
3208
3200
//
3209
3201
// 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 ( ) ) {
3211
3203
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ;
3212
3204
}
3213
3205
if let Some ( name) = weak_lang_items:: link_name ( attrs) {
0 commit comments