Skip to content

RA is broken for #[actix_rt::main] with proc macros enabled #4315

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
SomeoneToIgnore opened this issue May 5, 2020 · 8 comments · Fixed by #4431
Closed

RA is broken for #[actix_rt::main] with proc macros enabled #4315

SomeoneToIgnore opened this issue May 5, 2020 · 8 comments · Fixed by #4431
Labels
A-macro macro expansion E-hard

Comments

@SomeoneToIgnore
Copy link
Contributor

Cargo.toml:

[package]
name = "zzz"
version = "0.0.1"
edition = "2018"

[dependencies]
actix-rt = "1.1"
actix-web = "2.0"

main.rs:

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    let test = test();
    dbg!(test);
    println!("Hello, world!");
    Ok(())
}

#[derive(Debug)]
struct Test {
    test: i32,
}

fn test() -> Test {
    Test { test: 2 }
}

Enable proc macro and loadOutDirsFromCheck settings.

Expected: inlay hints present, highlighting works, completions proposed
Actual: very few RA features such as code lens are present, the rest is not working across the whole project

Here's how it looks with disabled proc macros:
image

Notice the hint and the highlighting.
When I toggle the proc macro checkbox and reload the server, I get this:
Screenshot 2020-05-05 at 13 09 06

This happens in the code of a whole project, not only in the main.rs, making RA pretty useless.
Another interesting thing to notice that RA works fine with tokio:
image

@edwin0cheng edwin0cheng added the A-macro macro expansion label May 5, 2020
@edwin0cheng
Copy link
Member

edwin0cheng commented May 6, 2020

Aiya, after some investigation, I ended up confirming the root cause of this bug:

There is a panic in actix_rt case:

thread '<unnamed>' panicked at 'can't resolve local ptr to SyntaxNode: SyntaxNodePtr { range: 160..329, kind: IMPL_DEF }', crates\ra_syntax\src\ptr.rs:30:28

It is caused by some proc-macro generated are inconsistent. I added some dbg! and here are two expansions expanded by the same struct. (by #[derive(derive_more::From)])

impl::core::convert::From<(h2::Error)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(h2::Error))->ConnectError{ConnectError::H2(original)}}impl::core::convert::From<(SslError)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(SslError))->ConnectError{ConnectError::SslError(original)}}impl::core::convert::From<(String)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(String))->ConnectError{ConnectError::SslHandshakeError(original)}}impl::core::convert::From<(io::Error)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(io::Error))->ConnectError{ConnectError::Io(original)}}impl::core::convert::From<(ResolveError)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(ResolveError))->ConnectError{ConnectError::Resolver(original)}}

impl::core::convert::From<(ResolveError)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(ResolveError))->ConnectError{ConnectError::Resolver(original)}}impl::core::convert::From<(String)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(String))->ConnectError{ConnectError::SslHandshakeError(original)}}impl::core::convert::From<(SslError)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(SslError))->ConnectError{ConnectError::SslError(original)}}impl::core::convert::From<(h2::Error)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(h2::Error))->ConnectError{ConnectError::H2(original)}}impl::core::convert::From<(io::Error)>forConnectError{#[allow(unused_variables)]#[inline]fnfrom(original:(io::Error))->ConnectError{ConnectError::Io(original)}}

Noted that the orders of tokens are different, and it is due to the fact that derive-more crate is using HashMap such that this order is non-deterministic.

And we had some discussion for the general solution of this problem and I will start to study and implement a solution soon.

@bjorn3
Copy link
Member

bjorn3 commented May 6, 2020

Even if there is a solution to this problem, derive-more should still be fixed to be deterministic. Otherwise crates using it have non reproducible builds. Maybe we should warn about non-deterministic expansions?

@edwin0cheng
Copy link
Member

Yeah, I will submit an issue to them.

@SomeoneToIgnore
Copy link
Contributor Author

SomeoneToIgnore commented May 6, 2020

Seems that there's exactly 3 usages of HashMap in their code: https://github.com/JelteF/derive_more/search?q=HashMap&unscoped_q=HashMap

hopefully, the PR to fix it will be small.

@edwin0cheng
Copy link
Member

Upstream issue submitted, and if someone could write a blog post to call out people please don't use Hashmap in proc-macro, I will buy them a beer :)

@rayanmargham
Copy link

image
It is still happening on my machine, please reopen the issue

@Veykril
Copy link
Member

Veykril commented Jun 27, 2022

What is the error you are getting, what rustc version and what rust-analzer version are you using?

@rayanmargham
Copy link

never mind I've fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion E-hard
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants