Skip to content

Commit cf20f7b

Browse files
committed
add specific help messages for stdcall and cdecl
1 parent 6c2a1a9 commit cf20f7b

File tree

7 files changed

+67
-4
lines changed

7 files changed

+67
-4
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::ops::ControlFlow;
44
use rustc_abi::FieldIdx;
55
use rustc_attr_data_structures::ReprAttr::ReprPacked;
66
use rustc_data_structures::unord::{UnordMap, UnordSet};
7-
use rustc_errors::MultiSpan;
87
use rustc_errors::codes::*;
8+
use rustc_errors::{EmissionGuarantee, MultiSpan};
99
use rustc_hir::def::{CtorKind, DefKind};
1010
use rustc_hir::{LangItem, Node, intravisit};
1111
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
@@ -37,20 +37,33 @@ use super::compare_impl_item::check_type_bounds;
3737
use super::*;
3838

3939
pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
40+
fn add_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) {
41+
if let ExternAbi::Cdecl { unwind } = abi {
42+
let suffix = if unwind { "-unwind" } else { "" };
43+
diag.help(format!("use `extern \"C{suffix}\"` instead",));
44+
} else if let ExternAbi::Stdcall { unwind } = abi {
45+
let suffix = if unwind { "-unwind" } else { "" };
46+
diag.help(format!(
47+
"if you need `extern \"stdcall{suffix}\"` on win32 and `extern \"C{suffix}\"` everywhere else, use `extern \"system{suffix}\"`"
48+
));
49+
}
50+
}
4051
match tcx.sess.target.is_abi_supported(abi) {
4152
Some(true) => (),
4253
Some(false) => {
43-
struct_span_code_err!(
54+
let mut err = struct_span_code_err!(
4455
tcx.dcx(),
4556
span,
4657
E0570,
4758
"`{abi}` is not a supported ABI for the current target",
48-
)
49-
.emit();
59+
);
60+
add_help(abi, &mut err);
61+
err.emit();
5062
}
5163
None => {
5264
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
5365
lint.primary_message("use of calling convention not supported on this target");
66+
add_help(abi, lint);
5467
});
5568
}
5669
}

tests/ui/abi/unsupported.aarch64.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
118118
|
119119
LL | extern "stdcall" {}
120120
| ^^^^^^^^^^^^^^^^^^^
121+
|
122+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
121123

122124
warning: the calling convention "cdecl" is not supported on this target
123125
--> $DIR/unsupported.rs:125:17
@@ -136,6 +138,7 @@ LL | extern "cdecl" {}
136138
|
137139
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
138140
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
141+
= help: use `extern "C"` instead
139142
= note: `#[warn(unsupported_calling_conventions)]` on by default
140143

141144
warning: the calling convention "vectorcall" is not supported on this target
@@ -230,6 +233,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
230233
|
231234
LL | extern "stdcall" fn stdcall() {}
232235
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236+
|
237+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
233238

234239
warning: use of calling convention not supported on this target
235240
--> $DIR/unsupported.rs:122:1
@@ -239,6 +244,7 @@ LL | extern "cdecl" fn cdecl() {}
239244
|
240245
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
241246
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
247+
= help: use `extern "C"` instead
242248

243249
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
244250
--> $DIR/unsupported.rs:134:1
@@ -363,6 +369,7 @@ LL | extern "cdecl" {}
363369
|
364370
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
365371
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
372+
= help: use `extern "C"` instead
366373
= note: `#[warn(unsupported_calling_conventions)]` on by default
367374

368375
Future breakage diagnostic:
@@ -407,5 +414,6 @@ LL | extern "cdecl" fn cdecl() {}
407414
|
408415
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
409416
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
417+
= help: use `extern "C"` instead
410418
= note: `#[warn(unsupported_calling_conventions)]` on by default
411419

tests/ui/abi/unsupported.arm.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
103103
|
104104
LL | extern "stdcall" {}
105105
| ^^^^^^^^^^^^^^^^^^^
106+
|
107+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
106108

107109
warning: the calling convention "cdecl" is not supported on this target
108110
--> $DIR/unsupported.rs:125:17
@@ -121,6 +123,7 @@ LL | extern "cdecl" {}
121123
|
122124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123125
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
126+
= help: use `extern "C"` instead
124127
= note: `#[warn(unsupported_calling_conventions)]` on by default
125128

