From d37da1e332a77a4cd66c2f36b4a5457f40a7bfd5 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 20 Jan 2022 14:07:54 -0500 Subject: 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. --- compiler/rustc_parse/src/parser/item.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_parse/src/parser') 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)) } } -- cgit 1.4.1-3-g733a5