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

Shadowing macro from std doesn't work #17623

Closed
Veetaha opened this issue Jul 18, 2024 · 3 comments
Closed

Shadowing macro from std doesn't work #17623

Veetaha opened this issue Jul 18, 2024 · 3 comments
Labels
A-macro macro expansion A-nameres name, path and module resolution C-bug Category: bug

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Jul 18, 2024

Take the following code as an example.

code snippet to reproduce:

macro_rules! vec {
    ($elem:expr; $n:expr) => (std::vec![::core::convert::Into::into($elem); $n]);
    ($($x:expr),* $(,)?) => (std::vec![$(::core::convert::Into::into($x)),* ]);
}

fn main() {
    let actual: Vec<String> = vec!["foo", "bar", "baz"];
    assert_eq!(actual, ["foo", "bar", "baz"]);
}

RA can't understand that this local vec macro shadows the macro from std. The code compiles fine with rustc though.

image

Meta

rust-analyzer version: rust-analyzer version: 0.3.2037-standalone [/home/veetaha/.vscode-server/extensions/rust-lang.rust-analyzer-0.3.2037-linux-x64/server/rust-analyzer]

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: VSCode

@Veetaha Veetaha added the C-bug Category: bug label Jul 18, 2024
@roife roife added the A-nameres name, path and module resolution label Jul 18, 2024
@roife
Copy link
Member

roife commented Jul 19, 2024

I find that if I comment out assert_eq, then vec will correctly resolve to the local one.

@Veykril
Copy link
Member

Veykril commented Jul 19, 2024

We don't resolve macros correctly when there is shadowing happening with textual macro scopes, there is a bunch of related issues #7084 #14862

Our macro name resolution is generally not working correctly in this regard

@roife roife added the A-macro macro expansion label Jul 19, 2024
@Veykril
Copy link
Member

Veykril commented Sep 1, 2024

This works now

@Veykril Veykril closed this as completed Sep 1, 2024
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 C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants