1
Fork 0

Rollup merge of #116420 - bvanjoi:fix-116203, r=Nilstrieb

discard invalid spans in external blocks

Fixes #116203

This PR has discarded the invalid `const_span`, thereby making the format more neat.

r? ``@Nilstrieb``
This commit is contained in:
Matthias Krüger 2023-12-07 21:38:07 +01:00 committed by GitHub
commit 71a8ca0522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 2 deletions

View file

@ -1733,7 +1733,7 @@ pub(crate) struct ExternItemCannotBeConst {
#[primary_span]
pub ident_span: Span,
#[suggestion(code = "static ", applicability = "machine-applicable")]
pub const_span: Span,
pub const_span: Option<Span>,
}
#[derive(Diagnostic)]

View file

@ -1139,9 +1139,11 @@ impl<'a> Parser<'a> {
Ok(kind) => kind,
Err(kind) => match kind {
ItemKind::Const(box ConstItem { ty, expr, .. }) => {
let const_span = Some(span.with_hi(ident.span.lo()))
.filter(|span| span.can_be_used_for_suggestions());
self.sess.emit_err(errors::ExternItemCannotBeConst {
ident_span: ident.span,
const_span: span.with_hi(ident.span.lo()),
const_span,
});
ForeignItemKind::Static(ty, Mutability::Not, expr)
}