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.
This commit is contained in:
parent
b82795244e
commit
d37da1e332
13 changed files with 172 additions and 70 deletions
|
@ -2322,16 +2322,17 @@ pub enum ModKind {
|
|||
Unloaded,
|
||||
}
|
||||
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
|
||||
pub struct ModSpans {
|
||||
/// `inner_span` covers the body of the module; for a file module, its the whole file.
|
||||
/// For an inline module, its the span inside the `{ ... }`, not including the curly braces.
|
||||
pub inner_span: Span,
|
||||
pub inject_use_span: Span,
|
||||
}
|
||||
|
||||
impl Default for ModSpans {
|
||||
fn default() -> ModSpans {
|
||||
ModSpans { inner_span: Default::default() }
|
||||
ModSpans { inner_span: Default::default(), inject_use_span: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1009,8 +1009,9 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
|
|||
ItemKind::Mod(unsafety, mod_kind) => {
|
||||
visit_unsafety(unsafety, vis);
|
||||
match mod_kind {
|
||||
ModKind::Loaded(items, _inline, ModSpans { inner_span }) => {
|
||||
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
|
||||
vis.visit_span(inner_span);
|
||||
vis.visit_span(inject_use_span);
|
||||
items.flat_map_in_place(|item| vis.flat_map_item(item));
|
||||
}
|
||||
ModKind::Unloaded => {}
|
||||
|
@ -1112,8 +1113,9 @@ pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
|||
vis.visit_id(id);
|
||||
visit_attrs(attrs, vis);
|
||||
items.flat_map_in_place(|item| vis.flat_map_item(item));
|
||||
let ModSpans { inner_span } = spans;
|
||||
let ModSpans { inner_span, inject_use_span } = spans;
|
||||
vis.visit_span(inner_span);
|
||||
vis.visit_span(inject_use_span);
|
||||
}
|
||||
|
||||
// Mutates one item into possibly many items.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue