Skip to content

Commit 930693c

Browse files
committed
store the span of the nested part of the use tree in the ast
1 parent 6557c5e commit 930693c

File tree

12 files changed

+33
-26
lines changed

12 files changed

+33
-26
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ pub enum UseTreeKind {
26972697
/// `use prefix` or `use prefix as rename`
26982698
Simple(Option<Ident>),
26992699
/// `use prefix::{...}`
2700-
Nested(ThinVec<(UseTree, NodeId)>),
2700+
Nested { items: ThinVec<(UseTree, NodeId)>, span: Span },
27012701
/// `use prefix::*`
27022702
Glob,
27032703
}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ pub fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
436436
vis.visit_path(prefix);
437437
match kind {
438438
UseTreeKind::Simple(rename) => visit_opt(rename, |rename| vis.visit_ident(rename)),
439-
UseTreeKind::Nested(items) => {
439+
UseTreeKind::Nested { items, .. } => {
440440
for (tree, id) in items {
441441
vis.visit_use_tree(tree);
442442
vis.visit_id(id);

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(
484484
visit_opt!(visitor, visit_ident, rename);
485485
}
486486
UseTreeKind::Glob => {}
487-
UseTreeKind::Nested(ref use_trees) => {
488-
for &(ref nested_tree, nested_id) in use_trees {
487+
UseTreeKind::Nested { ref items, .. } => {
488+
for &(ref nested_tree, nested_id) in items {
489489
try_visit!(visitor.visit_use_tree(nested_tree, nested_id, true));
490490
}
491491
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
134134

135135
fn lower_item_id_use_tree(&mut self, tree: &UseTree, vec: &mut SmallVec<[hir::ItemId; 1]>) {
136136
match &tree.kind {
137-
UseTreeKind::Nested(nested_vec) => {
138-
for &(ref nested, id) in nested_vec {
137+
UseTreeKind::Nested { items, .. } => {
138+
for &(ref nested, id) in items {
139139
vec.push(hir::ItemId {
140140
owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
141141
});
@@ -517,7 +517,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
517517
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
518518
hir::ItemKind::Use(path, hir::UseKind::Glob)
519519
}
520-
UseTreeKind::Nested(ref trees) => {
520+
UseTreeKind::Nested { items: ref trees, .. } => {
521521
// Nested imports are desugared into simple imports.
522522
// So, if we start with
523523
//

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl<'a> State<'a> {
712712
}
713713
self.word("*");
714714
}
715-
ast::UseTreeKind::Nested(items) => {
715+
ast::UseTreeKind::Nested { items, .. } => {
716716
if !tree.prefix.segments.is_empty() {
717717
self.print_path(&tree.prefix, false, 0);
718718
self.word("::");
@@ -731,7 +731,7 @@ impl<'a> State<'a> {
731731
self.print_use_tree(&use_tree.0);
732732
if !is_last {
733733
self.word(",");
734-
if let ast::UseTreeKind::Nested(_) = use_tree.0.kind {
734+
if let ast::UseTreeKind::Nested { .. } = use_tree.0.kind {
735735
self.hardbreak();
736736
} else {
737737
self.space();

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ impl<'cx, 'a> Context<'cx, 'a> {
120120
thin_vec![self.cx.attr_nested_word(sym::allow, sym::unused_imports, self.span)],
121121
ItemKind::Use(UseTree {
122122
prefix: self.cx.path(self.span, self.cx.std_path(&[sym::asserting])),
123-
kind: UseTreeKind::Nested(thin_vec![
124-
nested_tree(self, sym::TryCaptureGeneric),
125-
nested_tree(self, sym::TryCapturePrintable),
126-
]),
123+
kind: UseTreeKind::Nested {
124+
items: thin_vec![
125+
nested_tree(self, sym::TryCaptureGeneric),
126+
nested_tree(self, sym::TryCapturePrintable),
127+
],
128+
span: self.span,
129+
},
127130
span: self.span,
128131
}),
129132
),

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,8 @@ impl InvocationCollectorNode for P<ast::Item> {
11901190
match &ut.kind {
11911191
ast::UseTreeKind::Glob => {}
11921192
ast::UseTreeKind::Simple(_) => idents.push(ut.ident()),
1193-
ast::UseTreeKind::Nested(nested) => {
1194-
for (ut, _) in nested {
1193+
ast::UseTreeKind::Nested { items, .. } => {
1194+
for (ut, _) in items {
11951195
collect_use_tree_leaves(ut, idents);
11961196
}
11971197
}

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ declare_lint_pass!(UnusedImportBraces => [UNUSED_IMPORT_BRACES]);
14931493

14941494
impl UnusedImportBraces {
14951495
fn check_use_tree(&self, cx: &EarlyContext<'_>, use_tree: &ast::UseTree, item: &ast::Item) {
1496-
if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
1496+
if let ast::UseTreeKind::Nested { ref items, .. } = use_tree.kind {
14971497
// Recursively check nested UseTrees
14981498
for (tree, _) in items {
14991499
self.check_use_tree(cx, tree, item);
@@ -1514,7 +1514,7 @@ impl UnusedImportBraces {
15141514
rename.unwrap_or(orig_ident).name
15151515
}
15161516
ast::UseTreeKind::Glob => Symbol::intern("*"),
1517-
ast::UseTreeKind::Nested(_) => return,
1517+
ast::UseTreeKind::Nested { .. } => return,
15181518
};
15191519

15201520
cx.emit_span_lint(

compiler/rustc_parse/src/parser/item.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'a> Parser<'a> {
336336
UseTreeKind::Glob => {
337337
e.note("the wildcard token must be last on the path");
338338
}
339-
UseTreeKind::Nested(..) => {
339+
UseTreeKind::Nested { .. } => {
340340
e.note("glob-like brace syntax must be last on the path");
341341
}
342342
_ => (),
@@ -1056,7 +1056,11 @@ impl<'a> Parser<'a> {
10561056
Ok(if self.eat(&token::BinOp(token::Star)) {
10571057
UseTreeKind::Glob
10581058
} else {
1059-
UseTreeKind::Nested(self.parse_use_tree_list()?)
1059+
let lo = self.token.span;
1060+
UseTreeKind::Nested {
1061+
items: self.parse_use_tree_list()?,
1062+
span: lo.to(self.prev_token.span),
1063+
}
10601064
})
10611065
}
10621066

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
565565

566566
self.add_import(prefix, kind, use_tree.span, item, root_span, item.id, vis);
567567
}
568-
ast::UseTreeKind::Nested(ref items) => {
568+
ast::UseTreeKind::Nested { ref items, .. } => {
569569
// Ensure there is at most one `self` in the list
570570
let self_spans = items
571571
.iter()

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
128128
self.unused_import(self.base_id).add(id);
129129
}
130130
}
131-
ast::UseTreeKind::Nested(ref items) => self.check_imports_as_underscore(items),
131+
ast::UseTreeKind::Nested { ref items, .. } => self.check_imports_as_underscore(items),
132132
_ => {}
133133
}
134134
}
@@ -254,7 +254,7 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
254254
return;
255255
}
256256

257-
if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
257+
if let ast::UseTreeKind::Nested { ref items, .. } = use_tree.kind {
258258
if items.is_empty() {
259259
self.unused_import(self.base_id).add(id);
260260
}
@@ -292,7 +292,7 @@ fn calc_unused_spans(
292292
UnusedSpanResult::Used
293293
}
294294
}
295-
ast::UseTreeKind::Nested(ref nested) => {
295+
ast::UseTreeKind::Nested { items: ref nested, .. } => {
296296
if nested.is_empty() {
297297
return UnusedSpanResult::Unused { spans: vec![use_tree.span], remove: full_span };
298298
}

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,8 +2332,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23322332
None => {}
23332333
}
23342334
}
2335-
} else if let UseTreeKind::Nested(use_trees) = &use_tree.kind {
2336-
for (use_tree, _) in use_trees {
2335+
} else if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
2336+
for (use_tree, _) in items {
23372337
self.future_proof_import(use_tree);
23382338
}
23392339
}
@@ -2510,7 +2510,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
25102510
ItemKind::Use(ref use_tree) => {
25112511
let maybe_exported = match use_tree.kind {
25122512
UseTreeKind::Simple(_) | UseTreeKind::Glob => MaybeExported::Ok(item.id),
2513-
UseTreeKind::Nested(_) => MaybeExported::NestedUse(&item.vis),
2513+
UseTreeKind::Nested { .. } => MaybeExported::NestedUse(&item.vis),
25142514
};
25152515
self.resolve_doc_links(&item.attrs, maybe_exported);
25162516

0 commit comments

Comments
 (0)