Description
Procedural macros generate tokens, but sometimes the information is kept not in tokens, but rather in the lack of them (compare with #50130).
In particular, paths in use
are resolved as absolute-by-default.
Effectively, they have one extra segment added at the start during name resolution
use a::b::c;
=>
use {{root}}::a::b::c;
// Or using the syntax from https://github.com/rust-lang/rust/issues/44660
use crate::a::b::c;
The added root segment has its hygienic context and may be resolved at definition site (similarly to use $crate::a::b::c
from Macros 1.0) or at call site (similarly to use a::b::c
in Macros 1.0).
The question is how to determine this context, given that the root segment doesn't have its own explicit token?
Without its own token the crate root needs to inherit context from some other token that really exists (compare with #50122), but what token it should be exactly is a pretty tough choice.
macro m() {
use a::b::c; // ctxt(root) is most probably def-site because *everything* here has def-site context
use a::$b; // ctxt(root) is probably def-site?
use ::$a; // ctxt(root) is probably def-site??
use $a; // ctxt(root) is ???
$use_passed_from_the_outside a::b::c; // ctxt(root) is call-site??? should it be inherited from `use`?
$use_passed_from_the_outside $a; // this is not even funny
}
I hope this issue doesn't affect Procedural Macros 1.2 (crossing my fingers).
Since all tokens generated and accepted by those macros are supposed to have the same call-site context, implicitly created crate roots will have the same call-site context anyway regardless of the token from which it's going to inherit it.