Skip to content

Commit

Permalink
[WIP] light + improve
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 7, 2024
1 parent 9545601 commit a454c64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,23 @@ fn maybe_use_metavar_location(
metavar_span: Span,
orig_tt: &TokenTree,
) -> TokenTree {
let insert = |mspans: &mut FxHashMap<_, _>, s, ms| mspans.try_insert(s, ms).is_ok();
let undelimited_seq = matches!(
stack.last(),
Some(Frame::Sequence {
tts: [_],
sep: None,
kleene_op: KleeneOp::ZeroOrMore | KleeneOp::OneOrMore,
..
})
);
if undelimited_seq {
return orig_tt.clone();
}

let insert = |mspans: &mut FxHashMap<_, _>, s, ms| match mspans.try_insert(s, ms) {
Ok(_) => true,
Err(err) => *err.entry.get() == ms,
};
let no_collision = match orig_tt {
TokenTree::Token(token, ..) => {
with_metavar_spans(|mspans| insert(mspans, token.span, metavar_span))
Expand All @@ -358,18 +374,7 @@ fn maybe_use_metavar_location(
&& insert(mspans, dspan.entire(), metavar_span)
}),
};
let undelimited_seq = || {
matches!(
stack.last(),
Some(Frame::Sequence {
tts: [_],
sep: None,
kleene_op: KleeneOp::ZeroOrMore | KleeneOp::OneOrMore,
..
})
)
};
if no_collision || undelimited_seq() || cx.source_map().is_imported(metavar_span) {
if no_collision || cx.source_map().is_imported(metavar_span) {
return orig_tt.clone();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/impl-trait-in-macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/impl-trait-in-macro.rs:9:9
|
LL | ($($tr:tt)*) => { impl $($tr)* };
| ----------
| ----
| |
| expected type parameter
| found type parameter
Expand Down

0 comments on commit a454c64

Please sign in to comment.