126129
warning: the calling convention "vectorcall" is not supported on this target
@@ -209,6 +212,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
209212
|
210213
LL | extern "stdcall" fn stdcall() {}
211214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215+
|
216+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
212217

213218
warning: use of calling convention not supported on this target
214219
--> $DIR/unsupported.rs:122:1
@@ -218,6 +223,7 @@ LL | extern "cdecl" fn cdecl() {}
218223
|
219224
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220225
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
226+
= help: use `extern "C"` instead
221227

222228
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
223229
--> $DIR/unsupported.rs:134:1
@@ -331,6 +337,7 @@ LL | extern "cdecl" {}
331337
|
332338
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
333339
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
340+
= help: use `extern "C"` instead
334341
= note: `#[warn(unsupported_calling_conventions)]` on by default
335342

336343
Future breakage diagnostic:
@@ -375,5 +382,6 @@ LL | extern "cdecl" fn cdecl() {}
375382
|
376383
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
377384
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
385+
= help: use `extern "C"` instead
378386
= note: `#[warn(unsupported_calling_conventions)]` on by default
379387

tests/ui/abi/unsupported.riscv32.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
103103
|
104104
LL | extern "stdcall" {}
105105
| ^^^^^^^^^^^^^^^^^^^
106+
|
107+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
106108

107109
warning: the calling convention "cdecl" is not supported on this target
108110
--> $DIR/unsupported.rs:125:17
@@ -121,6 +123,7 @@ LL | extern "cdecl" {}
121123
|
122124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123125
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
126+
= help: use `extern "C"` instead
124127
= note: `#[warn(unsupported_calling_conventions)]` on by default
125128

126129
warning: the calling convention "vectorcall" is not supported on this target
@@ -209,6 +212,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
209212
|
210213
LL | extern "stdcall" fn stdcall() {}
211214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215+
|
216+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
212217

213218
warning: use of calling convention not supported on this target
214219
--> $DIR/unsupported.rs:122:1
@@ -218,6 +223,7 @@ LL | extern "cdecl" fn cdecl() {}
218223
|
219224
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220225
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
226+
= help: use `extern "C"` instead
221227

222228
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
223229
--> $DIR/unsupported.rs:134:1
@@ -331,6 +337,7 @@ LL | extern "cdecl" {}
331337
|
332338
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
333339
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
340+
= help: use `extern "C"` instead
334341
= note: `#[warn(unsupported_calling_conventions)]` on by default
335342

336343
Future breakage diagnostic:
@@ -375,5 +382,6 @@ LL | extern "cdecl" fn cdecl() {}
375382
|
376383
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
377384
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
385+
= help: use `extern "C"` instead
378386
= note: `#[warn(unsupported_calling_conventions)]` on by default
379387

tests/ui/abi/unsupported.riscv64.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
103103
|
104104
LL | extern "stdcall" {}
105105
| ^^^^^^^^^^^^^^^^^^^
106+
|
107+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
106108

107109
warning: the calling convention "cdecl" is not supported on this target
108110
--> $DIR/unsupported.rs:125:17
@@ -121,6 +123,7 @@ LL | extern "cdecl" {}
121123
|
122124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123125
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
126+
= help: use `extern "C"` instead
124127
= note: `#[warn(unsupported_calling_conventions)]` on by default
125128

126129
warning: the calling convention "vectorcall" is not supported on this target
@@ -209,6 +212,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
209212
|
210213
LL | extern "stdcall" fn stdcall() {}
211214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215+
|
216+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
212217

213218
warning: use of calling convention not supported on this target
214219
--> $DIR/unsupported.rs:122:1
@@ -218,6 +223,7 @@ LL | extern "cdecl" fn cdecl() {}
218223
|
219224
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220225
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
226+
= help: use `extern "C"` instead
221227

222228
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
223229
--> $DIR/unsupported.rs:134:1
@@ -331,6 +337,7 @@ LL | extern "cdecl" {}
331337
|
332338
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
333339
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
340+
= help: use `extern "C"` instead
334341
= note: `#[warn(unsupported_calling_conventions)]` on by default
335342

336343
Future breakage diagnostic:
@@ -375,5 +382,6 @@ LL | extern "cdecl" fn cdecl() {}
375382
|
376383
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
377384
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
385+
= help: use `extern "C"` instead
378386
= note: `#[warn(unsupported_calling_conventions)]` on by default
379387

