Rollup merge of #78603 - petrochenkov:fourdigits, r=matthewjasper
expand: Tweak a comment in implementation of `macro_rules` The answer to the removed FIXME is that we don't apply mark to the span `sp` just because that span is no longer used. We could apply it, but that would just be unnecessary extra work. The comments in code tell why the span is unused, it's a span of `$var` literally, which is lost for `tt` variables because their tokens are outputted directly, but kept for other variables which are outputted as [groups](https://doc.rust-lang.org/nightly/proc_macro/struct.Group.html) and `sp` is kept as the group's span. Closes https://github.com/rust-lang/rust/issues/2887
This commit is contained in:
commit
540d4743cc
1 changed files with 11 additions and 9 deletions
|
@ -232,17 +232,19 @@ pub(super) fn transcribe<'a>(
|
||||||
// the meta-var.
|
// the meta-var.
|
||||||
let ident = MacroRulesNormalizedIdent::new(orignal_ident);
|
let ident = MacroRulesNormalizedIdent::new(orignal_ident);
|
||||||
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
|
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
|
||||||
if let MatchedNonterminal(ref nt) = cur_matched {
|
if let MatchedNonterminal(nt) = cur_matched {
|
||||||
// FIXME #2887: why do we apply a mark when matching a token tree meta-var
|
let token = if let NtTT(tt) = &**nt {
|
||||||
// (e.g. `$x:tt`), but not when we are matching any other type of token
|
// `tt`s are emitted into the output stream directly as "raw tokens",
|
||||||
// tree?
|
// without wrapping them into groups.
|
||||||
if let NtTT(ref tt) = **nt {
|
tt.clone()
|
||||||
result.push(tt.clone().into());
|
|
||||||
} else {
|
} else {
|
||||||
|
// Other variables are emitted into the output stream as groups with
|
||||||
|
// `Delimiter::None` to maintain parsing priorities.
|
||||||
|
// `Interpolated` is currenty used for such groups in rustc parser.
|
||||||
marker.visit_span(&mut sp);
|
marker.visit_span(&mut sp);
|
||||||
let token = TokenTree::token(token::Interpolated(nt.clone()), sp);
|
TokenTree::token(token::Interpolated(nt.clone()), sp)
|
||||||
|
};
|
||||||
result.push(token.into());
|
result.push(token.into());
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// We were unable to descend far enough. This is an error.
|
// We were unable to descend far enough. This is an error.
|
||||||
return Err(cx.struct_span_err(
|
return Err(cx.struct_span_err(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue