Skip to content

Commit 13a09bc

Browse files
committed
Add hard error for extern without explicit ABI
1 parent 1acbda2 commit 13a09bc

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

compiler/rustc_ast_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ 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 declarations without an explicit ABI are disallowed
83+
.help = in previous editions, a default ABI was inferred, but this is no longer the case, so you must specify one explicitly
84+
8285
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
8386
.suggestion = remove the attribute
8487
.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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<'a> AstValidator<'a> {
684684
self.dcx().emit_err(errors::PatternFnPointer { span });
685685
});
686686
if let Extern::Implicit(extern_span) = bfty.ext {
687-
self.maybe_lint_missing_abi(extern_span, ty.id);
687+
self.handle_missing_abi(extern_span, ty.id);
688688
}
689689
}
690690
TyKind::TraitObject(bounds, ..) => {
@@ -717,10 +717,12 @@ impl<'a> AstValidator<'a> {
717717
}
718718
}
719719

720-
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
720+
fn handle_missing_abi(&mut self, span: Span, id: NodeId) {
721721
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
722722
// call site which do not have a macro backtrace. See #61963.
723-
if self
723+
if span.edition().at_least_edition_future() && self.features.explicit_extern_abis() {
724+
self.dcx().emit_err(errors::MissingAbi { span });
725+
} else if self
724726
.sess
725727
.source_map()
726728
.span_to_snippet(span)
@@ -996,7 +998,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
996998
}
997999

9981000
if abi.is_none() {
999-
self.maybe_lint_missing_abi(*extern_span, item.id);
1001+
self.handle_missing_abi(*extern_span, item.id);
10001002
}
10011003
self.with_in_extern_mod(*safety, |this| {
10021004
visit::walk_item(this, item);
@@ -1370,7 +1372,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13701372
},
13711373
) = fk
13721374
{
1373-
self.maybe_lint_missing_abi(*extern_span, id);
1375+
self.handle_missing_abi(*extern_span, id);
13741376
}
13751377

13761378
// Functions without bodies cannot have patterns.

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,11 @@ pub(crate) struct DuplicatePreciseCapturing {
823823
#[label]
824824
pub bound2: Span,
825825
}
826+
827+
#[derive(Diagnostic)]
828+
#[diag(ast_passes_extern_without_abi)]
829+
#[help]
830+
pub(crate) struct MissingAbi {
831+
#[primary_span]
832+
pub span: Span,
833+
}

0 commit comments

Comments
 (0)