From 976a3226fe0f145dfefd473e9fecd63d58aca50e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 6 May 2021 19:59:54 +0200 Subject: Don't store call-site text offsets in hygiene info --- crates/hir_def/src/path/lower.rs | 14 +++++++++----- crates/hir_def/src/path/lower/lower_use.rs | 23 ++++++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'crates/hir_def/src/path') 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 @@ mod lower_use; -use crate::intern::Interned; +use crate::{db::DefDatabase, intern::Interned}; use std::sync::Arc; use either::Either; @@ -20,7 +20,11 @@ pub(super) use lower_use::lower_use_tree; /// Converts an `ast::Path` to `Path`. Works with use trees. /// It correctly handles `$crate` based path from macro call. -pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { +pub(super) fn lower_path( + db: &dyn DefDatabase, + mut path: ast::Path, + ctx: &LowerCtx, +) -> Option { let mut kind = PathKind::Plain; let mut type_anchor = None; let mut segments = Vec::new(); @@ -36,7 +40,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { match segment.kind()? { ast::PathSegmentKind::Name(name_ref) => { // FIXME: this should just return name - match hygiene.name_ref_to_name(name_ref) { + match hygiene.name_ref_to_name(db.upcast(), name_ref) { Either::Left(name) => { let args = segment .generic_arg_list() @@ -71,7 +75,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { } // >::Foo desugars to Trait::Foo Some(trait_ref) => { - let path = Path::from_src(trait_ref.path()?, ctx)?; + let path = Path::from_src(db, trait_ref.path()?, ctx)?; let mod_path = (*path.mod_path).clone(); let num_segments = path.mod_path.segments.len(); kind = mod_path.kind; @@ -133,7 +137,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { // We follow what it did anyway :) if segments.len() == 1 && kind == PathKind::Plain { if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { - if let Some(crate_id) = hygiene.local_inner_macros(path) { + if let Some(crate_id) = hygiene.local_inner_macros(db.upcast(), path) { kind = PathKind::DollarCrate(crate_id); } } 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; use hir_expand::{hygiene::Hygiene, name::AsName}; use syntax::ast::{self, NameOwner}; -use crate::path::{ImportAlias, ModPath, PathKind}; +use crate::{ + db::DefDatabase, + path::{ImportAlias, ModPath, PathKind}, +}; pub(crate) fn lower_use_tree( + db: &dyn DefDatabase, prefix: Option, tree: ast::UseTree, hygiene: &Hygiene, @@ -21,13 +25,13 @@ pub(crate) fn lower_use_tree( None => prefix, // E.g. `use something::{inner}` (prefix is `None`, path is `something`) // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) - Some(path) => match convert_path(prefix, path, hygiene) { + Some(path) => match convert_path(db, prefix, path, hygiene) { Some(it) => Some(it), None => return, // FIXME: report errors somewhere }, }; for child_tree in use_tree_list.use_trees() { - lower_use_tree(prefix.clone(), child_tree, hygiene, cb); + lower_use_tree(db, prefix.clone(), child_tree, hygiene, cb); } } else { let alias = tree.rename().map(|a| { @@ -47,7 +51,7 @@ pub(crate) fn lower_use_tree( } } } - if let Some(path) = convert_path(prefix, ast_path, hygiene) { + if let Some(path) = convert_path(db, prefix, ast_path, hygiene) { cb(path, &tree, is_glob, alias) } // FIXME: report errors somewhere @@ -61,9 +65,14 @@ pub(crate) fn lower_use_tree( } } -fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> Option { +fn convert_path( + db: &dyn DefDatabase, + prefix: Option, + path: ast::Path, + hygiene: &Hygiene, +) -> Option { let prefix = if let Some(qual) = path.qualifier() { - Some(convert_path(prefix, qual, hygiene)?) + Some(convert_path(db, prefix, qual, hygiene)?) } else { prefix }; @@ -71,7 +80,7 @@ fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> let segment = path.segment()?; let res = match segment.kind()? { ast::PathSegmentKind::Name(name_ref) => { - match hygiene.name_ref_to_name(name_ref) { + match hygiene.name_ref_to_name(db.upcast(), name_ref) { Either::Left(name) => { // no type args in use let mut res = prefix.unwrap_or_else(|| { -- cgit v1.2.3 From 20ae41c1a12963e938cb3bd4c7c84007412d6fa6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 6 May 2021 23:23:50 +0200 Subject: Reuse database in LowerCtx --- crates/hir_def/src/path/lower.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/hir_def/src/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 @@ mod lower_use; -use crate::{db::DefDatabase, intern::Interned}; +use crate::intern::Interned; use std::sync::Arc; use either::Either; @@ -20,11 +20,7 @@ pub(super) use lower_use::lower_use_tree; /// Converts an `ast::Path` to `Path`. Works with use trees. /// It correctly handles `$crate` based path from macro call. -pub(super) fn lower_path( - db: &dyn DefDatabase, - mut path: ast::Path, - ctx: &LowerCtx, -) -> Option { +pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option { let mut kind = PathKind::Plain; let mut type_anchor = None; let mut segments = Vec::new(); @@ -40,7 +36,7 @@ pub(super) fn lower_path( match segment.kind()? { ast::PathSegmentKind::Name(name_ref) => { // FIXME: this should just return name - match hygiene.name_ref_to_name(db.upcast(), name_ref) { + match hygiene.name_ref_to_name(ctx.db.upcast(), name_ref) { Either::Left(name) => { let args = segment .generic_arg_list() @@ -75,7 +71,7 @@ pub(super) fn lower_path( } // >::Foo desugars to Trait::Foo Some(trait_ref) => { - let path = Path::from_src(db, trait_ref.path()?, ctx)?; + let path = Path::from_src(trait_ref.path()?, ctx)?; let mod_path = (*path.mod_path).clone(); let num_segments = path.mod_path.segments.len(); kind = mod_path.kind; @@ -137,7 +133,7 @@ pub(super) fn lower_path( // We follow what it did anyway :) if segments.len() == 1 && kind == PathKind::Plain { if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { - if let Some(crate_id) = hygiene.local_inner_macros(db.upcast(), path) { + if let Some(crate_id) = hygiene.local_inner_macros(ctx.db.upcast(), path) { kind = PathKind::DollarCrate(crate_id); } } -- cgit v1.2.3