Skip to content

Commit b73f7b4

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

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi
5151
None => {
5252
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
5353
lint.primary_message("use of calling convention not supported on this target");
54+
if let ExternAbi::Cdecl { unwind } = abi {
55+
let suffix = if unwind { "-unwind" } else { "" };
56+
lint.help(format!("use `extern \"C{suffix}\"` instead",));
57+
} else if let ExternAbi::Stdcall { unwind } = abi {
58+
let suffix = if unwind { "-unwind" } else { "" };
59+
lint.help(format!(
60+
"if you need `extern \"stdcall{suffix}\"` on win32 and `extern \"C{suffix}\"` everywhere else, use `extern \"system{suffix}\"`"
61+
));
62+
}
5463
});
5564
}
5665
}

tests/ui/abi/unsupported.aarch64.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ LL | extern "cdecl" {}
136136
|
137137
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
138138
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
139+
= help: use `extern "C"` instead
139140
= note: `#[warn(unsupported_calling_conventions)]` on by default
140141

141142
warning: the calling convention "vectorcall" is not supported on this target
@@ -239,6 +240,7 @@ LL | extern "cdecl" fn cdecl() {}
239240
|
240241
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
241242
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
243+
= help: use `extern "C"` instead
242244

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

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

tests/ui/abi/unsupported.arm.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ LL | extern "cdecl" {}
121121
|
122122
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123123
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
124+
= help: use `extern "C"` instead
124125
= note: `#[warn(unsupported_calling_conventions)]` on by default
125126

126127
warning: the calling convention "vectorcall" is not supported on this target
@@ -218,6 +219,7 @@ LL | extern "cdecl" fn cdecl() {}
218219
|
219220
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220221
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
222+
= help: use `extern "C"` instead
221223

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

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

tests/ui/abi/unsupported.riscv32.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ LL | extern "cdecl" {}
121121
|
122122
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123123
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
124+
= help: use `extern "C"` instead
124125
= note: `#[warn(unsupported_calling_conventions)]` on by default
125126

126127
warning: the calling convention "vectorcall" is not supported on this target
@@ -218,6 +219,7 @@ LL | extern "cdecl" fn cdecl() {}
218219
|
219220
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220221
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
222+
= help: use `extern "C"` instead
221223

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

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

tests/ui/abi/unsupported.riscv64.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ LL | extern "cdecl" {}
121121
|
122122
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123123
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
124+
= help: use `extern "C"` instead
124125
= note: `#[warn(unsupported_calling_conventions)]` on by default
125126

126127
warning: the calling convention "vectorcall" is not supported on this target
@@ -218,6 +219,7 @@ LL | extern "cdecl" fn cdecl() {}
218219
|
219220
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
220221
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
222+
= help: use `extern "C"` instead
221223

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

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

tests/ui/abi/unsupported.x64.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ LL | extern "cdecl" {}
121121
|
122122
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123123
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
124+
= help: use `extern "C"` instead
124125
= note: `#[warn(unsupported_calling_conventions)]` on by default
125126

126127
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
@@ -203,6 +204,7 @@ LL | extern "cdecl" fn cdecl() {}
203204
|
204205
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
205206
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
207+
= help: use `extern "C"` instead
206208

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

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

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)