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_def/src/path.rs | |
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_def/src/path.rs')
-rw-r--r-- | crates/hir_def/src/path.rs | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index d9ec03d2d..16440041d 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -14,10 +14,7 @@ use hir_expand::{ | |||
14 | }; | 14 | }; |
15 | use syntax::ast; | 15 | use syntax::ast; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::type_ref::{TypeBound, TypeRef}; |
18 | type_ref::{TypeBound, TypeRef}, | ||
19 | InFile, | ||
20 | }; | ||
21 | 18 | ||
22 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | 19 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
23 | pub struct ModPath { | 20 | pub struct ModPath { |
@@ -56,8 +53,7 @@ impl Display for ImportAlias { | |||
56 | 53 | ||
57 | impl ModPath { | 54 | impl ModPath { |
58 | pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { | 55 | pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { |
59 | let ctx = LowerCtx::with_hygiene(db, hygiene); | 56 | lower::convert_path(db, None, path, hygiene) |
60 | lower::lower_path(path, &ctx).map(|it| (*it.mod_path).clone()) | ||
61 | } | 57 | } |
62 | 58 | ||
63 | pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { | 59 | pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { |
@@ -70,18 +66,6 @@ impl ModPath { | |||
70 | ModPath { kind, segments: Vec::new() } | 66 | ModPath { kind, segments: Vec::new() } |
71 | } | 67 | } |
72 | 68 | ||
73 | /// Calls `cb` with all paths, represented by this use item. | ||
74 | pub fn expand_use_item( | ||
75 | db: &dyn DefDatabase, | ||
76 | item_src: InFile<ast::Use>, | ||
77 | hygiene: &Hygiene, | ||
78 | mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>), | ||
79 | ) { | ||
80 | if let Some(tree) = item_src.value.use_tree() { | ||
81 | lower::lower_use_tree(db, None, tree, hygiene, &mut cb); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | pub fn segments(&self) -> &[Name] { | 69 | pub fn segments(&self) -> &[Name] { |
86 | &self.segments | 70 | &self.segments |
87 | } | 71 | } |