Fix diagnostic for qualifier in extern block
Closes: https://github.com/rust-lang/rust/issues/123306
This commit is contained in:
parent
45796d1c24
commit
109daa2d4b
10 changed files with 93 additions and 72 deletions
|
@ -514,13 +514,32 @@ impl<'a> AstValidator<'a> {
|
|||
}
|
||||
|
||||
/// An `fn` in `extern { ... }` cannot have qualifiers, e.g. `async fn`.
|
||||
fn check_foreign_fn_headerless(&self, ident: Ident, span: Span, header: FnHeader) {
|
||||
if header.has_qualifiers() {
|
||||
fn check_foreign_fn_headerless(
|
||||
&self,
|
||||
// Deconstruct to ensure exhaustiveness
|
||||
FnHeader { unsafety, coroutine_kind, constness, ext }: FnHeader,
|
||||
) {
|
||||
let report_err = |span| {
|
||||
self.dcx().emit_err(errors::FnQualifierInExtern {
|
||||
span: ident.span,
|
||||
span: span,
|
||||
block: self.current_extern_span(),
|
||||
sugg_span: span.until(ident.span.shrink_to_lo()),
|
||||
});
|
||||
};
|
||||
match unsafety {
|
||||
Unsafe::Yes(span) => report_err(span),
|
||||
Unsafe::No => (),
|
||||
}
|
||||
match coroutine_kind {
|
||||
Some(knd) => report_err(knd.span()),
|
||||
None => (),
|
||||
}
|
||||
match constness {
|
||||
Const::Yes(span) => report_err(span),
|
||||
Const::No => (),
|
||||
}
|
||||
match ext {
|
||||
Extern::None => (),
|
||||
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1145,7 +1164,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
ForeignItemKind::Fn(box Fn { defaultness, sig, body, .. }) => {
|
||||
self.check_defaultness(fi.span, *defaultness);
|
||||
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
|
||||
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
|
||||
self.check_foreign_fn_headerless(sig.header);
|
||||
self.check_foreign_item_ascii_only(fi.ident);
|
||||
}
|
||||
ForeignItemKind::TyAlias(box TyAlias {
|
||||
|
|
|
@ -270,11 +270,10 @@ pub struct FnBodyInExtern {
|
|||
#[diag(ast_passes_extern_fn_qualifiers)]
|
||||
pub struct FnQualifierInExtern {
|
||||
#[primary_span]
|
||||
#[suggestion(code = "", applicability = "maybe-incorrect")]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub block: Span,
|
||||
#[suggestion(code = "fn ", applicability = "maybe-incorrect", style = "verbose")]
|
||||
pub sugg_span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue