Skip to content

Wrong function is resolved #8904

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

Closed
kristoff3r opened this issue May 21, 2021 · 3 comments
Closed

Wrong function is resolved #8904

kristoff3r opened this issue May 21, 2021 · 3 comments

Comments

@kristoff3r
Copy link

The js_sys crate has 2 functions called global: one in the outer scope and one in RegExp. When I try to use the outer one rustc handles it fine, but rust-analyzer consistently gives me docs and type hints for the RegExp one, and sometimes an error because that one takes 1 argument while the outer one takes 0.

This reproduces the problem for me on the latest rust-analyzer release:

Cargo.toml

[dependencies]
js-sys = "0.3.51"

main.rs

fn main() {
    let _res = js_sys::global();
}

Incidentally this example also triggers #5412

@Veykril
Copy link
Member

Veykril commented May 21, 2021

That's due to us not resolving attribute macros yet, cc #6029

@Veykril Veykril closed this as completed May 21, 2021
@kristoff3r
Copy link
Author

The correct function does not have an attribute macro, only the one that wrongly gets resolved does, so shouldn't the problem be the other way around if that is the cause?

@Veykril
Copy link
Member

Veykril commented May 21, 2021

The RegExp::global function is declared in an extern block, which is being changed by the proc macro. To RA this looks like an ordinary extern function and since its defined prior to the actual free standing global function I believe that resolution just picks the first function as that's what RA sees first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants