Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module alias misidentified as function declaration #4202

Closed
CleanCut opened this issue Apr 29, 2020 · 6 comments · Fixed by #4269
Closed

Module alias misidentified as function declaration #4202

CleanCut opened this issue Apr 29, 2020 · 6 comments · Fixed by #4269
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium

Comments

@CleanCut
Copy link

With Cargo.toml:

[dependencies]
nalgebra-glm = { version = "0.6.0", features = ["serde-serialize"] }

In src/lib.rs:

pub use nalgebra_glm as glm;

glm is identified as a function declaration. It is a module alias, so it should be identified as a namespace, probably with some sort of alias modifier.

image

@matklad matklad added E-medium E-has-instructions Issue has some instructions and pointers to code to get started labels Apr 29, 2020
@matklad
Copy link
Member

matklad commented Apr 29, 2020

Good catch! I think this should be fixed in classify_name_ref function here:

https://github.com/rust-analyzer/rust-analyzer/blob/549ce9a9cf25efa3eba6549f96b2e43bc640faa9/crates/ra_ide_db/src/defs.rs#L105

@bnjjj
Copy link
Contributor

bnjjj commented Apr 29, 2020

It's a part where I didn't already dig in. I will give a try this week :)

@bnjjj
Copy link
Contributor

bnjjj commented Apr 29, 2020

I took a look at the code in

And it seems I should add to https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/defs.rs#L121

this kind of pattern:

ast::Alias(it) => {
    let def = sema.to_def(&it)?;
    Some(Definition::ModuleDef(def.into()))
},

And then add ToDef implementation for use alias ?

@Veetaha
Copy link
Contributor

Veetaha commented Apr 29, 2020

Maybe duplicates #4030

@matklad
Copy link
Member

matklad commented Apr 30, 2020

I belive #4030 is different. There, we confuse namespaces, here, we don't handle aliases at all.

this kind of pattern:

I dont't think so, as there's there's no ModuleDef for an alias. Rather, the reference that is aliased should be resoled with sema.resolve_path

@CleanCut
Copy link
Author

CleanCut commented May 2, 2020

@matklad Did you mean to link to classify_name_ref? (You actually linked to classify_name)

https://github.com/rust-analyzer/rust-analyzer/blob/549ce9a9cf25efa3eba6549f96b2e43bc640faa9/crates/ra_ide_db/src/defs.rs#L198

bnjjj added a commit to bnjjj/rust-analyzer that referenced this issue May 2, 2020
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bors bors bot closed this as completed in b1a5dc8 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-has-instructions Issue has some instructions and pointers to code to get started E-medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants