Open
Description
Maybe this is just a misunderstanding of hygiene, but if a macro 2.0 is defined and used in the same function-like scope (function/const) then it can't resolve its own items:
#![feature(decl_macro)]
trait Tr { fn foo(self); }
const C: () = {
macro implit {
() => {
fn doit() { println!("Hi"); }
impl ::Tr for () {
fn foo(self) {
doit();
}
}
}
}
#[cfg(works)]
const T: () = { implit!(); () }; // this works with no error
#[cfg(not(works))]
implit!(); //~ ERROR cannot find function `doit` in this scope
};
fn main() {
().foo();
}
Expected Result
doit()
should resolve to the fn doit
in the scope of the macro, printing Hi!
Actual Result
Resolution error.
Note that
- Having the macro defined and used in a module (i.e., if
const C: ()
was amod _xyz
) does work. - Having the macro defined in 1 function-like scope, and used in a child scope of it (see
cfg(works)
) also works. This error only occurs if the macro is defined and used in the same scope.