Skip to content

Commit 66df93c

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

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

compiler/rustc_ast_passes/messages.ftl

+4
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

+19-14
Original file line numberDiff line numberDiff line change
@@ -712,20 +712,25 @@ impl<'a> AstValidator<'a> {
712712
}
713713

714714
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
715-
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
716-
// call site which do not have a macro backtrace. See #61963.
717-
if self
718-
.sess
719-
.source_map()
720-
.span_to_snippet(span)
721-
.is_ok_and(|snippet| !snippet.starts_with("#["))
722-
{
723-
self.lint_buffer.buffer_lint(
724-
MISSING_ABI,
725-
id,
726-
span,
727-
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
728-
)
715+
if span.edition().at_least_rust_2024() {
716+
self.dcx()
717+
.emit_err(errors::MissingAbi { span, default_abi: abi::Abi::FALLBACK.name() });
718+
} else {
719+
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
720+
// call site which do not have a macro backtrace. See #61963.
721+
if self
722+
.sess
723+
.source_map()
724+
.span_to_snippet(span)
725+
.is_ok_and(|snippet| !snippet.starts_with("#["))
726+
{
727+
self.lint_buffer.buffer_lint(
728+
MISSING_ABI,
729+
id,
730+
span,
731+
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
732+
)
733+
}
729734
}
730735
}
731736
}

compiler/rustc_ast_passes/src/errors.rs

+9
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)