Skip to content

Commit deba33e

Browse files
committed
add specific help messages for stdcall and cdecl
1 parent efb01db commit deba33e

File tree

9 files changed

+372
-106
lines changed

9 files changed

+372
-106
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 19 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,35 @@ 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 c_abi = ExternAbi::C { unwind };
43+
diag.help(format!("use `extern {c_abi}` instead",));
44+
} else if let ExternAbi::Stdcall { unwind } = abi {
45+
let c_abi = ExternAbi::C { unwind };
46+
let system_abi = ExternAbi::System { unwind };
47+
diag.help(format!(
48+
"if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
49+
use `extern {system_abi}`"
50+
));
51+
}
52+
}
4053
match tcx.sess.target.is_abi_supported(abi) {
4154
Some(true) => (),
4255
Some(false) => {
43-
struct_span_code_err!(
56+
let mut err = struct_span_code_err!(
4457
tcx.dcx(),
4558
span,
4659
E0570,
4760
"`{abi}` is not a supported ABI for the current target",
48-
)
49-
.emit();
61+
);
62+
add_help(abi, &mut err);
63+
err.emit();
5064
}
5165
None => {
5266
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
5367
lint.primary_message("use of calling convention not supported on this target");
68+
add_help(abi, lint);
5469
});
5570
}
5671
}

tests/ui/abi/unsupported.aarch64.stderr

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,19 @@ 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"`
123+
124+
error[E0570]: `"stdcall-unwind"` is not a supported ABI for the current target
125+
--> $DIR/unsupported.rs:121:1
126+
|
127+
LL | extern "stdcall-unwind" {}
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
129+
|
130+
= help: if you need `extern "stdcall-unwind"` on win32 and `extern "C-unwind"` everywhere else, use `extern "system-unwind"`
121131

