From f640f2dbb42829821f4ab96b4ad95a609cc1d5b3 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 2 Jul 2021 15:17:21 +0200 Subject: [PATCH] Fix incorrect guard for NameRefClass attribute resolution --- crates/ide/src/hover.rs | 20 ++++++++++++++++++++ crates/ide_db/src/defs.rs | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index f7a4c679a1b..f5fa8508085 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -4134,4 +4134,24 @@ pub fn foo() {} "#]], ) } + + #[test] + fn hover_attr_path_qualifier() { + check( + r#" +//- /foo.rs crate:foo + +//- /lib.rs crate:main.rs deps:foo +#[fo$0o::bar()] +struct Foo; + "#, + expect![[r#" + *foo* + + ```rust + extern crate foo + ``` + "#]], + ) + } } diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 02eb55ac35f..a6c6db6c06a 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -393,7 +393,8 @@ impl NameRefClass { Some(true) => sema.resolve_path(&path).and_then(|resolved| { match resolved { // Don't wanna collide with builtin attributes here like `test` hence guard - PathResolution::Def(module @ ModuleDef::Module(_)) if path == top_path => { + // so only resolve to modules that aren't the last segment + PathResolution::Def(module @ ModuleDef::Module(_)) if path != top_path => { Some(NameRefClass::Definition(Definition::ModuleDef(module))) } PathResolution::Macro(mac) if mac.kind() == hir::MacroKind::Attr => {