Skip to content

Commit acad033

Browse files
committed
expand: extract error_recursion_limit_reached
1 parent 64ea295 commit acad033

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/librustc_expand/expand.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -606,21 +606,26 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
606606
}
607607
}
608608

609-
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
610-
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
611-
let expn_data = self.cx.current_expansion.id.expn_data();
612-
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
613-
let mut err = self.cx.struct_span_err(
609+
fn error_recursion_limit_reached(&mut self) {
610+
let expn_data = self.cx.current_expansion.id.expn_data();
611+
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
612+
self.cx
613+
.struct_span_err(
614614
expn_data.call_site,
615615
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
616-
);
617-
err.help(&format!(
616+
)
617+
.help(&format!(
618618
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
619619
suggested_limit, self.cx.ecfg.crate_name,
620-
));
621-
err.emit();
622-
self.cx.trace_macros_diag();
623-
FatalError.raise();
620+
))
621+
.emit();
622+
self.cx.trace_macros_diag();
623+
FatalError.raise();
624+
}
625+
626+
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
627+
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
628+
self.error_recursion_limit_reached();
624629
}
625630

626631
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());

0 commit comments

Comments
 (0)