Add hard error for extern
without explicit ABI
This commit is contained in:
parent
ee53c26b41
commit
01cfa9aad5
4 changed files with 21 additions and 6 deletions
|
@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
|
||||||
.suggestion = remove the {$remove_descr}
|
.suggestion = remove the {$remove_descr}
|
||||||
.label = `extern` block begins here
|
.label = `extern` block begins here
|
||||||
|
|
||||||
|
ast_passes_extern_without_abi = `extern` declarations without an explicit ABI are disallowed
|
||||||
|
.suggestion = specify an ABI
|
||||||
|
.help = prior to Rust 2024, a default ABI was inferred
|
||||||
|
|
||||||
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
|
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
|
||||||
.suggestion = remove the attribute
|
.suggestion = remove the attribute
|
||||||
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable
|
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable
|
||||||
|
|
|
@ -684,7 +684,7 @@ impl<'a> AstValidator<'a> {
|
||||||
self.dcx().emit_err(errors::PatternFnPointer { span });
|
self.dcx().emit_err(errors::PatternFnPointer { span });
|
||||||
});
|
});
|
||||||
if let Extern::Implicit(extern_span) = bfty.ext {
|
if let Extern::Implicit(extern_span) = bfty.ext {
|
||||||
self.maybe_lint_missing_abi(extern_span, ty.id);
|
self.handle_missing_abi(extern_span, ty.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::TraitObject(bounds, ..) => {
|
TyKind::TraitObject(bounds, ..) => {
|
||||||
|
@ -717,10 +717,12 @@ impl<'a> AstValidator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
|
fn handle_missing_abi(&mut self, span: Span, id: NodeId) {
|
||||||
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
|
// 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.
|
// call site which do not have a macro backtrace. See #61963.
|
||||||
if self
|
if span.edition().at_least_edition_future() && self.features.explicit_extern_abis() {
|
||||||
|
self.dcx().emit_err(errors::MissingAbi { span });
|
||||||
|
} else if self
|
||||||
.sess
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(span)
|
.span_to_snippet(span)
|
||||||
|
@ -996,7 +998,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if abi.is_none() {
|
if abi.is_none() {
|
||||||
self.maybe_lint_missing_abi(*extern_span, item.id);
|
self.handle_missing_abi(*extern_span, item.id);
|
||||||
}
|
}
|
||||||
self.with_in_extern_mod(*safety, |this| {
|
self.with_in_extern_mod(*safety, |this| {
|
||||||
visit::walk_item(this, item);
|
visit::walk_item(this, item);
|
||||||
|
@ -1370,7 +1372,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
},
|
},
|
||||||
) = fk
|
) = fk
|
||||||
{
|
{
|
||||||
self.maybe_lint_missing_abi(*extern_span, id);
|
self.handle_missing_abi(*extern_span, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions without bodies cannot have patterns.
|
// Functions without bodies cannot have patterns.
|
||||||
|
|
|
@ -823,3 +823,12 @@ pub(crate) struct DuplicatePreciseCapturing {
|
||||||
#[label]
|
#[label]
|
||||||
pub bound2: Span,
|
pub bound2: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(ast_passes_extern_without_abi)]
|
||||||
|
#[help]
|
||||||
|
pub(crate) struct MissingAbi {
|
||||||
|
#[primary_span]
|
||||||
|
#[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ lint_expectation = this lint expectation is unfulfilled
|
||||||
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
|
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
|
||||||
.suggestion = convert it to a `use`
|
.suggestion = convert it to a `use`
|
||||||
|
|
||||||
lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
|
lint_extern_without_abi = `extern` declarations without an explicit ABI are deprecated
|
||||||
.label = ABI should be specified here
|
.label = ABI should be specified here
|
||||||
.suggestion = explicitly specify the {$default_abi} ABI
|
.suggestion = explicitly specify the {$default_abi} ABI
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue