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

global_asm! proc macro is not resolved #9687

Closed
budde25 opened this issue Jul 24, 2021 · 7 comments
Closed

global_asm! proc macro is not resolved #9687

budde25 opened this issue Jul 24, 2021 · 7 comments
Labels
A-macro macro expansion A-nameres name, path and module resolution

Comments

@budde25
Copy link

budde25 commented Jul 24, 2021

global_asm! proc macro throws there error that it is an unresolved-macro-call
Error: "unresolved macro self::global_asm! rust-analyzer(unresolved-macro-call)"

image

this does compile output of cargo check:

cargo check
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

Also not sure if it is relevant but I also have #![no_std]

@jonas-schievink
Copy link
Contributor

What Rust version are you using? This works fine for me. Can you provide the full source code needed to reproduce this?

@budde25
Copy link
Author

budde25 commented Jul 24, 2021

rustc 1.55.0-nightly (67b03007c 2021-07-23)
rust-analyzer INFO [7/24/2021, 8:57:52 AM]: Extension version: 0.2.678

That is interesting because it has been broken for me since I have been working on this project about 6 months ago, across different computers. I wonder if it has something to do with my project setup. The repo is https://github.com/budde25/os, the relevant code is in lib.rs.

@Andy-Python-Programmer
Copy link

Andy-Python-Programmer commented Jul 26, 2021

I am experiencing the same bug.

rustc version: rustc 1.56.0-nightly (d9aa28767 2021-07-24)
rust analyzer version: v0.2.678

For me it has recently broken after the proc macro bug is fixed.

@Bobo1239
Copy link
Contributor

Bisected the issue to rust-lang/rust#87227 (included since nightly-2021-07-20) which probably makes sense. Don't have time to look into the rust-analyzer side but hope this helps.

@jonas-schievink jonas-schievink added A-macro macro expansion A-nameres name, path and module resolution labels Jul 26, 2021
@jonas-schievink
Copy link
Contributor

Repro:

//- /lib.rs crate:lib deps:std
global_asm!();

//- /std.rs crate:std
pub mod prelude {
    pub mod rust_2018 {
        pub macro global_asm() {
            pub struct S;
        }
    }
}

This doesn't resolve, because we first check for global_asm! in the legacy scope, and then rewrite its path as self::global_asm. However, self::global_asm never resolves in the prelude.

This issue ties in with existing bugs around macro resolution described in #8828 (comment)

bors bot added a commit that referenced this issue Jul 28, 2021
9700: fix: Remove the legacy macro scoping hack r=matklad a=jonas-schievink

This stops prepending `self::` to single-ident macro paths, resolving even legacy-scoped macros using the fixed-point algorithm. This is not correct, but a lot easier than fixing this properly (which involves pushing a new scope for every macro definition and invocation).

This allows resolution of macros from the prelude, fixing #9687.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
@jonas-schievink
Copy link
Contributor

fixed by #9700

@budde25
Copy link
Author

budde25 commented Jul 28, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion A-nameres name, path and module resolution
Projects
None yet
Development

No branches or pull requests

4 participants