Skip to content

Commit 540d474

Browse files
authored
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 #2887
2 parents 8ed31d2 + 7652bc3 commit 540d474

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,19 @@ pub(super) fn transcribe<'a>(
232232
// the meta-var.
233233
let ident = MacroRulesNormalizedIdent::new(orignal_ident);
234234
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
235-
if let MatchedNonterminal(ref nt) = cur_matched {
236-
// FIXME #2887: why do we apply a mark when matching a token tree meta-var
237-
// (e.g. `$x:tt`), but not when we are matching any other type of token
238-
// tree?
239-
if let NtTT(ref tt) = **nt {
240-
result.push(tt.clone().into());
235+
if let MatchedNonterminal(nt) = cur_matched {
236+
let token = if let NtTT(tt) = &**nt {
237+
// `tt`s are emitted into the output stream directly as "raw tokens",
238+
// without wrapping them into groups.
239+
tt.clone()
241240
} else {
241+
// Other variables are emitted into the output stream as groups with
242+
// `Delimiter::None` to maintain parsing priorities.
243+
// `Interpolated` is currenty used for such groups in rustc parser.
242244
marker.visit_span(&mut sp);
243-
let token = TokenTree::token(token::Interpolated(nt.clone()), sp);
244-
result.push(token.into());
245-
}
245+
TokenTree::token(token::Interpolated(nt.clone()), sp)
246+
};
247+
result.push(token.into());
246248
} else {
247249
// We were unable to descend far enough. This is an error.
248250
return Err(cx.struct_span_err(

0 commit comments

Comments
 (0)