Skip to content

Rust analyzer expands wrong macro when running recursive expansion. #12505

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
hasunwoo opened this issue Jun 11, 2022 · 0 comments · Fixed by #14781
Closed

Rust analyzer expands wrong macro when running recursive expansion. #12505

hasunwoo opened this issue Jun 11, 2022 · 0 comments · Fixed by #14781
Labels
A-macro macro expansion A-nameres name, path and module resolution C-bug Category: bug

Comments

@hasunwoo
Copy link

rust-analyzer version: ad6810e 2022-06-06 stable
rustc version: rustc 1.62.0-nightly (a5ad0d29a 2022-05-12)

fn main() {
    //attempt to expand below macro
    println!("test");
}

mod text_io {
    #[macro_export]
    macro_rules! println {
        ($($arg:tt)*) => {{
            std::println!("called test_macro in text_io.");
            std::println!($($arg)*);
        }}
    }
}

Result when expanding macro recursively on line 3
image

It should expand macro exported by text_io module. but it expands println macro from standard library. I think rust analyzer confuse macro exported by text_io module with macro from standard library because they have same name.

output of command 'cargo expand'

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
fn main() {
    {
        {
            ::std::io::_print(::core::fmt::Arguments::new_v1(
                &["called test_macro in text_io.\n"],
                &[],
            ));
        };
        {
            ::std::io::_print(::core::fmt::Arguments::new_v1(&["test\n"], &[]));
        };
    };
}

recursive expansion of line 3 should look like below

    {
        {
            ::std::io::_print(::core::fmt::Arguments::new_v1(
                &["called test_macro in text_io.\n"],
                &[],
            ));
        };
        {
            ::std::io::_print(::core::fmt::Arguments::new_v1(&["test\n"], &[]));
        };
    };
@Veykril Veykril added A-nameres name, path and module resolution A-macro macro expansion labels Jun 11, 2022
@flodiebold flodiebold added the C-bug Category: bug label Jun 11, 2022
@hasunwoo hasunwoo changed the title Rust analyzer expands wrong macro when running recursive expansion of macro. Rust analyzer expands wrong macro when running recursive expansion. Jun 11, 2022
@bors bors closed this as completed in 9b33874 May 11, 2023
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

Successfully merging a pull request may close this issue.

3 participants