about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/check/check.rs
diff options
context:
space:
mode:
authorJubilee Young <workingjubilee@gmail.com>2025-06-09 15:36:48 -0700
committerJubilee Young <workingjubilee@gmail.com>2025-06-09 15:38:38 -0700
commit580a9555d51a5c8e29f4f27f652cf0d6700ea879 (patch)
treee33a1f0760db19eaaa550c9cfbd25a4276f7c8a1 /compiler/rustc_hir_analysis/src/check/check.rs
parentd13a431a6cc69cd65efe7c3eb7808251d6fd7a46 (diff)
downloadrust-580a9555d51a5c8e29f4f27f652cf0d6700ea879.tar.gz
rust-580a9555d51a5c8e29f4f27f652cf0d6700ea879.zip
compiler: Fix reusing same lint on fn ptrs with newly-deprecated ABIs
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check/check.rs')
-rw-r--r--compiler/rustc_hir_analysis/src/check/check.rs40
1 files changed, 24 insertions, 16 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs
index 064b42413f0..87fac985dcc 100644
--- a/compiler/rustc_hir_analysis/src/check/check.rs
+++ b/compiler/rustc_hir_analysis/src/check/check.rs
@@ -37,22 +37,23 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
 use super::compare_impl_item::check_type_bounds;
 use super::*;
 
+fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) {
+    if let ExternAbi::Cdecl { unwind } = abi {
+        let c_abi = ExternAbi::C { unwind };
+        diag.help(format!("use `extern {c_abi}` instead",));
+    } else if let ExternAbi::Stdcall { unwind } = abi {
+        let c_abi = ExternAbi::C { unwind };
+        let system_abi = ExternAbi::System { unwind };
+        diag.help(format!(
+            "if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
+                use `extern {system_abi}`"
+        ));
+    }
+}
+
 pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
     // FIXME: this should be checked earlier, e.g. in `rustc_ast_lowering`, to fix
     // things like #86232.
-    fn add_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) {
-        if let ExternAbi::Cdecl { unwind } = abi {
-            let c_abi = ExternAbi::C { unwind };
-            diag.help(format!("use `extern {c_abi}` instead",));
-        } else if let ExternAbi::Stdcall { unwind } = abi {
-            let c_abi = ExternAbi::C { unwind };
-            let system_abi = ExternAbi::System { unwind };
-            diag.help(format!(
-                "if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
-                use `extern {system_abi}`"
-            ));
-        }
-    }
 
     match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
         AbiMapping::Direct(..) => (),
@@ -63,13 +64,13 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi
                 E0570,
                 "`{abi}` is not a supported ABI for the current target",
             );
-            add_help(abi, &mut err);
+            add_abi_diag_help(abi, &mut err);
             err.emit();
         }
         AbiMapping::Deprecated(..) => {
             tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
                 lint.primary_message("use of calling convention not supported on this target");
-                add_help(abi, lint);
+                add_abi_diag_help(abi, lint);
             });
         }
     }
@@ -80,7 +81,14 @@ pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Ex
     // in `check_abi` above.
     match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
         AbiMapping::Direct(..) => (),
-        AbiMapping::Deprecated(..) | AbiMapping::Invalid => {
+        // this is not a redundant match arm: these ABIs started linting after reviving this lint
+        AbiMapping::Deprecated(..) => {
+            tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
+                lint.primary_message("use of calling convention not supported on this target");
+                add_abi_diag_help(abi, lint);
+            });
+        }
+        AbiMapping::Invalid => {
             tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
                 lint.primary_message(format!(
                     "the calling convention {abi} is not supported on this target"