aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/hir/src/source_analyzer.rs5
-rw-r--r--crates/hir_def/src/body.rs2
-rw-r--r--crates/hir_def/src/body/lower.rs4
-rw-r--r--crates/hir_def/src/path.rs6
-rw-r--r--crates/hir_def/src/path/lower.rs14
-rw-r--r--crates/hir_ty/src/display.rs2
7 files changed, 15 insertions, 20 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index d53d81c07..62500602a 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -855,7 +855,7 @@ impl<'a> SemanticsScope<'a> {
855 /// necessary a heuristic, as it doesn't take hygiene into account. 855 /// necessary a heuristic, as it doesn't take hygiene into account.
856 pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> { 856 pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> {
857 let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id); 857 let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id);
858 let path = Path::from_src(self.db.upcast(), path.clone(), &ctx)?; 858 let path = Path::from_src(path.clone(), &ctx)?;
859 resolve_hir_path(self.db, &self.resolver, &path) 859 resolve_hir_path(self.db, &self.resolver, &path)
860 } 860 }
861} 861}
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs
index 186421cbd..b5c65808e 100644
--- a/crates/hir/src/source_analyzer.rs
+++ b/crates/hir/src/source_analyzer.rs
@@ -204,8 +204,7 @@ impl SourceAnalyzer {
204 macro_call: InFile<&ast::MacroCall>, 204 macro_call: InFile<&ast::MacroCall>,
205 ) -> Option<MacroDef> { 205 ) -> Option<MacroDef> {
206 let ctx = body::LowerCtx::new(db.upcast(), macro_call.file_id); 206 let ctx = body::LowerCtx::new(db.upcast(), macro_call.file_id);
207 let path = 207 let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &ctx))?;
208 macro_call.value.path().and_then(|ast| Path::from_src(db.upcast(), ast, &ctx))?;
209 self.resolver.resolve_path_as_macro(db.upcast(), path.mod_path()).map(|it| it.into()) 208 self.resolver.resolve_path_as_macro(db.upcast(), path.mod_path()).map(|it| it.into())
210 } 209 }
211 210
@@ -285,7 +284,7 @@ impl SourceAnalyzer {
285 // This must be a normal source file rather than macro file. 284 // This must be a normal source file rather than macro file.
286 let hygiene = Hygiene::new(db.upcast(), self.file_id); 285 let hygiene = Hygiene::new(db.upcast(), self.file_id);
287 let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene); 286 let ctx = body::LowerCtx::with_hygiene(db.upcast(), &hygiene);
288 let hir_path = Path::from_src(db.upcast(), path.clone(), &ctx)?; 287 let hir_path = Path::from_src(path.clone(), &ctx)?;
289 288
290 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we 289 // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
291 // trying to resolve foo::bar. 290 // trying to resolve foo::bar.
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs
index 9510a8575..8360426f1 100644
--- a/crates/hir_def/src/body.rs
+++ b/crates/hir_def/src/body.rs
@@ -194,7 +194,7 @@ impl Expander {
194 194
195 fn parse_path(&mut self, db: &dyn DefDatabase, path: ast::Path) -> Option<Path> { 195 fn parse_path(&mut self, db: &dyn DefDatabase, path: ast::Path) -> Option<Path> {
196 let ctx = LowerCtx::with_hygiene(db, &self.cfg_expander.hygiene); 196 let ctx = LowerCtx::with_hygiene(db, &self.cfg_expander.hygiene);
197 Path::from_src(db, path, &ctx) 197 Path::from_src(path, &ctx)
198 } 198 }
199 199
200 fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { 200 fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> {
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index e4fa7f9c9..75dc19c11 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -41,7 +41,7 @@ use crate::{
41use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource}; 41use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource};
42 42
43pub struct LowerCtx<'a> { 43pub struct LowerCtx<'a> {
44 db: &'a dyn DefDatabase, 44 pub db: &'a dyn DefDatabase,
45 hygiene: Hygiene, 45 hygiene: Hygiene,
46 file_id: Option<HirFileId>, 46 file_id: Option<HirFileId>,
47 source_ast_id_map: Option<Arc<AstIdMap>>, 47 source_ast_id_map: Option<Arc<AstIdMap>>,
@@ -70,7 +70,7 @@ impl<'a> LowerCtx<'a> {
70 } 70 }
71 71
72 pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> { 72 pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
73 Path::from_src(self.db, ast, self) 73 Path::from_src(ast, self)
74 } 74 }
75 75
76 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> Option<FileAstId<N>> { 76 pub(crate) fn ast_id<N: AstNode>(&self, item: &N) -> Option<FileAstId<N>> {
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs
index 64bff318e..a43441b1c 100644
--- a/crates/hir_def/src/path.rs
+++ b/crates/hir_def/src/path.rs
@@ -49,7 +49,7 @@ pub enum ImportAlias {
49impl ModPath { 49impl ModPath {
50 pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { 50 pub fn from_src(db: &dyn DefDatabase, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> {
51 let ctx = LowerCtx::with_hygiene(db, hygiene); 51 let ctx = LowerCtx::with_hygiene(db, hygiene);
52 lower::lower_path(db, path, &ctx).map(|it| (*it.mod_path).clone()) 52 lower::lower_path(path, &ctx).map(|it| (*it.mod_path).clone())
53 } 53 }
54 54
55 pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { 55 pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
@@ -169,8 +169,8 @@ pub enum GenericArg {
169impl Path { 169impl Path {
170 /// Converts an `ast::Path` to `Path`. Works with use trees. 170 /// Converts an `ast::Path` to `Path`. Works with use trees.
171 /// It correctly handles `$crate` based path from macro call. 171 /// It correctly handles `$crate` based path from macro call.
172 pub fn from_src(db: &dyn DefDatabase, path: ast::Path, ctx: &LowerCtx) -> Option<Path> { 172 pub fn from_src(path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
173 lower::lower_path(db, path, ctx) 173 lower::lower_path(path, ctx)
174 } 174 }
175 175
176 /// Converts a known mod path to `Path`. 176 /// Converts a known mod path to `Path`.
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs
index 3b3a3738f..a873325b2 100644
--- a/crates/hir_def/src/path/lower.rs
+++ b/crates/hir_def/src/path/lower.rs
@@ -2,7 +2,7 @@
2 2
3mod lower_use; 3mod lower_use;
4 4
5use crate::{db::DefDatabase, intern::Interned}; 5use crate::intern::Interned;
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use either::Either; 8use either::Either;
@@ -20,11 +20,7 @@ pub(super) use lower_use::lower_use_tree;
20 20
21/// Converts an `ast::Path` to `Path`. Works with use trees. 21/// Converts an `ast::Path` to `Path`. Works with use trees.
22/// It correctly handles `$crate` based path from macro call. 22/// It correctly handles `$crate` based path from macro call.
23pub(super) fn lower_path( 23pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
24 db: &dyn DefDatabase,
25 mut path: ast::Path,
26 ctx: &LowerCtx,
27) -> Option<Path> {
28 let mut kind = PathKind::Plain; 24 let mut kind = PathKind::Plain;
29 let mut type_anchor = None; 25 let mut type_anchor = None;
30 let mut segments = Vec::new(); 26 let mut segments = Vec::new();
@@ -40,7 +36,7 @@ pub(super) fn lower_path(
40 match segment.kind()? { 36 match segment.kind()? {
41 ast::PathSegmentKind::Name(name_ref) => { 37 ast::PathSegmentKind::Name(name_ref) => {
42 // FIXME: this should just return name 38 // FIXME: this should just return name
43 match hygiene.name_ref_to_name(db.upcast(), name_ref) { 39 match hygiene.name_ref_to_name(ctx.db.upcast(), name_ref) {
44 Either::Left(name) => { 40 Either::Left(name) => {
45 let args = segment 41 let args = segment
46 .generic_arg_list() 42 .generic_arg_list()
@@ -75,7 +71,7 @@ pub(super) fn lower_path(
75 } 71 }
76 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo 72 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
77 Some(trait_ref) => { 73 Some(trait_ref) => {
78 let path = Path::from_src(db, trait_ref.path()?, ctx)?; 74 let path = Path::from_src(trait_ref.path()?, ctx)?;
79 let mod_path = (*path.mod_path).clone(); 75 let mod_path = (*path.mod_path).clone();
80 let num_segments = path.mod_path.segments.len(); 76 let num_segments = path.mod_path.segments.len();
81 kind = mod_path.kind; 77 kind = mod_path.kind;
@@ -137,7 +133,7 @@ pub(super) fn lower_path(
137 // We follow what it did anyway :) 133 // We follow what it did anyway :)
138 if segments.len() == 1 && kind == PathKind::Plain { 134 if segments.len() == 1 && kind == PathKind::Plain {
139 if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { 135 if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
140 if let Some(crate_id) = hygiene.local_inner_macros(db.upcast(), path) { 136 if let Some(crate_id) = hygiene.local_inner_macros(ctx.db.upcast(), path) {
141 kind = PathKind::DollarCrate(crate_id); 137 kind = PathKind::DollarCrate(crate_id);
142 } 138 }
143 } 139 }
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index f452edc61..1f6edf7a2 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -1002,7 +1002,7 @@ impl HirDisplay for TypeRef {
1002 let macro_call = macro_call.to_node(f.db.upcast()); 1002 let macro_call = macro_call.to_node(f.db.upcast());
1003 let ctx = body::LowerCtx::with_hygiene(f.db.upcast(), &Hygiene::new_unhygienic()); 1003 let ctx = body::LowerCtx::with_hygiene(f.db.upcast(), &Hygiene::new_unhygienic());
1004 match macro_call.path() { 1004 match macro_call.path() {
1005 Some(path) => match Path::from_src(f.db.upcast(), path, &ctx) { 1005 Some(path) => match Path::from_src(path, &ctx) {
1006 Some(path) => path.hir_fmt(f)?, 1006 Some(path) => path.hir_fmt(f)?,
1007 None => write!(f, "{{macro}}")?, 1007 None => write!(f, "{{macro}}")?,
1008 }, 1008 },