tests/ui/abi/unsupported.x64.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
103103
|
104104
LL | extern "stdcall" {}
105105
| ^^^^^^^^^^^^^^^^^^^
106+
|
107+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
106108

107109
warning: the calling convention "cdecl" is not supported on this target
108110
--> $DIR/unsupported.rs:125:17
@@ -121,6 +123,7 @@ LL | extern "cdecl" {}
121123
|
122124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123125
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
126+
= help: use `extern "C"` instead
124127
= note: `#[warn(unsupported_calling_conventions)]` on by default
125128

126129
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
@@ -194,6 +197,8 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
194197
|
195198
LL | extern "stdcall" fn stdcall() {}
196199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200+
|
201+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
197202

198203
warning: use of calling convention not supported on this target
199204
--> $DIR/unsupported.rs:122:1
@@ -203,6 +208,7 @@ LL | extern "cdecl" fn cdecl() {}
203208
|
204209
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
205210
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
211+
= help: use `extern "C"` instead
206212

207213
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
208214
--> $DIR/unsupported.rs:150:1
@@ -310,6 +316,7 @@ LL | extern "cdecl" {}
310316
|
311317
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
312318
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
319+
= help: use `extern "C"` instead
313320
= note: `#[warn(unsupported_calling_conventions)]` on by default
314321

315322
Future breakage diagnostic:
@@ -343,5 +350,6 @@ LL | extern "cdecl" fn cdecl() {}
343350
|
344351
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
345352
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
353+
= help: use `extern "C"` instead
346354
= note: `#[warn(unsupported_calling_conventions)]` on by default
347355

tests/ui/abi/unsupported.x64_win.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ LL | extern "stdcall" {}
106106
|
107107
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
108108
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
109+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
109110
= note: `#[warn(unsupported_calling_conventions)]` on by default
110111

111112
warning: the calling convention "cdecl" is not supported on this target
@@ -125,6 +126,7 @@ LL | extern "cdecl" {}
125126
|
126127
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
127128
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
129+
= help: use `extern "C"` instead
128130

129131
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
130132
--> $DIR/unsupported.rs:144:21
@@ -158,6 +160,7 @@ LL | extern "cdecl" {}
158160
|
159161
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
160162
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
163+
= help: use `extern "C"` instead
161164

162165
error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target
163166
--> $DIR/unsupported.rs:36:1
@@ -209,6 +212,7 @@ LL | extern "stdcall" fn stdcall() {}
209212
|
210213
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
211214
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
215+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
212216

213217
warning: use of calling convention not supported on this target
214218
--> $DIR/unsupported.rs:122:1
@@ -218,6 +222,7 @@ LL | extern "cdecl" fn cdecl() {}
218222
|
219223
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220224
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
225+
= help: use `extern "C"` instead
221226

222227
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
223228
--> $DIR/unsupported.rs:150:1
@@ -314,6 +319,7 @@ LL | extern "stdcall" {}
314319
|
315320
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
316321
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
322+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
317323
= note: `#[warn(unsupported_calling_conventions)]` on by default
318324

319325
Future breakage diagnostic:
@@ -336,6 +342,7 @@ LL | extern "cdecl" {}
336342
|
337343
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
338344
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
345+
= help: use `extern "C"` instead
339346
= note: `#[warn(unsupported_calling_conventions)]` on by default
340347

341348
Future breakage diagnostic:
@@ -369,6 +376,7 @@ LL | extern "cdecl" {}
369376
|
370377
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
371378
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
379+
= help: use `extern "C"` instead
372380
= note: `#[warn(unsupported_calling_conventions)]` on by default
373381

374382
Future breakage diagnostic:
@@ -380,6 +388,7 @@ LL | extern "stdcall" fn stdcall() {}
380388
|
381389
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
382390
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
391+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
383392
= note: `#[warn(unsupported_calling_conventions)]` on by default
384393

385394
Future breakage diagnostic:
@@ -391,5 +400,6 @@ LL | extern "cdecl" fn cdecl() {}
391400
|
392401
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
393402
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
403+
= help: use `extern "C"` instead
394404
= note: `#[warn(unsupported_calling_conventions)]` on by default
395405

0 commit comments

Comments
 (0)