Skip to content

Commit 498fce2

Browse files
committed
Auto merge of #129935 - RalfJung:unsupported_calling_conventions, r=
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](#86231 (comment)) even when the PR was landed. This should get cratered, and I assume then it needs a t-compiler FCP. Fixes #88397
2 parents d6c8169 + 0c5a9b3 commit 498fce2

File tree

13 files changed

+42
-123
lines changed

13 files changed

+42
-123
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::{
2020
AdtDef, GenericArgKind, ParamEnv, RegionKind, TypeSuperVisitable, TypeVisitable,
2121
TypeVisitableExt,
2222
};
23-
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
23+
use rustc_session::lint::builtin::UNINHABITED_STATIC;
2424
use rustc_target::abi::FieldIdx;
2525
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
2626
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
@@ -34,23 +34,15 @@ use super::compare_impl_item::{check_type_bounds, compare_impl_method, compare_i
3434
use super::*;
3535
use crate::check::intrinsicck::InlineAsmCtxt;
3636

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

5648
// This ABI is only allowed on function pointers
@@ -754,7 +746,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
754746
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
755747
return;
756748
};
757-
check_abi(tcx, it.hir_id(), it.span, abi);
749+
check_abi(tcx, it.span, abi);
758750

759751
match abi {
760752
Abi::RustIntrinsic => {

compiler/rustc_hir_typeck/src/lib.rs

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

159-
check_abi(tcx, id, span, fn_sig.abi());
159+
check_abi(tcx, span, fn_sig.abi());
160160

161161
// Compute the function signature from point of view of inside the fn.
162162
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
@@ -575,6 +575,7 @@ fn register_builtins(store: &mut LintStore) {
575575
<https://github.com/rust-lang/rust/issues/107457> for more information",
576576
);
577577
store.register_removed("writes_through_immutable_pointer", "converted into hard error");
578+
store.register_removed("unsupported_calling_conventions", "converted into hard error");
578579
}
579580

580581
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint_defs/src/builtin.rs

-48
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ declare_lint_pass! {
124124
UNSAFE_OP_IN_UNSAFE_FN,
125125
UNSTABLE_NAME_COLLISIONS,
126126
UNSTABLE_SYNTAX_PRE_EXPANSION,
127-
UNSUPPORTED_CALLING_CONVENTIONS,
128127
UNUSED_ASSIGNMENTS,
129128
UNUSED_ASSOCIATED_TYPE_BOUNDS,
130129
UNUSED_ATTRIBUTES,
@@ -3922,53 +3921,6 @@ declare_lint! {
39223921
crate_level_only
39233922
}
39243923

3925-
declare_lint! {
3926-
/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3927-
/// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3928-
/// variants) on targets that cannot meaningfully be supported for the requested target.
3929-
///
3930-
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3931-
/// code, because this calling convention was never specified for those targets.
3932-
///
3933-
/// Historically MSVC toolchains have fallen back to the regular C calling convention for
3934-
/// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3935-
/// hack across many more targets.
3936-
///
3937-
/// ### Example
3938-
///
3939-
/// ```rust,ignore (needs specific targets)
3940-
/// extern "stdcall" fn stdcall() {}
3941-
/// ```
3942-
///
3943-
/// This will produce:
3944-
///
3945-
/// ```text
3946-
/// warning: use of calling convention not supported on this target
3947-
/// --> $DIR/unsupported.rs:39:1
3948-
/// |
3949-
/// LL | extern "stdcall" fn stdcall() {}
3950-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3951-
/// |
3952-
/// = note: `#[warn(unsupported_calling_conventions)]` on by default
3953-
/// = warning: this was previously accepted by the compiler but is being phased out;
3954-
/// it will become a hard error in a future release!
3955-
/// = note: for more information, see issue ...
3956-
/// ```
3957-
///
3958-
/// ### Explanation
3959-
///
3960-
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3961-
/// defined at all, but was previously accepted due to a bug in the implementation of the
3962-
/// compiler.
3963-
pub UNSUPPORTED_CALLING_CONVENTIONS,
3964-
Warn,
3965-
"use of unsupported calling convention",
3966-
@future_incompatible = FutureIncompatibleInfo {
3967-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
3968-
reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
3969-
};
3970-
}
3971-
39723924
declare_lint! {
39733925
/// The `break_with_label_and_loop` lint detects labeled `break` expressions with
39743926
/// an unlabeled loop as their value expression.

compiler/rustc_target/src/spec/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2660,10 +2660,9 @@ impl Target {
26602660
}
26612661
}
26622662

2663-
/// Returns a None if the UNSUPPORTED_CALLING_CONVENTIONS lint should be emitted
2664-
pub fn is_abi_supported(&self, abi: Abi) -> Option<bool> {
2663+
pub fn is_abi_supported(&self, abi: Abi) -> bool {
26652664
use Abi::*;
2666-
Some(match abi {
2665+
match abi {
26672666
Rust
26682667
| C { .. }
26692668
| System { .. }
@@ -2719,9 +2718,9 @@ impl Target {
27192718
// architectures for which these calling conventions are actually well defined.
27202719
Stdcall { .. } | Fastcall { .. } if self.arch == "x86" => true,
27212720
Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => true,
2722-
// Return a `None` for other cases so that we know to emit a future compat lint.
2723-
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => return None,
2724-
})
2721+
// Reject these calling conventions everywhere else.
2722+
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => false,
2723+
}
27252724
}
27262725

27272726
/// Minimum integer size in bits that this target can perform atomic
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#![warn(clippy::missing_const_for_fn)]
2-
#![allow(unsupported_calling_conventions)]
32
#![feature(const_extern_fn)]
43

4+
55
extern "C-unwind" fn c_unwind() {}
66
//~^ ERROR: this could be a `const fn`
77
extern "system" fn system() {}
88
//~^ ERROR: this could be a `const fn`
99
extern "system-unwind" fn system_unwind() {}
1010
//~^ ERROR: this could be a `const fn`
11-
pub extern "stdcall" fn std_call() {}
11+
pub extern "vectorcall" fn vector_call() {}
1212
//~^ ERROR: this could be a `const fn`
13-
pub extern "stdcall-unwind" fn std_call_unwind() {}
13+
pub extern "vectorcall-unwind" fn vector_call_unwind() {}
1414
//~^ ERROR: this could be a `const fn`

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ LL | const extern "system-unwind" fn system_unwind() {}
3636
error: this could be a `const fn`
3737
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:11:1
3838
|
39-
LL | pub extern "stdcall" fn std_call() {}
40-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
LL | pub extern "vectorcall" fn vector_call() {}
40+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
|
4242
help: make the function `const`
4343
|
44-
LL | pub const extern "stdcall" fn std_call() {}
44+
LL | pub const extern "vectorcall" fn vector_call() {}
4545
| +++++
4646

4747
error: this could be a `const fn`
4848
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:13:1
4949
|
50-
LL | pub extern "stdcall-unwind" fn std_call_unwind() {}
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
LL | pub extern "vectorcall-unwind" fn vector_call_unwind() {}
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5252
|
5353
help: make the function `const`
5454
|
55-
LL | pub const extern "stdcall-unwind" fn std_call_unwind() {}
55+
LL | pub const extern "vectorcall-unwind" fn vector_call_unwind() {}
5656
| +++++
5757

5858
error: aborting due to 5 previous errors

tests/ui/abi/unsupported.aarch64.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
4040
LL | extern "thiscall" fn thiscall() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242

43-
warning: use of calling convention not supported on this target
43+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
4444
--> $DIR/unsupported.rs:56:1
4545
|
4646
LL | extern "stdcall" fn stdcall() {}
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48-
|
49-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
50-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
51-
= note: `#[warn(unsupported_calling_conventions)]` on by default
5248

53-
error: aborting due to 7 previous errors; 1 warning emitted
49+
error: aborting due to 8 previous errors
5450

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

tests/ui/abi/unsupported.arm.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
3434
LL | extern "thiscall" fn thiscall() {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
warning: use of calling convention not supported on this target
37+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
3838
--> $DIR/unsupported.rs:56:1
3939
|
4040
LL | extern "stdcall" fn stdcall() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
45-
= note: `#[warn(unsupported_calling_conventions)]` on by default
4642

47-
error: aborting due to 6 previous errors; 1 warning emitted
43+
error: aborting due to 7 previous errors
4844

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

tests/ui/abi/unsupported.riscv32.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
3434
LL | extern "thiscall" fn thiscall() {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
warning: use of calling convention not supported on this target
37+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
3838
--> $DIR/unsupported.rs:56:1
3939
|
4040
LL | extern "stdcall" fn stdcall() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
45-
= note: `#[warn(unsupported_calling_conventions)]` on by default
4642

47-
error: aborting due to 6 previous errors; 1 warning emitted
43+
error: aborting due to 7 previous errors
4844

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

tests/ui/abi/unsupported.riscv64.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
3434
LL | extern "thiscall" fn thiscall() {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
warning: use of calling convention not supported on this target
37+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
3838
--> $DIR/unsupported.rs:56:1
3939
|
4040
LL | extern "stdcall" fn stdcall() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
45-
= note: `#[warn(unsupported_calling_conventions)]` on by default
4642

47-
error: aborting due to 6 previous errors; 1 warning emitted
43+
error: aborting due to 7 previous errors
4844

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

tests/ui/abi/unsupported.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,8 @@ extern "thiscall" fn thiscall() {}
5454
//[riscv32]~^^^^ ERROR is not a supported ABI
5555
//[riscv64]~^^^^^ ERROR is not a supported ABI
5656
extern "stdcall" fn stdcall() {}
57-
//[x64]~^ WARN use of calling convention not supported
58-
//[x64]~^^ WARN this was previously accepted
59-
//[arm]~^^^ WARN use of calling convention not supported
60-
//[arm]~^^^^ WARN this was previously accepted
61-
//[aarch64]~^^^^^ WARN use of calling convention not supported
62-
//[aarch64]~^^^^^^ WARN this was previously accepted
63-
//[riscv32]~^^^^^^^ WARN use of calling convention not supported
64-
//[riscv32]~^^^^^^^^ WARN this was previously accepted
65-
//[riscv64]~^^^^^^^^^ WARN use of calling convention not supported
66-
//[riscv64]~^^^^^^^^^^ WARN this was previously accepted
57+
//[x64]~^ ERROR is not a supported ABI
58+
//[arm]~^^ ERROR is not a supported ABI
59+
//[aarch64]~^^^ ERROR is not a supported ABI
60+
//[riscv32]~^^^^ ERROR is not a supported ABI
61+
//[riscv64]~^^^^^ ERROR is not a supported ABI

tests/ui/abi/unsupported.x64.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ error[E0570]: `"thiscall"` is not a supported ABI for the current target
3434
LL | extern "thiscall" fn thiscall() {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
warning: use of calling convention not supported on this target
37+
error[E0570]: `"stdcall"` is not a supported ABI for the current target
3838
--> $DIR/unsupported.rs:56:1
3939
|
4040
LL | extern "stdcall" fn stdcall() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44-
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
45-
= note: `#[warn(unsupported_calling_conventions)]` on by default
4642

47-
error: aborting due to 6 previous errors; 1 warning emitted
43+
error: aborting due to 7 previous errors
4844

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

0 commit comments

Comments
 (0)