about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-12-07 21:38:07 +0100
committerGitHub <noreply@github.com>2023-12-07 21:38:07 +0100
commit71a8ca0522d727e2900e4a6f0899f3664de97035 (patch)
treedbb2ba94f0c4b9c66e66cc34c8cf7e1ae369df2d /compiler/rustc_parse/src/parser
parent0e7f91b75e7484a713e2f644212cfc1aa7478a28 (diff)
parent4138702621f32528fee8bf55eb1b8c0b99ac369b (diff)
downloadrust-71a8ca0522d727e2900e4a6f0899f3664de97035.tar.gz
rust-71a8ca0522d727e2900e4a6f0899f3664de97035.zip
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``
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 8a987767dc4..086e8d5cf9b 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -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)
                         }