about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2022-01-20 14:07:54 -0500
committerFelix S. Klock II <pnkfelix@pnkfx.org>2022-03-03 18:58:37 -0500
commitd37da1e332a77a4cd66c2f36b4a5457f40a7bfd5 (patch)
treef3638bd95437411b3a0c926e0ce9a864997542e9 /compiler/rustc_parse/src/parser
parentb82795244e31ce1ad60bbb823c4e4b91f921c296 (diff)
downloadrust-d37da1e332a77a4cd66c2f36b4a5457f40a7bfd5.tar.gz
rust-d37da1e332a77a4cd66c2f36b4a5457f40a7bfd5.zip
Adjusted diagnostic output so that if there is no `use` in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 484a27fa59d..c370195659d 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -55,6 +55,7 @@ impl<'a> Parser<'a> {
         let lo = self.token.span;
         let attrs = self.parse_inner_attributes()?;
 
+        let post_attr_lo = self.token.span;
         let mut items = vec![];
         while let Some(item) = self.parse_item(ForceCollect::No)? {
             items.push(item);
@@ -71,7 +72,9 @@ impl<'a> Parser<'a> {
             }
         }
 
-        Ok((attrs, items, ModSpans { inner_span: lo.to(self.prev_token.span) }))
+        let inject_use_span = post_attr_lo.data().with_hi(post_attr_lo.lo());
+        let mod_spans = ModSpans { inner_span: lo.to(self.prev_token.span), inject_use_span };
+        Ok((attrs, items, mod_spans))
     }
 }