Skip to content

Commit 7a03d0b

Browse files
compiler: Avoid double-errors on ABIs during hir_analysis
1 parent 19eb44c commit 7a03d0b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,13 +1621,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
16211621

16221622
// we can't do codegen for unsupported ABIs, so error now so we won't get farther
16231623
if !tcx.sess.target.is_abi_supported(extern_abi) {
1624-
struct_span_code_err!(
1624+
let mut err = struct_span_code_err!(
16251625
tcx.dcx(),
16261626
span,
16271627
E0570,
16281628
"`{extern_abi}` is not a supported ABI for the current target",
1629-
)
1630-
.emit();
1629+
);
1630+
1631+
if let ExternAbi::Stdcall { unwind } = extern_abi {
1632+
let c_abi = ExternAbi::C { unwind };
1633+
let system_abi = ExternAbi::System { unwind };
1634+
err.help(format!("if you need `extern {extern_abi}` on win32 and `extern {c_abi}` everywhere else, \
1635+
use `extern {system_abi}`"
1636+
));
1637+
}
1638+
err.emit();
16311639
}
16321640
// stability gate even things that are already errored on
16331641
gate_unstable_abi(tcx.sess, tcx.features(), span, extern_abi);

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,8 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi
5656

5757
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) {
5858
AbiMapping::Direct(..) => (),
59-
AbiMapping::Invalid => {
60-
let mut err = struct_span_code_err!(
61-
tcx.dcx(),
62-
span,
63-
E0570,
64-
"`{abi}` is not a supported ABI for the current target",
65-
);
66-
add_help(abi, &mut err);
67-
err.emit();
68-
}
59+
// already erred in rustc_ast_lowering
60+
AbiMapping::Invalid => (),
6961
AbiMapping::Deprecated(..) => {
7062
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
7163
lint.primary_message("use of calling convention not supported on this target");

0 commit comments

Comments
 (0)