Skip to content

Commit

Permalink
Make implicit "C" abi an error in Rust 2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Oct 30, 2024
1 parent 466c9cc commit 66df93c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
.suggestion = remove the {$remove_descr}
.label = `extern` block begins here
ast_passes_extern_without_abi = extern declaration without an ABI
.label = ABI should be specified here
.suggestion = explicitly specify an ABI
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
.suggestion = remove the attribute
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable
Expand Down
33 changes: 19 additions & 14 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,25 @@ impl<'a> AstValidator<'a> {
}

fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
// call site which do not have a macro backtrace. See #61963.
if self
.sess
.source_map()
.span_to_snippet(span)
.is_ok_and(|snippet| !snippet.starts_with("#["))
{
self.lint_buffer.buffer_lint(
MISSING_ABI,
id,
span,
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
)
if span.edition().at_least_rust_2024() {
self.dcx()
.emit_err(errors::MissingAbi { span, default_abi: abi::Abi::FALLBACK.name() });
} else {
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
// call site which do not have a macro backtrace. See #61963.
if self
.sess
.source_map()
.span_to_snippet(span)
.is_ok_and(|snippet| !snippet.starts_with("#["))
{
self.lint_buffer.buffer_lint(
MISSING_ABI,
id,
span,
BuiltinLintDiag::MissingAbi(span, abi::Abi::FALLBACK),
)
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,12 @@ pub(crate) struct DuplicatePreciseCapturing {
#[label]
pub bound2: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_extern_without_abi)]
pub(crate) struct MissingAbi {
#[primary_span]
#[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")]
pub span: Span,
pub default_abi: &'static str,
}

0 comments on commit 66df93c

Please sign in to comment.