aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/path
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-06 18:59:54 +0100
committerJonas Schievink <[email protected]>2021-05-06 18:59:54 +0100
commit976a3226fe0f145dfefd473e9fecd63d58aca50e (patch)
tree59dd6c2e4cc81c3f9285d47e5a44e370110818c7 /crates/hir_def/src/path
parentb37b709459a4ff881a91965ebf0c39e3a449c304 (diff)
Don't store call-site text offsets in hygiene info
Diffstat (limited to 'crates/hir_def/src/path')
-rw-r--r--crates/hir_def/src/path/lower.rs14
-rw-r--r--crates/hir_def/src/path/lower/lower_use.rs23
2 files changed, 25 insertions, 12 deletions
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs
index 1df6db525..3b3a3738f 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::intern::Interned; 5use crate::{db::DefDatabase, intern::Interned};
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use either::Either; 8use either::Either;
@@ -20,7 +20,11 @@ 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(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> { 23pub(super) fn lower_path(
24 db: &dyn DefDatabase,
25 mut path: ast::Path,
26 ctx: &LowerCtx,
27) -> Option<Path> {
24 let mut kind = PathKind::Plain; 28 let mut kind = PathKind::Plain;
25 let mut type_anchor = None; 29 let mut type_anchor = None;
26 let mut segments = Vec::new(); 30 let mut segments = Vec::new();
@@ -36,7 +40,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
36 match segment.kind()? { 40 match segment.kind()? {
37 ast::PathSegmentKind::Name(name_ref) => { 41 ast::PathSegmentKind::Name(name_ref) => {
38 // FIXME: this should just return name 42 // FIXME: this should just return name
39 match hygiene.name_ref_to_name(name_ref) { 43 match hygiene.name_ref_to_name(db.upcast(), name_ref) {
40 Either::Left(name) => { 44 Either::Left(name) => {
41 let args = segment 45 let args = segment
42 .generic_arg_list() 46 .generic_arg_list()
@@ -71,7 +75,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
71 } 75 }
72 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo 76 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
73 Some(trait_ref) => { 77 Some(trait_ref) => {
74 let path = Path::from_src(trait_ref.path()?, ctx)?; 78 let path = Path::from_src(db, trait_ref.path()?, ctx)?;
75 let mod_path = (*path.mod_path).clone(); 79 let mod_path = (*path.mod_path).clone();
76 let num_segments = path.mod_path.segments.len(); 80 let num_segments = path.mod_path.segments.len();
77 kind = mod_path.kind; 81 kind = mod_path.kind;
@@ -133,7 +137,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
133 // We follow what it did anyway :) 137 // We follow what it did anyway :)
134 if segments.len() == 1 && kind == PathKind::Plain { 138 if segments.len() == 1 && kind == PathKind::Plain {
135 if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { 139 if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
136 if let Some(crate_id) = hygiene.local_inner_macros(path) { 140 if let Some(crate_id) = hygiene.local_inner_macros(db.upcast(), path) {
137 kind = PathKind::DollarCrate(crate_id); 141 kind = PathKind::DollarCrate(crate_id);
138 } 142 }
139 } 143 }
diff --git a/crates/hir_def/src/path/lower/lower_use.rs b/crates/hir_def/src/path/lower/lower_use.rs
index e2965b033..ee80e3df3 100644
--- a/crates/hir_def/src/path/lower/lower_use.rs
+++ b/crates/hir_def/src/path/lower/lower_use.rs
@@ -7,9 +7,13 @@ use either::Either;
7use hir_expand::{hygiene::Hygiene, name::AsName}; 7use hir_expand::{hygiene::Hygiene, name::AsName};
8use syntax::ast::{self, NameOwner}; 8use syntax::ast::{self, NameOwner};
9 9
10use crate::path::{ImportAlias, ModPath, PathKind}; 10use crate::{
11 db::DefDatabase,
12 path::{ImportAlias, ModPath, PathKind},
13};
11 14
12pub(crate) fn lower_use_tree( 15pub(crate) fn lower_use_tree(
16 db: &dyn DefDatabase,
13 prefix: Option<ModPath>, 17 prefix: Option<ModPath>,
14 tree: ast::UseTree, 18 tree: ast::UseTree,
15 hygiene: &Hygiene, 19 hygiene: &Hygiene,
@@ -21,13 +25,13 @@ pub(crate) fn lower_use_tree(
21 None => prefix, 25 None => prefix,
22 // E.g. `use something::{inner}` (prefix is `None`, path is `something`) 26 // E.g. `use something::{inner}` (prefix is `None`, path is `something`)
23 // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) 27 // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
24 Some(path) => match convert_path(prefix, path, hygiene) { 28 Some(path) => match convert_path(db, prefix, path, hygiene) {
25 Some(it) => Some(it), 29 Some(it) => Some(it),
26 None => return, // FIXME: report errors somewhere 30 None => return, // FIXME: report errors somewhere
27 }, 31 },
28 }; 32 };
29 for child_tree in use_tree_list.use_trees() { 33 for child_tree in use_tree_list.use_trees() {
30 lower_use_tree(prefix.clone(), child_tree, hygiene, cb); 34 lower_use_tree(db, prefix.clone(), child_tree, hygiene, cb);
31 } 35 }
32 } else { 36 } else {
33 let alias = tree.rename().map(|a| { 37 let alias = tree.rename().map(|a| {
@@ -47,7 +51,7 @@ pub(crate) fn lower_use_tree(
47 } 51 }
48 } 52 }
49 } 53 }
50 if let Some(path) = convert_path(prefix, ast_path, hygiene) { 54 if let Some(path) = convert_path(db, prefix, ast_path, hygiene) {
51 cb(path, &tree, is_glob, alias) 55 cb(path, &tree, is_glob, alias)
52 } 56 }
53 // FIXME: report errors somewhere 57 // FIXME: report errors somewhere
@@ -61,9 +65,14 @@ pub(crate) fn lower_use_tree(
61 } 65 }
62} 66}
63 67
64fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) -> Option<ModPath> { 68fn convert_path(
69 db: &dyn DefDatabase,
70 prefix: Option<ModPath>,
71 path: ast::Path,
72 hygiene: &Hygiene,
73) -> Option<ModPath> {
65 let prefix = if let Some(qual) = path.qualifier() { 74 let prefix = if let Some(qual) = path.qualifier() {
66 Some(convert_path(prefix, qual, hygiene)?) 75 Some(convert_path(db, prefix, qual, hygiene)?)
67 } else { 76 } else {
68 prefix 77 prefix
69 }; 78 };
@@ -71,7 +80,7 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
71 let segment = path.segment()?; 80 let segment = path.segment()?;
72 let res = match segment.kind()? { 81 let res = match segment.kind()? {
73 ast::PathSegmentKind::Name(name_ref) => { 82 ast::PathSegmentKind::Name(name_ref) => {
74 match hygiene.name_ref_to_name(name_ref) { 83 match hygiene.name_ref_to_name(db.upcast(), name_ref) {
75 Either::Left(name) => { 84 Either::Left(name) => {
76 // no type args in use 85 // no type args in use
77 let mut res = prefix.unwrap_or_else(|| { 86 let mut res = prefix.unwrap_or_else(|| {