Skip to content

fix: resolve each definition when a use statement imports multiple items#22655

Open
Hmikihiro wants to merge 1 commit into
rust-lang:masterfrom
Hmikihiro:hover_doc
Open

fix: resolve each definition when a use statement imports multiple items#22655
Hmikihiro wants to merge 1 commit into
rust-lang:masterfrom
Hmikihiro:hover_doc

Conversation

@Hmikihiro

@Hmikihiro Hmikihiro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

When it finds definitions on a NameRef of a use statement, it returns multiple definitions as NameRefClass::DefinitionPerNs. Each definition is registered in the vector of definiotns.

In goto_definition, hover and highlights, It show multiple items in use statement.

Fixes #22632

AI-disclosure: Antigravity

スクリーンショット 2026-06-28 13 31 19 スクリーンショット 2026-06-28 13 31 50
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 28, 2026
@rustbot

This comment has been minimized.

When it finds definitions on a NameRef of a use statement, it returns multiple definitions as NameRefClass::DefinitionPerNs. Each definition is registered in the vector of definiotns.

    In goto_definition, hover and highlights, It show multiple items in use statement.

    Fixes rust-lang#22632

    AI-disclosure: Antigravity

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The right way, I'm pretty sure about that, is not to do add a different variant to NameRefClass. What it is - I don't know. It might be changing Definition to include all namespaces, or returning multiple NameRefClasses from classify(), or having a new method, or something else entirely.

Also note that @dfireBird has already claimed #19421, which is highly related (although not the same), you might want to discuss their approach with them.

View changes since this review

macro_ns: macros(),
let type_ns = types().or_else(items);
if let Some(PathResolution::Def(ModuleDef::Module(module))) = type_ns
&& module.is_crate_root(db)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That if is definitely incorrect. Why did you add it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I think that fix was just a stopgap measure. The issue is that the system is searching for and finding the value inside the crate at the same level as foo, which represents the crate, so I'll look into it and fix that part as well.

#[test]
fn function_doesnt_shadow_crate_in_use_tree() {
check(
r#"
//- /main.rs crate:main deps:foo
use foo$0::{foo};
//- /foo.rs crate:foo
pub fn foo() {}
"#,
expect![[r#"
*foo*
```rust
extern crate foo
```
"#]],
)
}

*foo*

```rust
extern crate foo
```

---

```rust
foo
```

```rust
pub fn foo()
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. In analysis we won't resolve this to the function because it wasn't recorded yet in the module, but in IDE resolution we have everything recorded.

I don't know if we can solve this, but I don't think this justifies this if. It can also lead to wrong resolution, e.g.:

use crate as foo;
fn foo() {}

mod bar {
    use super::foo$0;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, how do we even get to this function in this case? It should call resolve_hir_path_qualifier() instead.

@rustbot

rustbot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #22673) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

3 participants