From c0dd36fd425416f5465abf7f12f5d3a14b35751d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Apr 2021 13:38:01 +0200 Subject: Store `#[derive]` attribute ID along macro invoc --- crates/hir_def/src/nameres/collector.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index f431da3f2..d13d7be27 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -13,7 +13,7 @@ use hir_expand::{ builtin_macro::find_builtin_macro, name::{AsName, Name}, proc_macro::ProcMacroExpander, - HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, + AttrId, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, }; use hir_expand::{InFile, MacroCallLoc}; use rustc_hash::{FxHashMap, FxHashSet}; @@ -216,7 +216,7 @@ struct MacroDirective { #[derive(Clone, Debug, Eq, PartialEq)] enum MacroDirectiveKind { FnLike { ast_id: AstIdWithPath }, - Derive { ast_id: AstIdWithPath }, + Derive { ast_id: AstIdWithPath, derive_attr: AttrId }, } struct DefData<'a> { @@ -831,10 +831,14 @@ impl DefCollector<'_> { Err(UnresolvedMacro) | Ok(Err(_)) => {} } } - MacroDirectiveKind::Derive { ast_id } => { - match derive_macro_as_call_id(ast_id, self.db, self.def_map.krate, |path| { - self.resolve_derive_macro(directive.module_id, &path) - }) { + MacroDirectiveKind::Derive { ast_id, derive_attr } => { + match derive_macro_as_call_id( + ast_id, + *derive_attr, + self.db, + self.def_map.krate, + |path| self.resolve_derive_macro(directive.module_id, &path), + ) { Ok(call_id) => { resolved.push((directive.module_id, call_id, directive.depth)); res = ReachedFixedPoint::No; @@ -1368,7 +1372,7 @@ impl ModCollector<'_, '_> { self.def_collector.unexpanded_macros.push(MacroDirective { module_id: self.module_id, depth: self.macro_depth + 1, - kind: MacroDirectiveKind::Derive { ast_id }, + kind: MacroDirectiveKind::Derive { ast_id, derive_attr: derive.id }, }); } } -- cgit v1.2.3 From 4ea5f690bc2692699208999f46a85a9872cbfc73 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Apr 2021 14:46:52 +0200 Subject: Undo path resolution hack for extern prelude We don't populate the extern prelude for block DefMaps anymore, so this is unnecessary --- crates/hir_def/src/nameres/path_resolution.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 60471937c..a9cf651d2 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -384,15 +384,10 @@ impl DefMap { } } }; - // Give precedence to names in outer `DefMap`s over the extern prelude; only check prelude - // from the crate DefMap. - let from_extern_prelude = match self.block { - Some(_) => PerNs::none(), - None => self - .extern_prelude - .get(name) - .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)), - }; + let from_extern_prelude = self + .extern_prelude + .get(name) + .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)); let from_prelude = self.resolve_in_prelude(db, name); -- cgit v1.2.3