From cf3b4f1e208247c9d171273dabff9c6b3c98a240 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 10 Apr 2021 17:49:12 +0200 Subject: hir_ty: Expand macros at type position --- crates/hir/src/semantics.rs | 4 +++- crates/hir/src/source_analyzer.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 7955bf0b5..29c0821cf 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -6,6 +6,7 @@ use std::{cell::RefCell, fmt, iter::successors}; use base_db::{FileId, FileRange}; use hir_def::{ + body, resolver::{self, HasResolver, Resolver, TypeNs}, AsMacroCall, FunctionId, TraitId, VariantId, }; @@ -854,7 +855,8 @@ impl<'a> SemanticsScope<'a> { /// necessary a heuristic, as it doesn't take hygiene into account. pub fn speculative_resolve(&self, path: &ast::Path) -> Option { let hygiene = Hygiene::new(self.db.upcast(), self.file_id); - let path = Path::from_src(path.clone(), &hygiene)?; + let ctx = body::LowerCtx::with_hygiene(&hygiene); + let path = Path::from_src(path.clone(), &ctx)?; resolve_hir_path(self.db, &self.resolver, &path) } } diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 847d2537d..0895bd6f1 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -9,6 +9,7 @@ use std::{iter::once, sync::Arc}; use hir_def::{ body::{ + self, scope::{ExprScopes, ScopeId}, Body, BodySourceMap, }, @@ -202,8 +203,8 @@ impl SourceAnalyzer { db: &dyn HirDatabase, macro_call: InFile<&ast::MacroCall>, ) -> Option { - let hygiene = Hygiene::new(db.upcast(), macro_call.file_id); - let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?; + let ctx = body::LowerCtx::new(db.upcast(), macro_call.file_id); + let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &ctx))?; self.resolver.resolve_path_as_macro(db.upcast(), path.mod_path()).map(|it| it.into()) } @@ -281,7 +282,9 @@ impl SourceAnalyzer { } // This must be a normal source file rather than macro file. - let hir_path = Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?; + let hygiene = Hygiene::new(db.upcast(), self.file_id); + let ctx = body::LowerCtx::with_hygiene(&hygiene); + let hir_path = Path::from_src(path.clone(), &ctx)?; // Case where path is a qualifier of another path, e.g. foo::bar::Baz where we // trying to resolve foo::bar. -- cgit v1.2.3 From 28ef7c20d79803403be58eeffa18ab1fb21e261c Mon Sep 17 00:00:00 2001 From: cynecx Date: Mon, 12 Apr 2021 16:24:48 +0200 Subject: hir_ty: deal with TypeRef::Macro in HirFormatter --- crates/hir/src/semantics.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 29c0821cf..62500602a 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::{self, HasResolver, Resolver, TypeNs}, AsMacroCall, FunctionId, TraitId, VariantId, }; -use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo}; +use hir_expand::{name::AsName, ExpansionInfo}; use hir_ty::associated_type_shorthand_candidates; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; @@ -854,8 +854,7 @@ impl<'a> SemanticsScope<'a> { /// Resolve a path as-if it was written at the given scope. This is /// necessary a heuristic, as it doesn't take hygiene into account. pub fn speculative_resolve(&self, path: &ast::Path) -> Option { - let hygiene = Hygiene::new(self.db.upcast(), self.file_id); - let ctx = body::LowerCtx::with_hygiene(&hygiene); + let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id); let path = Path::from_src(path.clone(), &ctx)?; resolve_hir_path(self.db, &self.resolver, &path) } -- cgit v1.2.3