-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
A-macromacro expansionmacro expansionE-has-instructionsIssue has some instructions and pointers to code to get startedIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right now
Description
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:
... 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:
Metadata
Metadata
Assignees
Labels
A-macromacro expansionmacro expansionE-has-instructionsIssue has some instructions and pointers to code to get startedIssue has some instructions and pointers to code to get startedS-actionableSomeone could pick this issue up and work on it right nowSomeone could pick this issue up and work on it right now


