diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index b9e35fea7c..cca51b8167 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1890,7 +1890,7 @@ impl ModCollector<'_, '_> { } fn collect_macro_call(&mut self, mac: &MacroCall) { - let mut ast_id = AstIdWithPath::new(self.file_id(), mac.ast_id, (*mac.path).clone()); + let ast_id = AstIdWithPath::new(self.file_id(), mac.ast_id, (*mac.path).clone()); // Case 1: try to resolve in legacy scope and expand macro_rules let mut error = None; @@ -1941,11 +1941,6 @@ impl ModCollector<'_, '_> { } // Case 2: resolve in module scope, expand during name resolution. - // We rewrite simple path `macro_name` to `self::macro_name` to force resolve in module scope only. - if ast_id.path.is_ident() { - ast_id.path.kind = PathKind::Super(0); - } - self.def_collector.unresolved_macros.push(MacroDirective { module_id: self.module_id, depth: self.macro_depth + 1, diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index 730a4593d9..45448ba81b 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs @@ -349,8 +349,10 @@ macro_rules! m { "#, expect![[r#" crate + S: t v "#]], ); + // FIXME: should not expand. legacy macro scoping is not implemented. } #[test] @@ -427,6 +429,7 @@ macro_rules! baz { "#, expect![[r#" crate + NotFoundBefore: t v Ok: t v OkAfter: t v OkShadowStop: t v @@ -462,6 +465,7 @@ macro_rules! baz { crate::m3::m5 "#]], ); + // FIXME: should not see `NotFoundBefore` } #[test] @@ -994,3 +998,26 @@ structs!(Foo); "#]], ); } + +#[test] +fn macro_in_prelude() { + check( + r#" +//- /lib.rs crate:lib deps:std +global_asm!(); + +//- /std.rs crate:std +pub mod prelude { + pub mod rust_2018 { + pub macro global_asm() { + pub struct S; + } + } +} + "#, + expect![[r#" + crate + S: t v + "#]], + ) +} diff --git a/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs index f0f7725dbf..ea0f35501b 100644 --- a/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs +++ b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs @@ -63,7 +63,7 @@ foo::bar!(92); macro_rules! m { () => {} } m!(); m2!(); - //^^ error: unresolved macro `self::m2!` + //^^ error: unresolved macro `m2!` "#, ); }