Skip to content

R-A does not resolve macro calls correctly when the name clashes with core::macros::bultin macros. #13683

Closed
@LouisGariepy

Description

@LouisGariepy

rust-analyzer version: v0.4.1299

rustc version: 1.65.0

MRE

To reproduce the problem, create a new crate (I'll call it my_crate for the sake of this example) with a main.rs and a lib.rs.

The lib.rs:

// lib.rs

/// Some crazy documentation
#[macro_export]
macro_rules! column {
    () => {
        "hello"
    };
}

The main.rs

// main.rs
use my_crate::column; // <-- This macro's name clashes with `core::macros::builtin::column`

fn main() {
    // R-A resolves this as the `core::macros::builtin::column` macro (which returns a u32), 
    // so it thinks something is wrong with this code.
    // rustc is able to compile this just fine (i.e. it resolves our own `column` macro correctly)
    let _ = column!().chars();
}

What I expected to happen

I expected R-A to analyze understand that our macro shadows the built-in one. This is the correct Rust behavior.

Aliasing our macro import with as solves the problem, but should not be required.

What actually happens

R-A complains about {unknown} methods, and when the macro call is hovered, it offers the documentation for the bult-in macro instead of our own macro.

And yet, the code compiles just fine, because it is completely valid.

Screenshot from 2022-11-26 20-34-23

Screenshot from 2022-11-26 20-34-53

Screenshot from 2022-11-26 20-36-03

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionA-nameresname, path and module resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions