Skip to content

Commit a7b0aa0

Browse files
committed
rustc_span: move pretty syntax from macro_backtrace to ExpnKind::descr.
1 parent 787c458 commit a7b0aa0

File tree

10 files changed

+18
-27
lines changed

10 files changed

+18
-27
lines changed

src/librustc_expand/expand.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
596596
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
597597
let mut err = self.cx.struct_span_err(
598598
expn_data.call_site,
599-
&format!(
600-
"recursion limit reached while expanding the macro `{}`",
601-
expn_data.kind.descr()
602-
),
599+
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
603600
);
604601
err.help(&format!(
605602
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",

src/librustc_span/hygiene.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,16 @@ pub enum ExpnKind {
732732
}
733733

734734
impl ExpnKind {
735-
pub fn descr(&self) -> Symbol {
735+
pub fn descr(&self) -> String {
736736
match *self {
737-
ExpnKind::Root => kw::PathRoot,
738-
ExpnKind::Macro(_, descr) => descr,
739-
ExpnKind::AstPass(kind) => Symbol::intern(kind.descr()),
740-
ExpnKind::Desugaring(kind) => Symbol::intern(kind.descr()),
737+
ExpnKind::Root => kw::PathRoot.to_string(),
738+
ExpnKind::Macro(macro_kind, name) => match macro_kind {
739+
MacroKind::Bang => format!("{}!", name),
740+
MacroKind::Attr => format!("#[{}]", name),
741+
MacroKind::Derive => format!("#[derive({})]", name),
742+
},
743+
ExpnKind::AstPass(kind) => kind.descr().to_string(),
744+
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
741745
}
742746
}
743747
}

src/librustc_span/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,9 @@ impl Span {
455455
}
456456
// Don't print recursive invocations.
457457
if !expn_data.call_site.source_equal(&prev_span) {
458-
let (pre, post) = match expn_data.kind {
459-
ExpnKind::Root => break,
460-
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
461-
ExpnKind::AstPass(..) => ("", ""),
462-
ExpnKind::Macro(macro_kind, _) => match macro_kind {
463-
MacroKind::Bang => ("", "!"),
464-
MacroKind::Attr => ("#[", "]"),
465-
MacroKind::Derive => ("#[derive(", ")]"),
466-
},
467-
};
468458
result.push(MacroBacktrace {
469459
call_site: expn_data.call_site,
470-
macro_decl_name: format!("{}{}{}", pre, expn_data.kind.descr(), post),
460+
macro_decl_name: expn_data.kind.descr(),
471461
def_site_span: expn_data.def_site,
472462
});
473463
}

src/test/ui/did_you_mean/recursion_limit_macro.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: recursion limit reached while expanding the macro `recurse`
1+
error: recursion limit reached while expanding `recurse!`
22
--> $DIR/recursion_limit_macro.rs:10:31
33
|
44
LL | ($t:tt $($tail:tt)*) => { recurse!($($tail)*) };

src/test/ui/infinite/infinite-macro-expansion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
macro_rules! recursive {
2-
() => (recursive!()) //~ ERROR recursion limit reached while expanding the macro `recursive`
2+
() => (recursive!()) //~ ERROR recursion limit reached while expanding `recursive!`
33
}
44

55
fn main() {

src/test/ui/infinite/infinite-macro-expansion.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: recursion limit reached while expanding the macro `recursive`
1+
error: recursion limit reached while expanding `recursive!`
22
--> $DIR/infinite-macro-expansion.rs:2:12
33
|
44
LL | () => (recursive!())

src/test/ui/issues/issue-16098.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ macro_rules! prob1 {
44
};
55
($n:expr) => {
66
if ($n % 3 == 0) || ($n % 5 == 0) {
7-
$n + prob1!($n - 1); //~ ERROR recursion limit reached while expanding the macro `prob1`
7+
$n + prob1!($n - 1); //~ ERROR recursion limit reached while expanding `prob1!`
88
} else {
99
prob1!($n - 1);
1010
}

src/test/ui/issues/issue-16098.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: recursion limit reached while expanding the macro `prob1`
1+
error: recursion limit reached while expanding `prob1!`
22
--> $DIR/issue-16098.rs:7:18
33
|
44
LL | $n + prob1!($n - 1);

src/test/ui/macros/trace_faulty_macros.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | my_faulty_macro!();
2020
= note: to `my_faulty_macro ! (bcd) ;`
2121
= note: expanding `my_faulty_macro! { bcd }`
2222

23-
error: recursion limit reached while expanding the macro `my_recursive_macro`
23+
error: recursion limit reached while expanding `my_recursive_macro!`
2424
--> $DIR/trace_faulty_macros.rs:22:9
2525
|
2626
LL | my_recursive_macro!();

0 commit comments

Comments
 (0)