Open
Description
I wanted to demonstrate name resolution detecting maro expansion shadowing
#![feature(decl_macro)]
mod foo {
pub macro import_bar($name:ident) {
use bar::time_travel as $name;
}
}
mod bar {
pub macro time_travel($name:ident) {
// The uncommented version never errors.
use foo::import_bar as $name;
// use bar::time_travel as $name;
}
}
use foo::*;
// Only if the invocation uses the glob import and `time_travel`
// shadows it to something *different*, does it produce an error.
/*foo::*/import_bar!(m2);
m2!(import_bar);
However, while the example works as expected, "warning: unused import: foo::*
" is produced, despite the import being used by the first macro invocation (and trying to remove it results in an error).
This is likely caused by us marking imports as used after expansion is finished, so the use foo::import_bar as import_bar;
import gets marked as used, instead of use foo::*;
.
But the macro couldn't have expanded without the later-shadowed glob import, so maybe expansion should mark the imports used to find the macro, as used, early?