Skip to content

Commit 1de57a5

Browse files
committed
Auto merge of rust-lang#129935 - RalfJung:unsupported_calling_conventions, r=compiler-errors
make unsupported_calling_conventions a hard error This has been a future-compat lint (not shown in dependencies) since Rust 1.55, released 3 years ago. Hopefully that was enough time so this can be made a hard error now. Given that long timeframe, I think it's justified to skip the "show in dependencies" stage. There were [not many crates hitting this](rust-lang#86231 (comment)) even when the lint was originally added. This should get cratered, and I assume then it needs a t-compiler FCP. (t-compiler because this looks entirely like an implementation oversight -- for the vast majority of ABIs, we already have a hard error, but some were initially missed, and we are finally fixing that.) Fixes rust-lang#87678
2 parents 814df6e + de3cbf3 commit 1de57a5

File tree

15 files changed

+97
-201
lines changed

15 files changed

+97
-201
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+17-28
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{
2222
AdtDef, GenericArgKind, ParamEnv, RegionKind, TypeSuperVisitable, TypeVisitable,
2323
TypeVisitableExt,
2424
};
25-
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
25+
use rustc_session::lint::builtin::UNINHABITED_STATIC;
2626
use rustc_target::abi::FieldIdx;
2727
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2828
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
@@ -36,36 +36,25 @@ use super::compare_impl_item::{check_type_bounds, compare_impl_method, compare_i
3636
use super::*;
3737
use crate::check::intrinsicck::InlineAsmCtxt;
3838

39-
pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
40-
match tcx.sess.target.is_abi_supported(abi) {
41-
Some(true) => (),
42-
Some(false) => {
43-
struct_span_code_err!(
44-
tcx.dcx(),
45-
span,
46-
E0570,
47-
"`{abi}` is not a supported ABI for the current target",
48-
)
49-
.emit();
50-
}
51-
None => {
52-
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
53-
lint.primary_message("use of calling convention not supported on this target");
54-
});
55-
}
39+
pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: Abi) {
40+
if !tcx.sess.target.is_abi_supported(abi) {
41+
struct_span_code_err!(
42+
tcx.dcx(),
43+
span,
44+
E0570,
45+
"`{abi}` is not a supported ABI for the current target",
46+
)
47+
.emit();
5648
}
5749
}
5850

5951
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
60-
match tcx.sess.target.is_abi_supported(abi) {
61-
Some(true) => (),
62-
Some(false) | None => {
63-
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
64-
lint.primary_message(format!(
65-
"the calling convention {abi} is not supported on this target"
66-
));
67-
});
68-
}
52+
if !tcx.sess.target.is_abi_supported(abi) {
53+
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
54+
lint.primary_message(format!(
55+
"the calling convention {abi} is not supported on this target"
56+
));
57+
});
6958
}
7059
}
7160

@@ -705,7 +694,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
705694
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
706695
return;
707696
};
708-
check_abi(tcx, it.hir_id(), it.span, abi);
697+
check_abi(tcx, it.span, abi);
709698

710699
match abi {
711700
Abi::RustIntrinsic => {

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn typeck_with_fallback<'tcx>(
155155
tcx.fn_sig(def_id).instantiate_identity()
156156
};
157157

158-
check_abi(tcx, id, span, fn_sig.abi());
158+
check_abi(tcx, span, fn_sig.abi());
159159

160160
// Compute the function signature from point of view of inside the fn.
161161
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ fn register_builtins(store: &mut LintStore) {
598598
"converted into hard error, see PR #125380 \
599599
<https://github.com/rust-lang/rust/pull/125380> for more information",
600600
);
601+
store.register_removed("unsupported_calling_conventions", "converted into hard error");
601602
}
602603

603604
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint_defs/src/builtin.rs

-48
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ declare_lint_pass! {
123123
UNSAFE_OP_IN_UNSAFE_FN,
124124
UNSTABLE_NAME_COLLISIONS,
125125
UNSTABLE_SYNTAX_PRE_EXPANSION,
126-
UNSUPPORTED_CALLING_CONVENTIONS,
127126
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
128127
UNUSED_ASSIGNMENTS,
129128
UNUSED_ASSOCIATED_TYPE_BOUNDS,
@@ -3787,53 +3786,6 @@ declare_lint! {
37873786
crate_level_only
37883787
}
37893788

3790-
declare_lint! {
3791-
/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3792-
/// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3793-
/// variants) on targets that cannot meaningfully be supported for the requested target.
3794-
///
3795-
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3796-
/// code, because this calling convention was never specified for those targets.
3797-
///
3798-
/// Historically MSVC toolchains have fallen back to the regular C calling convention for
3799-
/// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3800-
/// hack across many more targets.
3801-
///
3802-
/// ### Example
3803-
///
3804-
/// ```rust,ignore (needs specific targets)
3805-
/// extern "stdcall" fn stdcall() {}
3806-
/// ```
3807-
///
3808-
/// This will produce:
3809-
///
3810-
/// ```text
3811-
/// warning: use of calling convention not supported on this target
3812-
/// --> $DIR/unsupported.rs:39:1
3813-
/// |
3814-
/// LL | extern "stdcall" fn stdcall() {}
3815-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3816-
/// |
3817-
/// = note: `#[warn(unsupported_calling_conventions)]` on by default
3818-
/// = warning: this was previously accepted by the compiler but is being phased out;
3819-
/// it will become a hard error in a future release!
3820-
/// = note: for more information, see issue ...
3821-
/// ```
3822-
///
3823-
/// ### Explanation
3824-
///
3825-
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3826-
/// defined at all, but was previously accepted due to a bug in the implementation of the
3827-
/// compiler.
3828-
pub UNSUPPORTED_CALLING_CONVENTIONS,
3829-
Warn,
3830-
"use of unsupported calling convention",
3831-
@future_incompatible = FutureIncompatibleInfo {
3832-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
3833-
reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
3834-
};
3835-
}
3836-
38373789
declare_lint! {
38383790
/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
38393791
/// a target dependent calling convention on a target that does not support this calling

compiler/rustc_target/src/spec/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2757,10 +2757,9 @@ impl Target {
27572757
}
27582758
}
27592759

2760-
/// Returns a None if the UNSUPPORTED_CALLING_CONVENTIONS lint should be emitted
2761-
pub fn is_abi_supported(&self, abi: Abi) -> Option<bool> {
2760+
pub fn is_abi_supported(&self, abi: Abi) -> bool {
27622761
use Abi::*;
2763-
Some(match abi {
2762+
match abi {
27642763
Rust
27652764
| C { .. }
27662765
| System { .. }
@@ -2819,9 +2818,9 @@ impl Target {
28192818
// architectures for which these calling conventions are actually well defined.
28202819
Stdcall { .. } | Fastcall { .. } if self.arch == "x86" => true,
28212820
Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => true,
2822-
// Return a `None` for other cases so that we know to emit a future compat lint.
2823-
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => return None,
2824-
})
2821+
// Reject these calling conventions everywhere else.
2822+
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => false,
2823+
}
28252824
}
28262825

28272826
/// Minimum integer size in bits that this target can perform atomic

src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(clippy::missing_const_for_fn)]
22
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
3-
#![allow(unsupported_calling_conventions)]
4-
#![feature(const_trait_impl)]
3+
#![feature(const_trait_impl, abi_vectorcall)]
4+
55

66
use std::mem::transmute;
77

@@ -212,8 +212,8 @@ mod extern_fn {
212212
//~^ ERROR: this could be a `const fn`
213213
const extern "system-unwind" fn system_unwind() {}
214214
//~^ ERROR: this could be a `const fn`
215-
pub const extern "stdcall" fn std_call() {}
215+
pub const extern "vectorcall" fn std_call() {}
216216
//~^ ERROR: this could be a `const fn`
217-
pub const extern "stdcall-unwind" fn std_call_unwind() {}
217+
pub const extern "vectorcall-unwind" fn std_call_unwind() {}
218218
//~^ ERROR: this could be a `const fn`
219219
}

src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(clippy::missing_const_for_fn)]
22
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
3-
#![allow(unsupported_calling_conventions)]
4-
#![feature(const_trait_impl)]
3+
#![feature(const_trait_impl, abi_vectorcall)]
4+
55

66
use std::mem::transmute;
77

@@ -212,8 +212,8 @@ mod extern_fn {
212212
//~^ ERROR: this could be a `const fn`
213213
extern "system-unwind" fn system_unwind() {}
214214
//~^ ERROR: this could be a `const fn`
215-
pub extern "stdcall" fn std_call() {}
215+
pub extern "vectorcall" fn std_call() {}
216216
//~^ ERROR: this could be a `const fn`
217-
pub extern "stdcall-unwind" fn std_call_unwind() {}
217+
pub extern "vectorcall-unwind" fn std_call_unwind() {}
218218
//~^ ERROR: this could be a `const fn`
219219
}

src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,23 @@ LL | const extern "system-unwind" fn system_unwind() {}
319319
error: this could be a `const fn`
320320
--> tests/ui/missing_const_for_fn/could_be_const.rs:215:5
321321
|
322-
LL | pub extern "stdcall" fn std_call() {}
323-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
322+
LL | pub extern "vectorcall" fn std_call() {}
323+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
324324
|
325325
help: make the function `const`
326326
|
327-
LL | pub const extern "stdcall" fn std_call() {}
327+
LL | pub const extern "vectorcall" fn std_call() {}
328328
| +++++
329329

330330
error: this could be a `const fn`
331331
--> tests/ui/missing_const_for_fn/could_be_const.rs:217:5
332332
|
333-
LL | pub extern "stdcall-unwind" fn std_call_unwind() {}
334-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
333+
LL | pub extern "vectorcall-unwind" fn std_call_unwind() {}
334+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335335
|
336336
help: make the function `const`
337337
|
338-
LL | pub const extern "stdcall-unwind" fn std_call_unwind() {}
338+
LL | pub const extern "vectorcall-unwind" fn std_call_unwind() {}
339339
| +++++
340340

341341
error: aborting due to 26 previous errors

tests/ui/abi/unsupported.aarch64.stderr

+9-16
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,22 @@ LL | extern "thiscall" {}
105105
| ^^^^^^^^^^^^^^^^^^^^
106106

107107
warning: the calling convention "stdcall" is not supported on this target
108-
--> $DIR/unsupported.rs:170:19
108+
--> $DIR/unsupported.rs:165:19
109109
|
110110
LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
111111
| ^^^^^^^^^^^^^^^^^^^^^
112112
|
113113
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
114114
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
115115

116-
warning: use of calling convention not supported on this target
117-
--> $DIR/unsupported.rs:183:1
116+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
117+
--> $DIR/unsupported.rs:178:1
118118
|
119119
LL | extern "stdcall" {}
120120
| ^^^^^^^^^^^^^^^^^^^
121-
|
122-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
123-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
124-
= note: `#[warn(unsupported_calling_conventions)]` on by default
125121

126122
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
127-
--> $DIR/unsupported.rs:195:21
123+
--> $DIR/unsupported.rs:185:21
128124
|
129125
LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
130126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -133,7 +129,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
133129
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
134130

135131
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
136-
--> $DIR/unsupported.rs:203:22
132+
--> $DIR/unsupported.rs:193:22
137133
|
138134
LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
139135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -142,7 +138,7 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
142138
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
143139

144140
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
145-
--> $DIR/unsupported.rs:208:1
141+
--> $DIR/unsupported.rs:198:1
146142
|
147143
LL | extern "C-cmse-nonsecure-entry" {}
148144
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -189,21 +185,18 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
189185
LL | extern "thiscall" fn thiscall() {}
190186
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191187

192-
warning: use of calling convention not supported on this target
188+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
193189
--> $DIR/unsupported.rs:159:1
194190
|
195191
LL | extern "stdcall" fn stdcall() {}
196192
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197-
|
198-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
199-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
200193

201194
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
202-
--> $DIR/unsupported.rs:201:1
195+
--> $DIR/unsupported.rs:191:1
203196
|
204197
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
205198
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
206199

207-
error: aborting due to 16 previous errors; 12 warnings emitted
200+
error: aborting due to 18 previous errors; 10 warnings emitted
208201

209202
For more information about this error, try `rustc --explain E0570`.

tests/ui/abi/unsupported.arm.stderr

+9-16
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,22 @@ LL | extern "thiscall" {}
9090
| ^^^^^^^^^^^^^^^^^^^^
9191

9292
warning: the calling convention "stdcall" is not supported on this target
93-
--> $DIR/unsupported.rs:170:19
93+
--> $DIR/unsupported.rs:165:19
9494
|
9595
LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
9696
| ^^^^^^^^^^^^^^^^^^^^^
9797
|
9898
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9999
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
100100

101-
warning: use of calling convention not supported on this target
102-
--> $DIR/unsupported.rs:183:1
101+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
102+
--> $DIR/unsupported.rs:178:1
103103
|
104104
LL | extern "stdcall" {}
105105
| ^^^^^^^^^^^^^^^^^^^
106-
|
107-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
108-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
109-
= note: `#[warn(unsupported_calling_conventions)]` on by default
110106

111107
warning: the calling convention "C-cmse-nonsecure-call" is not supported on this target
112-
--> $DIR/unsupported.rs:195:21
108+
--> $DIR/unsupported.rs:185:21
113109
|
114110
LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
115111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +114,7 @@ LL | fn cmse_call_ptr(f: extern "C-cmse-nonsecure-call" fn()) {
118114
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
119115

120116
warning: the calling convention "C-cmse-nonsecure-entry" is not supported on this target
121-
--> $DIR/unsupported.rs:203:22
117+
--> $DIR/unsupported.rs:193:22
122118
|
123119
LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
124120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -127,7 +123,7 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
127123
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
128124

129125
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
130-
--> $DIR/unsupported.rs:208:1
126+
--> $DIR/unsupported.rs:198:1
131127
|
132128
LL | extern "C-cmse-nonsecure-entry" {}
133129
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -168,21 +164,18 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
168164
LL | extern "thiscall" fn thiscall() {}
169165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170166

171-
warning: use of calling convention not supported on this target
167+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
172168
--> $DIR/unsupported.rs:159:1
173169
|
174170
LL | extern "stdcall" fn stdcall() {}
175171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176-
|
177-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
178-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
179172

180173
error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current target
181-
--> $DIR/unsupported.rs:201:1
174+
--> $DIR/unsupported.rs:191:1
182175
|
183176
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
184177
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185178

186-
error: aborting due to 14 previous errors; 11 warnings emitted
179+
error: aborting due to 16 previous errors; 9 warnings emitted
187180

188181
For more information about this error, try `rustc --explain E0570`.

0 commit comments

Comments
 (0)