eupn / macrotest

Test harness for declarative and procedural macros expansion via `cargo-expand`
47 stars 9 forks source link

Wrong lines stripped if an input contains module-level attribute #77

Closed dtolnay closed 2 years ago

dtolnay commented 2 years ago

Macrotest assumes that the output of cargo expand always begins with the following exactly 5 lines.

https://github.com/eupn/macrotest/blob/779cfa5b70899a9793ba8be5f2d78fcb0eb0436f/src/expand.rs#L390-L391

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

However, that is not the case if there is an inner attribute in the input. For example the following crate:

#![feature(proc_macro_span)]

fn foo() {}

expands as:

#![feature(prelude_import)]
#![feature(proc_macro_span)]
#[prelude_import]
use std::prelude::rust_2018::*;
#[macro_use]
extern crate std;
fn foo() {}

and after stripping exactly 5 lines from the front, macrotest's .expanded.rs will result in:

extern crate std;
fn foo() {}

which is not what is expected. The correct expansion would be:

#![feature(proc_macro_span)]
fn foo() {}