about summary refs log tree commit diff
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
commit651f46376aa6bb259c58cbb3debad6e0edce31bf (patch)
treef3039ee6c0dce674c3826486e17faecf391ce931
parent74876ef4e9b29184787f6d8f3ba447e78def3a47 (diff)
downloadrust-651f46376aa6bb259c58cbb3debad6e0edce31bf.tar.gz
rust-651f46376aa6bb259c58cbb3debad6e0edce31bf.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.
-rw-r--r--src/parse/parser.rs2
-rw-r--r--src/visitor.rs2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 3b4e762b6dd..6983249c15d 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -113,7 +113,7 @@ impl<'a> Parser<'a> {
         let result = catch_unwind(AssertUnwindSafe(|| {
             let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
             match parser.parse_mod(&TokenKind::Eof) {
-                Ok((a, i, ast::ModSpans { inner_span })) => Some((a, i, inner_span)),
+                Ok((a, i, ast::ModSpans { inner_span, inject_use_span: _ })) => Some((a, i, inner_span)),
                 Err(mut e) => {
                     e.emit();
                     if sess.can_reset_errors() {
diff --git a/src/visitor.rs b/src/visitor.rs
index c44b2fc6ae3..dec977e98ca 100644
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -916,7 +916,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
         self.push_str(&ident_str);
 
         if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind {
-            let ast::ModSpans { inner_span } = *spans;
+            let ast::ModSpans{ inner_span, inject_use_span: _ } = *spans;
             match self.config.brace_style() {
                 BraceStyle::AlwaysNextLine => {
                     let indent_str = self.block_indent.to_string_with_newline(self.config);