Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,17 @@ impl TtParser {
ErrorReported(guarantee)
}

fn nameize<I: Iterator<Item = NamedMatch>>(
fn nameize<I: ExactSizeIterator<Item = NamedMatch>>(
&self,
matcher: &[MatcherLoc],
mut res: I,
) -> NamedMatches {
// Make that each metavar has _exactly one_ binding. If so, insert the binding into the
// `NamedParseResult`. Otherwise, it's an error.
let mut ret_val = FxHashMap::default();
if res.len() == 0 {
return FxHashMap::default();
}
let mut ret_val = FxHashMap::with_capacity_and_hasher(res.len(), Default::default());
for loc in matcher {
if let &MatcherLoc::MetaVarDecl { bind, .. } = loc
&& ret_val
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub(super) fn transcribe<'a>(
src_span,
DelimSpacing::new(Spacing::Alone, Spacing::Alone)
)],
result: Vec::new(),
result: Vec::with_capacity(src.tts.len()),
result_stack: Vec::new(),
};

Expand Down Expand Up @@ -271,7 +271,8 @@ pub(super) fn transcribe<'a>(
tscx.marker.mark_span(&mut span.open);
tscx.marker.mark_span(&mut span.close);
tscx.stack.push(Frame::new_delimited(delimited, span, *spacing));
tscx.result_stack.push(mem::take(&mut tscx.result));
tscx.result_stack
.push(mem::replace(&mut tscx.result, Vec::with_capacity(delimited.tts.len())));
}

// Nothing much to do here. Just push the token to the result, being careful to
Expand Down