diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-27 12:56:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-27 12:56:26 +0100 |
commit | d0a4ba294ccf0c925a5ff1115c19a60c6a24b734 (patch) | |
tree | 5caf7619e3486f68516d81971abc3018ddee5323 /crates/hir | |
parent | bfb06e17acd4bcb623ad5656490a7a1971980441 (diff) | |
parent | 196cb65ead398f81340de431400103224d7de660 (diff) |
Merge #8997
8997: internal: stop expanding UseTrees during ItemTree lowering r=jonas-schievink a=jonas-schievink
Closes https://github.com/rust-analyzer/rust-analyzer/issues/8908
Messy diff, but `ItemTree` lowering got simpler, since we now have a strict 1-to-1 mapping between `ast::Item` and `ModItem`.
The most messy part is mapping a single `UseTree` back to its `ast::UseTree` counterpart for diagnostics, but I think the ad-hoc source map built during lowering does the job.
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/lib.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 1ecd2391b..01b2de515 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -472,27 +472,13 @@ impl Module { | |||
472 | }); | 472 | }); |
473 | } | 473 | } |
474 | 474 | ||
475 | DefDiagnosticKind::UnresolvedImport { ast, index } => { | 475 | DefDiagnosticKind::UnresolvedImport { id, index } => { |
476 | let use_item = ast.to_node(db.upcast()); | 476 | let file_id = id.file_id(); |
477 | let hygiene = Hygiene::new(db.upcast(), ast.file_id); | 477 | let item_tree = id.item_tree(db.upcast()); |
478 | let mut cur = 0; | 478 | let import = &item_tree[id.value]; |
479 | let mut tree = None; | ||
480 | ModPath::expand_use_item( | ||
481 | db.upcast(), | ||
482 | InFile::new(ast.file_id, use_item), | ||
483 | &hygiene, | ||
484 | |_mod_path, use_tree, _is_glob, _alias| { | ||
485 | if cur == *index { | ||
486 | tree = Some(use_tree.clone()); | ||
487 | } | ||
488 | |||
489 | cur += 1; | ||
490 | }, | ||
491 | ); | ||
492 | 479 | ||
493 | if let Some(tree) = tree { | 480 | let use_tree = import.use_tree_to_ast(db.upcast(), file_id, *index); |
494 | sink.push(UnresolvedImport { file: ast.file_id, node: AstPtr::new(&tree) }); | 481 | sink.push(UnresolvedImport { file: file_id, node: AstPtr::new(&use_tree) }); |
495 | } | ||
496 | } | 482 | } |
497 | 483 | ||
498 | DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => { | 484 | DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } => { |