diff options
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 33ef87563..b1a014074 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -3,6 +3,8 @@ | |||
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use hir_def::{attr::Attr, type_ref::TypeRef}; | ||
7 | use hir_expand::hygiene::Hygiene; | ||
6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 8 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
7 | use ra_cfg::CfgOptions; | 9 | use ra_cfg::CfgOptions; |
8 | use ra_syntax::{ | 10 | use ra_syntax::{ |
@@ -11,7 +13,6 @@ use ra_syntax::{ | |||
11 | }; | 13 | }; |
12 | 14 | ||
13 | use crate::{ | 15 | use crate::{ |
14 | attr::Attr, | ||
15 | code_model::{Module, ModuleSource}, | 16 | code_model::{Module, ModuleSource}, |
16 | db::{AstDatabase, DefDatabase, HirDatabase}, | 17 | db::{AstDatabase, DefDatabase, HirDatabase}, |
17 | generics::HasGenericParams, | 18 | generics::HasGenericParams, |
@@ -19,8 +20,7 @@ use crate::{ | |||
19 | ids::MacroCallLoc, | 20 | ids::MacroCallLoc, |
20 | resolve::Resolver, | 21 | resolve::Resolver, |
21 | ty::Ty, | 22 | ty::Ty, |
22 | type_ref::TypeRef, | 23 | AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, |
23 | AssocItem, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, | ||
24 | TypeAlias, | 24 | TypeAlias, |
25 | }; | 25 | }; |
26 | 26 | ||
@@ -129,7 +129,7 @@ impl ImplData { | |||
129 | ) -> Self { | 129 | ) -> Self { |
130 | let target_trait = node.target_trait().map(TypeRef::from_ast); | 130 | let target_trait = node.target_trait().map(TypeRef::from_ast); |
131 | let target_type = TypeRef::from_ast_opt(node.target_type()); | 131 | let target_type = TypeRef::from_ast_opt(node.target_type()); |
132 | let ctx = LocationCtx::new(db, module, file_id); | 132 | let ctx = LocationCtx::new(db, module.id, file_id); |
133 | let negative = node.is_negative(); | 133 | let negative = node.is_negative(); |
134 | let items = if let Some(item_list) = node.item_list() { | 134 | let items = if let Some(item_list) = node.item_list() { |
135 | item_list | 135 | item_list |
@@ -182,7 +182,7 @@ impl ModuleImplBlocks { | |||
182 | ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { | 182 | ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { |
183 | let mut source_map = ImplSourceMap::default(); | 183 | let mut source_map = ImplSourceMap::default(); |
184 | let crate_graph = db.crate_graph(); | 184 | let crate_graph = db.crate_graph(); |
185 | let cfg_options = crate_graph.cfg_options(module.krate.crate_id()); | 185 | let cfg_options = crate_graph.cfg_options(module.id.krate); |
186 | 186 | ||
187 | let result = ModuleImplBlocks::collect(db, cfg_options, module, &mut source_map); | 187 | let result = ModuleImplBlocks::collect(db, cfg_options, module, &mut source_map); |
188 | (Arc::new(result), Arc::new(source_map)) | 188 | (Arc::new(result), Arc::new(source_map)) |
@@ -228,10 +228,11 @@ impl ModuleImplBlocks { | |||
228 | owner: &dyn ast::ModuleItemOwner, | 228 | owner: &dyn ast::ModuleItemOwner, |
229 | file_id: HirFileId, | 229 | file_id: HirFileId, |
230 | ) { | 230 | ) { |
231 | let hygiene = Hygiene::new(db, file_id); | ||
231 | for item in owner.items_with_macros() { | 232 | for item in owner.items_with_macros() { |
232 | match item { | 233 | match item { |
233 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { | 234 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { |
234 | let attrs = Attr::from_attrs_owner(file_id, &impl_block_ast, db); | 235 | let attrs = Attr::from_attrs_owner(&impl_block_ast, &hygiene); |
235 | if attrs.map_or(false, |attrs| { | 236 | if attrs.map_or(false, |attrs| { |
236 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | 237 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) |
237 | }) { | 238 | }) { |
@@ -248,7 +249,7 @@ impl ModuleImplBlocks { | |||
248 | } | 249 | } |
249 | ast::ItemOrMacro::Item(_) => (), | 250 | ast::ItemOrMacro::Item(_) => (), |
250 | ast::ItemOrMacro::Macro(macro_call) => { | 251 | ast::ItemOrMacro::Macro(macro_call) => { |
251 | let attrs = Attr::from_attrs_owner(file_id, ¯o_call, db); | 252 | let attrs = Attr::from_attrs_owner(¯o_call, &hygiene); |
252 | if attrs.map_or(false, |attrs| { | 253 | if attrs.map_or(false, |attrs| { |
253 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | 254 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) |
254 | }) { | 255 | }) { |
@@ -256,14 +257,13 @@ impl ModuleImplBlocks { | |||
256 | } | 257 | } |
257 | 258 | ||
258 | //FIXME: we should really cut down on the boilerplate required to process a macro | 259 | //FIXME: we should really cut down on the boilerplate required to process a macro |
259 | let ast_id = db.ast_id_map(file_id).ast_id(¯o_call).with_file_id(file_id); | 260 | let ast_id = AstId::new(file_id, db.ast_id_map(file_id).ast_id(¯o_call)); |
260 | if let Some(path) = macro_call | 261 | if let Some(path) = |
261 | .path() | 262 | macro_call.path().and_then(|path| Path::from_src(path, &hygiene)) |
262 | .and_then(|path| Path::from_src(Source { ast: path, file_id }, db)) | ||
263 | { | 263 | { |
264 | if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path) | 264 | if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path) |
265 | { | 265 | { |
266 | let call_id = MacroCallLoc { def: def.id, ast_id }.id(db); | 266 | let call_id = db.intern_macro(MacroCallLoc { def: def.id, ast_id }); |
267 | let file_id = call_id.as_file(MacroFileKind::Items); | 267 | let file_id = call_id.as_file(MacroFileKind::Items); |
268 | if let Some(item_list) = | 268 | if let Some(item_list) = |
269 | db.parse_or_expand(file_id).and_then(ast::MacroItems::cast) | 269 | db.parse_or_expand(file_id).and_then(ast::MacroItems::cast) |