@@ -10,22 +10,35 @@ use rustc_session::lint::{self, Lint};
1010use rustc_span:: def_id:: DefId ;
1111use rustc_span:: { Ident , Span , Symbol } ;
1212
13- /// Emit diagnostic for calls to `#[inline(always)]`-annotated functions with a
14- /// `#[target_feature]` attribute where the caller enables a different set of target features.
15- pub ( crate ) fn emit_inline_always_target_feature_diagnostic < ' a , ' tcx > (
13+ /// Emit the `inline_always_mismatching_target_features` lint for a call to an
14+ /// `#[inline(always)]` function that cannot be inlined at the call site.
15+ ///
16+ /// This is used for both direct caller/callee target feature mismatches and
17+ /// vector ABI mismatches. `feature_source_def_id` identifies the side that
18+ /// contributes the missing features, while `feature_target_def_id` identifies
19+ /// the side that should be updated by the suggestion.
20+ pub ( crate ) fn emit_inline_always_target_feature_diagnostic < ' tcx > (
1621 tcx : TyCtxt < ' tcx > ,
1722 call_span : Span ,
1823 callee_def_id : DefId ,
1924 caller_def_id : DefId ,
20- callee_only : & [ & ' a str ] ,
25+ missing_features : & str ,
26+ feature_source_def_id : DefId ,
27+ feature_target_def_id : DefId ,
2128) {
2229 tcx. emit_node_span_lint (
2330 lint:: builtin:: INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES ,
2431 tcx. local_def_id_to_hir_id ( caller_def_id. as_local ( ) . unwrap ( ) ) ,
2532 call_span,
2633 rustc_errors:: DiagDecorator ( |lint| {
34+ // These calls to `tcx.def_path_str(...)` need to live inside this
35+ // closure otherwise can cause an ICE, see;
36+ // https://github.com/rust-lang/rust/pull/150805
2737 let callee = tcx. def_path_str ( callee_def_id) ;
28- let caller = tcx. def_path_str ( caller_def_id) ;
38+ let feature_target = tcx. def_path_str ( feature_target_def_id) ;
39+ let feature_source = tcx. def_path_str ( feature_source_def_id) ;
40+
41+ let suggested_features = missing_features. replace ( ", " , "," ) ;
2942
3043 lint. primary_message ( format ! (
3144 "call to `#[inline(always)]`-annotated `{callee}` \
@@ -34,17 +47,19 @@ pub(crate) fn emit_inline_always_target_feature_diagnostic<'a, 'tcx>(
3447 lint. note ( "function will not be inlined" ) ;
3548
3649 lint. note ( format ! (
37- "the following target features are on `{callee }` but missing from `{caller}`: {}" ,
38- callee_only . join ( ", " )
50+ "the following target features are on `{feature_source }` but missing from \
51+ `{feature_target}`: {missing_features}"
3952 ) ) ;
40- lint. span_note ( callee_def_id. default_span ( tcx) , format ! ( "`{callee}` is defined here" ) ) ;
53+ lint. span_note (
54+ feature_source_def_id. default_span ( tcx) ,
55+ format ! ( "`{feature_source}` is defined here" ) ,
56+ ) ;
4157
42- let feats = callee_only. join ( "," ) ;
4358 lint. span_suggestion (
44- tcx. def_span ( caller_def_id ) . shrink_to_lo ( ) ,
45- format ! ( "add `#[target_feature]` attribute to `{caller }`" ) ,
46- format ! ( "#[target_feature(enable = \" {feats }\" )]\n " ) ,
47- lint :: Applicability :: MaybeIncorrect ,
59+ tcx. def_span ( feature_target_def_id ) . shrink_to_lo ( ) ,
60+ format ! ( "add `#[target_feature]` attribute to `{feature_target }`" ) ,
61+ format ! ( "#[target_feature(enable = \" {suggested_features }\" )]\n " ) ,
62+ Applicability :: MaybeIncorrect ,
4863 ) ;
4964 } ) ,
5065 ) ;
0 commit comments