rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.2k stars 1.59k forks source link

`unresolved-macro-call` suggests to import crate/module instead of macro #10702

Open jonasbb opened 2 years ago

jonasbb commented 2 years ago
// color-eyre = "0.5.11"

fn main() {
    eyre!();
}

In this code snippet, rust-analyzer correctly shows the "unresolved macro eyre!" error. The code action suggests to import/qualify the macro as color_eyre::eyre which does not work, since color_eyre::eyre is the re-export of the eyre crate. The correct path is color_eyre::eyre::eyre. The error happens with the standard configuration of rust-analyzer. The wrong path suggestion does not come from rustc, since it is not in the cargo check error message.

rust-analyzer version: 04f03a360 2021-11-01 stable VSCode: 1.62

jonas-schievink commented 2 years ago

Huh, interesting, our import infra doesn't handle reexported crates at all, so nothing in eyre is seen from a crate that only depends on color-eyre. Actually that's not true, ImportMap handles reexports across crates.

jonas-schievink commented 2 years ago

This is caused by the reexports of the eyre! macro and can be reproduced using this lib.rs (both reexports are needed):

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

pub use eyre as format_err;
pub use eyre as anyhow;