Skip to content

Commit 3b69781

Browse files
committed
Tweak fully_expand_fragment loop.
Control flow never gets past the end of the `ExpandResult::Retry` match arm, due to the `span_bug` and the `continue`. Therefore, the code after the match can only be reached from the `ExpandResult::Ready` arm. This commit moves that code after the match into the `ExpandResult::Ready` arm, avoiding the need for the `continue` in the `ExpandResult::Retry` arm.
1 parent 79c4d02 commit 3b69781

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/rustc_expand/src/expand.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
471471
self.cx.force_mode = force;
472472

473473
let fragment_kind = invoc.fragment_kind;
474-
let (expanded_fragment, new_invocations) = match self.expand_invoc(invoc, &ext.kind) {
474+
match self.expand_invoc(invoc, &ext.kind) {
475475
ExpandResult::Ready(fragment) => {
476476
let mut derive_invocations = Vec::new();
477477
let derive_placeholders = self
@@ -503,13 +503,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
503503
})
504504
.unwrap_or_default();
505505

506-
let (fragment, collected_invocations) =
506+
let (expanded_fragment, collected_invocations) =
507507
self.collect_invocations(fragment, &derive_placeholders);
508508
// We choose to expand any derive invocations associated with this macro
509509
// invocation *before* any macro invocations collected from the output
510510
// fragment.
511511
derive_invocations.extend(collected_invocations);
512-
(fragment, derive_invocations)
512+
513+
progress = true;
514+
if expanded_fragments.len() < depth {
515+
expanded_fragments.push(Vec::new());
516+
}
517+
expanded_fragments[depth - 1].push((expn_id, expanded_fragment));
518+
invocations.extend(derive_invocations.into_iter().rev());
513519
}
514520
ExpandResult::Retry(invoc) => {
515521
if force {
@@ -520,17 +526,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
520526
} else {
521527
// Cannot expand, will retry this invocation later.
522528
undetermined_invocations.push((invoc, Some(ext)));
523-
continue;
524529
}
525530
}
526-
};
527-
528-
progress = true;
529-
if expanded_fragments.len() < depth {
530-
expanded_fragments.push(Vec::new());
531531
}
532-
expanded_fragments[depth - 1].push((expn_id, expanded_fragment));
533-
invocations.extend(new_invocations.into_iter().rev());
534532
}
535533

536534
self.cx.current_expansion = orig_expansion_data;

0 commit comments

Comments
 (0)