diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-19 14:01:30 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-19 14:01:30 +0100 |
commit | e4f7f1e1bd2ca3c1816abf87779ad8893b7bf990 (patch) | |
tree | e843f284eca0c2a8d371c7af7c6532bace0d504d /crates/hir/src | |
parent | 3f1a220f32220cd4a664ca1adac5eb36e9eb33b2 (diff) | |
parent | f0507ab7c697ba4bcd59dd2f673dfff5072e3e1a (diff) |
Merge #8462
8462: Expand macros at type position r=jonas-schievink a=cynecx
Co-authored-by: cynecx <[email protected]>
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/semantics.rs | 7 | ||||
-rw-r--r-- | crates/hir/src/source_analyzer.rs | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 7955bf0b5..62500602a 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -6,10 +6,11 @@ use std::{cell::RefCell, fmt, iter::successors}; | |||
6 | 6 | ||
7 | use base_db::{FileId, FileRange}; | 7 | use base_db::{FileId, FileRange}; |
8 | use hir_def::{ | 8 | use hir_def::{ |
9 | body, | ||
9 | resolver::{self, HasResolver, Resolver, TypeNs}, | 10 | resolver::{self, HasResolver, Resolver, TypeNs}, |
10 | AsMacroCall, FunctionId, TraitId, VariantId, | 11 | AsMacroCall, FunctionId, TraitId, VariantId, |
11 | }; | 12 | }; |
12 | use hir_expand::{hygiene::Hygiene, name::AsName, ExpansionInfo}; | 13 | use hir_expand::{name::AsName, ExpansionInfo}; |
13 | use hir_ty::associated_type_shorthand_candidates; | 14 | use hir_ty::associated_type_shorthand_candidates; |
14 | use itertools::Itertools; | 15 | use itertools::Itertools; |
15 | use rustc_hash::{FxHashMap, FxHashSet}; | 16 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -853,8 +854,8 @@ impl<'a> SemanticsScope<'a> { | |||
853 | /// Resolve a path as-if it was written at the given scope. This is | 854 | /// Resolve a path as-if it was written at the given scope. This is |
854 | /// necessary a heuristic, as it doesn't take hygiene into account. | 855 | /// necessary a heuristic, as it doesn't take hygiene into account. |
855 | pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> { | 856 | pub fn speculative_resolve(&self, path: &ast::Path) -> Option<PathResolution> { |
856 | let hygiene = Hygiene::new(self.db.upcast(), self.file_id); | 857 | let ctx = body::LowerCtx::new(self.db.upcast(), self.file_id); |
857 | let path = Path::from_src(path.clone(), &hygiene)?; | 858 | let path = Path::from_src(path.clone(), &ctx)?; |
858 | resolve_hir_path(self.db, &self.resolver, &path) | 859 | resolve_hir_path(self.db, &self.resolver, &path) |
859 | } | 860 | } |
860 | } | 861 | } |
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}; | |||
9 | 9 | ||
10 | use hir_def::{ | 10 | use hir_def::{ |
11 | body::{ | 11 | body::{ |
12 | self, | ||
12 | scope::{ExprScopes, ScopeId}, | 13 | scope::{ExprScopes, ScopeId}, |
13 | Body, BodySourceMap, | 14 | Body, BodySourceMap, |
14 | }, | 15 | }, |
@@ -202,8 +203,8 @@ impl SourceAnalyzer { | |||
202 | db: &dyn HirDatabase, | 203 | db: &dyn HirDatabase, |
203 | macro_call: InFile<&ast::MacroCall>, | 204 | macro_call: InFile<&ast::MacroCall>, |
204 | ) -> Option<MacroDef> { | 205 | ) -> Option<MacroDef> { |
205 | let hygiene = Hygiene::new(db.upcast(), macro_call.file_id); | 206 | let ctx = body::LowerCtx::new(db.upcast(), macro_call.file_id); |
206 | let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &hygiene))?; | 207 | let path = macro_call.value.path().and_then(|ast| Path::from_src(ast, &ctx))?; |
207 | 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()) |
208 | } | 209 | } |
209 | 210 | ||
@@ -281,7 +282,9 @@ impl SourceAnalyzer { | |||
281 | } | 282 | } |
282 | 283 | ||
283 | // This must be a normal source file rather than macro file. | 284 | // This must be a normal source file rather than macro file. |
284 | let hir_path = Path::from_src(path.clone(), &Hygiene::new(db.upcast(), self.file_id))?; | 285 | let hygiene = Hygiene::new(db.upcast(), self.file_id); |
286 | let ctx = body::LowerCtx::with_hygiene(&hygiene); | ||
287 | let hir_path = Path::from_src(path.clone(), &ctx)?; | ||
285 | 288 | ||
286 | // 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 |
287 | // trying to resolve foo::bar. | 290 | // trying to resolve foo::bar. |