Skip to content

Include! macro behaviors differently between rust-analyzer and standard library #7846

@YuJuncen

Description

@YuJuncen

Hello! Recently, I found that seems there are some undocumented magic in the include! macro.

With this directory structure:

├── Cargo.toml
├── magic
│   ├── lib.rs
│   └── magic.rs
├── src
│   └── main.rs

... and those files:

// magic/lib.rs
pub mod magic;
// magic/magic.rs
pub fn hello() {
    println!("hello, world!")
}
// main.rs
include!("../magic/lib.rs");

fn main() {
    magic::hello();
}

Maybe a little strange, these compiles:

image

... and rustc told us, those macro was expanded to:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;

pub mod magic {
    pub fn hello() {
        {
            ::std::io::_print(::core::fmt::Arguments::new_v1(&["hello, world!\n"],
                                                             &match () {
                                                                  () => [],
                                                              }));
        }
    }
}
fn main() { magic::hello(); }

... but rust-analyzer gave another version of the include! macro expansion, with an error unresolved module:

image

RA version:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionE-has-instructionsIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions