Skip to content

Commit 18e938e

Browse files
committed
Make implicit "C" abi an error in Rust 2024.
1 parent 466c9cc commit 18e938e

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
7979
.suggestion = remove the {$remove_descr}
8080
.label = `extern` block begins here
8181
82+
ast_passes_extern_without_abi = extern declaration without an ABI
83+
.label = ABI should be specified here
84+
.suggestion = explicitly specify an ABI
85+
8286
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
8387
.suggestion = remove the attribute
8488
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ impl<'a> AstValidator<'a> {
712712
}
713713

714714
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
715+
if span.edition().at_least_rust_2024() {
716+
self.dcx()
717+
.emit_err(errors::MissingAbi { span, default_abi: abi::Abi::FALLBACK.name() });
718+
}
715719
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
716720
// call site which do not have a macro backtrace. See #61963.
717721
if self

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,12 @@ pub(crate) struct DuplicatePreciseCapturing {
833833
#[label]
834834
pub bound2: Span,
835835
}
836+
837+
#[derive(Diagnostic)]
838+
#[diag(ast_passes_extern_without_abi)]
839+
pub(crate) struct MissingAbi {
840+
#[primary_span]
841+
#[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")]
842+
pub span: Span,
843+
pub default_abi: &'static str,
844+
}

0 commit comments

Comments
 (0)