diff options
Diffstat (limited to 'crates/hir_def/src/path.rs')
-rw-r--r-- | crates/hir_def/src/path.rs | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 9b8873fd2..16440041d 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs | |||
@@ -4,7 +4,6 @@ mod lower; | |||
4 | use std::{ | 4 | use std::{ |
5 | fmt::{self, Display}, | 5 | fmt::{self, Display}, |
6 | iter, | 6 | iter, |
7 | sync::Arc, | ||
8 | }; | 7 | }; |
9 | 8 | ||
10 | use crate::{body::LowerCtx, db::DefDatabase, intern::Interned, type_ref::LifetimeRef}; | 9 | use crate::{body::LowerCtx, db::DefDatabase, intern::Interned, type_ref::LifetimeRef}; |
@@ -15,10 +14,7 @@ use hir_expand::{ | |||
15 | }; | 14 | }; |
16 | use syntax::ast; | 15 | use syntax::ast; |
17 | 16 | ||
18 | use crate::{ | 17 | use crate::type_ref::{TypeBound, TypeRef}; |
19 | type_ref::{TypeBound, TypeRef}, | ||
20 | InFile, | ||
21 | }; | ||
22 | 18 | ||
23 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | 19 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] |
24 | pub struct ModPath { | 20 | pub struct ModPath { |
@@ -57,8 +53,7 @@ impl Display for ImportAlias { | |||
57 | 53 | ||
58 | impl ModPath { | 54 | impl ModPath { |
59 | 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> { |
60 | let ctx = LowerCtx::with_hygiene(db, hygiene); | 56 | lower::convert_path(db, None, path, hygiene) |
61 | lower::lower_path(path, &ctx).map(|it| (*it.mod_path).clone()) | ||
62 | } | 57 | } |
63 | 58 | ||
64 | 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 { |
@@ -71,18 +66,6 @@ impl ModPath { | |||
71 | ModPath { kind, segments: Vec::new() } | 66 | ModPath { kind, segments: Vec::new() } |
72 | } | 67 | } |
73 | 68 | ||
74 | /// Calls `cb` with all paths, represented by this use item. | ||
75 | pub(crate) fn expand_use_item( | ||
76 | db: &dyn DefDatabase, | ||
77 | item_src: InFile<ast::Use>, | ||
78 | hygiene: &Hygiene, | ||
79 | mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>), | ||
80 | ) { | ||
81 | if let Some(tree) = item_src.value.use_tree() { | ||
82 | lower::lower_use_tree(db, None, tree, hygiene, &mut cb); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | pub fn segments(&self) -> &[Name] { | 69 | pub fn segments(&self) -> &[Name] { |
87 | &self.segments | 70 | &self.segments |
88 | } | 71 | } |
@@ -136,7 +119,7 @@ pub struct Path { | |||
136 | type_anchor: Option<Interned<TypeRef>>, | 119 | type_anchor: Option<Interned<TypeRef>>, |
137 | mod_path: Interned<ModPath>, | 120 | mod_path: Interned<ModPath>, |
138 | /// Invariant: the same len as `self.mod_path.segments` | 121 | /// Invariant: the same len as `self.mod_path.segments` |
139 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 122 | generic_args: Vec<Option<Interned<GenericArgs>>>, |
140 | } | 123 | } |
141 | 124 | ||
142 | /// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This | 125 | /// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This |
@@ -165,7 +148,7 @@ pub struct AssociatedTypeBinding { | |||
165 | /// Bounds for the associated type, like in `Iterator<Item: | 148 | /// Bounds for the associated type, like in `Iterator<Item: |
166 | /// SomeOtherTrait>`. (This is the unstable `associated_type_bounds` | 149 | /// SomeOtherTrait>`. (This is the unstable `associated_type_bounds` |
167 | /// feature.) | 150 | /// feature.) |
168 | pub bounds: Vec<TypeBound>, | 151 | pub bounds: Vec<Interned<TypeBound>>, |
169 | } | 152 | } |
170 | 153 | ||
171 | /// A single generic argument. | 154 | /// A single generic argument. |
@@ -185,7 +168,7 @@ impl Path { | |||
185 | /// Converts a known mod path to `Path`. | 168 | /// Converts a known mod path to `Path`. |
186 | pub(crate) fn from_known_path( | 169 | pub(crate) fn from_known_path( |
187 | path: ModPath, | 170 | path: ModPath, |
188 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 171 | generic_args: Vec<Option<Interned<GenericArgs>>>, |
189 | ) -> Path { | 172 | ) -> Path { |
190 | Path { type_anchor: None, mod_path: Interned::new(path), generic_args } | 173 | Path { type_anchor: None, mod_path: Interned::new(path), generic_args } |
191 | } | 174 | } |
@@ -239,7 +222,7 @@ pub struct PathSegment<'a> { | |||
239 | 222 | ||
240 | pub struct PathSegments<'a> { | 223 | pub struct PathSegments<'a> { |
241 | segments: &'a [Name], | 224 | segments: &'a [Name], |
242 | generic_args: &'a [Option<Arc<GenericArgs>>], | 225 | generic_args: &'a [Option<Interned<GenericArgs>>], |
243 | } | 226 | } |
244 | 227 | ||
245 | impl<'a> PathSegments<'a> { | 228 | impl<'a> PathSegments<'a> { |