Skip to content

Most of macros from std are not resolved #1688

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
oxalica opened this issue Aug 15, 2019 · 5 comments · Fixed by #1795
Closed

Most of macros from std are not resolved #1688

oxalica opened this issue Aug 15, 2019 · 5 comments · Fixed by #1795

Comments

@oxalica
Copy link
Contributor

oxalica commented Aug 15, 2019

I'm using rust-analyzer from master with vscode extension.

I found it failed to infer the type of vec! (no type decorator, even no {unknown}), but it works well with my simple implementation using macro_rules. So I think there is something wrong resolving them.

Most of macros from std do not work, except std::dbg!, while dbg! (without prefix) still fails.

The output from "Rust Analyzer Language Server Trace" contains no errors.

Screenshot:
Screenshot_20190816_020553

@DJMcNab
Copy link
Contributor

DJMcNab commented Aug 18, 2019

EDIT: Nevermind, I misread the issue

Also sorry for my multiple replies. I guess GitHub doesn't use idempotency tokens

@oxalica
Copy link
Contributor Author

oxalica commented Aug 28, 2019

It seems to be caused by #[macro_use] not working. Is it implemented yet?
Related: #60

Here is a simple example:
In crate1/src/lib.rs:

#[macro_export]
macro_rules! foo {
    () => { 42 };
}

In crate2/src/main.rs:

#[macro_use] // This has no effect
extern crate crate1;

// use crate1::*; // Uncomment this, and everything works

fn main() {
    let _t = foo!(); // No type inferred
}

bors bot added a commit that referenced this issue Sep 5, 2019
1743: Support `#[macro_use]` on `extern crate` r=matklad a=uHOOCCOOHu

Unfortunately, #1688 is still an issue. My guess is wrong :(

Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
@oxalica
Copy link
Contributor Author

oxalica commented Sep 5, 2019

Some related issue (may be blocking issue):

  1. Textual scoped macro is partial handled now, only module level macros will be resolved (in an approximate way) and expanded.
  2. $crate in macro is not supported.

@lnicola
Copy link
Member

lnicola commented Sep 9, 2019

So this is still not working, however vec! is a bit problematic because it has two versions, gated with #[cfg]. Neither vec! nor std::vec! work.

But note that vec! is defined in liballoc. format! is defined in the same crate, and while format! doesn't work, std::format! does. So my suspicion is that there are two bugs:

  • #[cfg] is not supported
  • there's a prelude definition problem preventing format! from working (since dbg! from libstd is fine now)

@oxalica
Copy link
Contributor Author

oxalica commented Sep 9, 2019

#[cfg] works. The current issue is still in name resolving and importing, and I'm working on it.

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

Successfully merging a pull request may close this issue.

3 participants