Skip to content

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

Closed
@hasunwoo

Description

@hasunwoo

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"], &[]));
        };
    };

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