Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 13f7623

Browse files
committed
store the span of the nested part of the use tree in the ast
1 parent 2ec337c commit 13f7623

File tree

17 files changed

+45
-36
lines changed

17 files changed

+45
-36
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ pub enum UseTreeKind {
27032703
/// `use prefix` or `use prefix as rename`
27042704
Simple(Option<Ident>),
27052705
/// `use prefix::{...}`
2706-
Nested(ThinVec<(UseTree, NodeId)>),
2706+
Nested { items: ThinVec<(UseTree, NodeId)>, span: Span },
27072707
/// `use prefix::*`
27082708
Glob,
27092709
}

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
@@ -488,8 +488,8 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(
488488
visit_opt!(visitor, visit_ident, rename);
489489
}
490490
UseTreeKind::Glob => {}
491-
UseTreeKind::Nested(ref use_trees) => {
492-
for &(ref nested_tree, nested_id) in use_trees {
491+
UseTreeKind::Nested { ref items, .. } => {
492+
for &(ref nested_tree, nested_id) in items {
493493
try_visit!(visitor.visit_use_tree(nested_tree, nested_id, true));
494494
}
495495
}

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
@@ -1499,7 +1499,7 @@ declare_lint_pass!(UnusedImportBraces => [UNUSED_IMPORT_BRACES]);
14991499

15001500
impl UnusedImportBraces {
15011501
fn check_use_tree(&self, cx: &EarlyContext<'_>, use_tree: &ast::UseTree, item: &ast::Item) {
1502-
if let ast::UseTreeKind::Nested(ref items) = use_tree.kind {
1502+
if let ast::UseTreeKind::Nested { ref items, .. } = use_tree.kind {
15031503
// Recursively check nested UseTrees
15041504
for (tree, _) in items {
15051505
self.check_use_tree(cx, tree, item);
@@ -1520,7 +1520,7 @@ impl UnusedImportBraces {
15201520
rename.unwrap_or(orig_ident).name
15211521
}
15221522
ast::UseTreeKind::Glob => Symbol::intern("*"),
1523-
ast::UseTreeKind::Nested(_) => return,
1523+
ast::UseTreeKind::Nested { .. } => return,
15241524
};
15251525

15261526
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()

0 commit comments

Comments
 (0)