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
4 changed files with 71 additions and 2 deletions

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)
}