122132
warning: the calling convention "cdecl" is not supported on this target
123-
--> $DIR/unsupported.rs:125:17
133+
--> $DIR/unsupported.rs:129:17
124134
|
125135
LL | fn cdecl_ptr(f: extern "cdecl" fn()) {
126136
| ^^^^^^^^^^^^^^^^^^^
@@ -129,17 +139,28 @@ LL | fn cdecl_ptr(f: extern "cdecl" fn()) {
129139
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
130140

131141
warning: use of calling convention not supported on this target
132-
--> $DIR/unsupported.rs:130:1
142+
--> $DIR/unsupported.rs:134:1
133143
|
134144
LL | extern "cdecl" {}
135145
| ^^^^^^^^^^^^^^^^^
136146
|
137147
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
138148
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
149+
= help: use `extern "C"` instead
139150
= note: `#[warn(unsupported_calling_conventions)]` on by default
140151

152+
warning: use of calling convention not supported on this target
153+
--> $DIR/unsupported.rs:137:1
154+
|
155+
LL | extern "cdecl-unwind" {}
156+
| ^^^^^^^^^^^^^^^^^^^^^^^^
157+
|
158+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
159+
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
160+
= help: use `extern "C-unwind"` instead
161+
141162
warning: the calling convention "vectorcall" is not supported on this target
142-
--> $DIR/unsupported.rs:136:22
163+
--> $DIR/unsupported.rs:143:22
143164
|
144165
LL | fn vectorcall_ptr(f: extern "vectorcall" fn()) {
145166
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -148,13 +169,13 @@ LL | fn vectorcall_ptr(f: extern "vectorcall" fn()) {
148169
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
149170

150171
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
151-
--> $DIR/unsupported.rs:141:1
172+
--> $DIR/unsupported.rs:148:1
152173
|
153174
LL | extern "vectorcall" {}
154175
| ^^^^^^^^^^^^^^^^^^^^^^
155176

156177
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
157-
--> $DIR/unsupported.rs:144:21
178+
--> $DIR/unsupported.rs:151:21
158179
|
159180
LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
160181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -163,7 +184,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
163184
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
164185

165186
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
166-
--> $DIR/unsupported.rs:152:22
187+
--> $DIR/unsupported.rs:159:22
167188
|
168189
LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
169190
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -172,7 +193,7 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
172193
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
173194

174195
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
175-
--> $DIR/unsupported.rs:157:1
196+
--> $DIR/unsupported.rs:164:1
176197
|
177198
LL | extern "C-cmse-nonsecure-entry" {}
178199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -230,29 +251,32 @@ error[E0570]: `"stdcall"` is not a supported ABI for the current target
230251
|
231252
LL | extern "stdcall" fn stdcall() {}
232253
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254+
|
255+
= help: if you need `extern "stdcall"` on win32 and `extern "C"` everywhere else, use `extern "system"`
233256

234257
warning: use of calling convention not supported on this target
235-
--> $DIR/unsupported.rs:122:1
258+
--> $DIR/unsupported.rs:126:1
236259
|
237260
LL | extern "cdecl" fn cdecl() {}
238261
| ^^^^^^^^^^^^^^^^^^^^^^^^^
239262
|
240263
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
241264
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
265+
= help: use `extern "C"` instead
242266

243267
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
244-
--> $DIR/unsupported.rs:134:1
268+
--> $DIR/unsupported.rs:141:1
245269
|
246270
LL | extern "vectorcall" fn vectorcall() {}
247271
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248272

249273
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
250-
--> $DIR/unsupported.rs:150:1
274+
--> $DIR/unsupported.rs:157:1
251275
|
252276
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
253277
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254278

255-
error: aborting due to 21 previous errors; 14 warnings emitted
279+
error: aborting due to 22 previous errors; 15 warnings emitted
256280

257281
For more information about this error, try `rustc --explain E0570`.
258282
Future incompatibility report: Future breakage diagnostic:
@@ -345,7 +369,7 @@ LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
345369

346370
Future breakage diagnostic:
347371
warning: the calling convention "cdecl" is not supported on this target
348-
--> $DIR/unsupported.rs:125:17
372+
--> $DIR/unsupported.rs:129:17
349373
|
350374
LL | fn cdecl_ptr(f: extern "cdecl" fn()) {
351375
| ^^^^^^^^^^^^^^^^^^^
@@ -356,18 +380,31 @@ LL | fn cdecl_ptr(f: extern "cdecl" fn()) {
356380

357381
Future breakage diagnostic:
358382
warning: use of calling convention not supported on this target
359-
--> $DIR/unsupported.rs:130:1
383+
--> $DIR/unsupported.rs:134:1
360384
|
361385
LL | extern "cdecl" {}
362386
| ^^^^^^^^^^^^^^^^^
363387
|
364388
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
365389
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
390+
= help: use `extern "C"` instead
391+
= note: `#[warn(unsupported_calling_conventions)]` on by default
392+
393+
Future breakage diagnostic:
394+
warning: use of calling convention not supported on this target
395+
--> $DIR/unsupported.rs:137:1
396+
|
397+
LL | extern "cdecl-unwind" {}
398+
| ^^^^^^^^^^^^^^^^^^^^^^^^
399+
|
400+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
401+
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
402+
= help: use `extern "C-unwind"` instead
366403
= note: `#[warn(unsupported_calling_conventions)]` on by default
367404

368405
Future breakage diagnostic:
369406
warning: the calling convention "vectorcall" is not supported on this target
370-
--> $DIR/unsupported.rs:136:22
407+
--> $DIR/unsupported.rs:143:22
371408
|
372409
LL | fn vectorcall_ptr(f: extern "vectorcall" fn()) {
373410
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -378,7 +415,7 @@ LL | fn vectorcall_ptr(f: extern "vectorcall" fn()) {
378415

379416
Future breakage diagnostic:
380417
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
381-
--> $DIR/unsupported.rs:144:21
418+
--> $DIR/unsupported.rs:151:21
382419
|
383420
LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
384421
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -389,7 +426,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
389426

390427
Future breakage diagnostic:
391428
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
392-
--> $DIR/unsupported.rs:152:22
429+
--> $DIR/unsupported.rs:159:22
393430
|
394431
LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
395432
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -400,12 +437,13 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
400437

401438
Future breakage diagnostic:
402439
warning: use of calling convention not supported on this target
403-
--> $DIR/unsupported.rs:122:1
440+
--> $DIR/unsupported.rs:126:1
404441
|
405442
LL | extern "cdecl" fn cdecl() {}
406443
| ^^^^^^^^^^^^^^^^^^^^^^^^^
407444
|
408445
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
409446
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
447+
= help: use `extern "C"` instead
410448
= note: `#[warn(unsupported_calling_conventions)]` on by default
411449

0 commit comments

Comments
 (0)