Skip to content

Commit 7518492

Browse files
committed
expand: extract error_wrong_fragment_kind
1 parent acad033 commit 7518492

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/librustc_expand/expand.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
623623
FatalError.raise();
624624
}
625625

626+
/// A macro's expansion does not fit in this fragment kind.
627+
/// For example, a non-type macro in a type position.
628+
fn error_wrong_fragment_kind(&mut self, kind: AstFragmentKind, mac: &ast::Mac, span: Span) {
629+
let msg = format!(
630+
"non-{kind} macro in {kind} position: {path}",
631+
kind = kind.name(),
632+
path = pprust::path_to_string(&mac.path),
633+
);
634+
self.cx.span_err(span, &msg);
635+
self.cx.trace_macros_diag();
636+
}
637+
626638
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
627639
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
628640
self.error_recursion_limit_reached();
@@ -643,13 +655,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
643655
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
644656
result
645657
} else {
646-
let msg = format!(
647-
"non-{kind} macro in {kind} position: {path}",
648-
kind = fragment_kind.name(),
649-
path = pprust::path_to_string(&mac.path),
650-
);
651-
self.cx.span_err(span, &msg);
652-
self.cx.trace_macros_diag();
658+
self.error_wrong_fragment_kind(fragment_kind, &mac, span);
653659
fragment_kind.dummy(span)
654660
};
655661
self.cx.current_expansion.prior_type_ascription = prev;

0 commit comments

Comments
 (0)