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

Could not resolve macro iproduct #6793

Closed
grunweg opened this issue Dec 10, 2020 · 7 comments
Closed

Could not resolve macro iproduct #6793

grunweg opened this issue Dec 10, 2020 · 7 comments
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now

Comments

@grunweg
Copy link

grunweg commented Dec 10, 2020

Thanks for your work on the project. So far, the experience of having rust-analyzer support has been a huge boon!
I just found my first rust-analyzer bug: rust-analyzer fails to resolve a trivial macro.

Minimised input

$ cat Cargo.toml
// [package] section omitted for brevity
[dependencies]
itertools = "0.9.0"
$ cat src/main.rs 
fn test(_input: &str) {}

fn main() {
    let t = ["toast", "bread"];
    use itertools::iproduct;
    for (a, b) in itertools::iproduct!(t.iter(), t.iter()) {
         test(&(a.to_string() + b));
    }
    println!("Hello, world!");
}

Expected output
rust-analyzer doesn't output any diagnostic.

Actual output
I get a diagnostic for line 6 (the one with the for loop): "could not resolve macro iproduct" (twice)

Meta information
I'm using the atom plugin with the rust-analyzer server binary; I don't think this matters.
Does not happen with the 2020-11-30 release.
Does reproduce with the 2020-12-07 release (which I just updated to; downgraded to 2020-11-30 to continue developing seamlessly).

I can try to bisect the bug, but I'm not sure how long that'd take me. (Compiling rust-analyzer takes a while on my older notebook.) Let me know if this would be helpful.

@lnicola
Copy link
Member

lnicola commented Dec 10, 2020

Duplicate of #1165.

@lnicola lnicola closed this as completed Dec 10, 2020
@flodiebold
Copy link
Member

As an additional note, this does not happen in the 2020-11-30 release because the macro-error diagnostic was newly added. You can set "rust-analyzer.diagnostics.disabled": ["macro-error"] to hide it without having to downgrade.

@flodiebold
Copy link
Member

Actually, @lnicola while there's a local import there, the macro is referred to with the full path, so it shouldn't matter 🤔

@flodiebold flodiebold reopened this Dec 10, 2020
@flodiebold flodiebold added A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now labels Dec 10, 2020
@lnicola
Copy link
Member

lnicola commented Dec 10, 2020

It still seems related to the local import, since moving it to the top fixes the errors. But go to definition on the macro works -- strange.

@lnicola
Copy link
Member

lnicola commented Dec 10, 2020

Is it an error to use a qualified macro like this? cargo check complains if I remove the use:

error: cannot find macro `iproduct` in this scope
 --> src/main.rs:5:19
  |
5 |     for (a, b) in itertools::iproduct!(t.iter(), t.iter()) {
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: consider importing this macro:
          itertools::iproduct
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find macro `iproduct` in this scope
 --> src/main.rs:5:19
  |
5 |     for (a, b) in itertools::iproduct!(t.iter(), t.iter()) {
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: consider importing this macro:
          itertools::iproduct
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

@flodiebold
Copy link
Member

flodiebold commented Dec 10, 2020

Ah, the macro is written in a way that directly calls iproduct! recursively. So yeah, this is expected. You could make an issue in the itertools repository about this, but they may have some reason (backwards compatibility?) for doing this (instead of something like $crate::iproduct!).

@grunweg
Copy link
Author

grunweg commented Dec 10, 2020

Wow, that was a quick response. (By now, I had bisected it to the emission of the diagnostic.)
Thanks for all the advice! I can confirm that moving the import to the top fixes the diagnostics issue for me.
The diagnostic emission breaks syntax highlighting for me, but I'll file a follow-up issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

3 participants