Skip to content

Commit 651f463

Browse files
committed
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.
1 parent 74876ef commit 651f463

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a> Parser<'a> {
113113
let result = catch_unwind(AssertUnwindSafe(|| {
114114
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
115115
match parser.parse_mod(&TokenKind::Eof) {
116-
Ok((a, i, ast::ModSpans { inner_span })) => Some((a, i, inner_span)),
116+
Ok((a, i, ast::ModSpans { inner_span, inject_use_span: _ })) => Some((a, i, inner_span)),
117117
Err(mut e) => {
118118
e.emit();
119119
if sess.can_reset_errors() {

src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
916916
self.push_str(&ident_str);
917917

918918
if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind {
919-
let ast::ModSpans { inner_span } = *spans;
919+
let ast::ModSpans{ inner_span, inject_use_span: _ } = *spans;
920920
match self.config.brace_style() {
921921
BraceStyle::AlwaysNextLine => {
922922
let indent_str = self.block_indent.to_string_with_newline(self.config);

0 commit comments

Comments
 (0)