Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rustc_span: move pretty syntax from macro_backtrace to ExpnKind::descr.
  • Loading branch information
eddyb committed Jan 26, 2020
commit a7b0aa0675f6e81bdb62e614c020a6862381c98a
5 changes: 1 addition & 4 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
let mut err = self.cx.struct_span_err(
expn_data.call_site,
&format!(
"recursion limit reached while expanding the macro `{}`",
expn_data.kind.descr()
),
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
);
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
Expand Down
14 changes: 9 additions & 5 deletions src/librustc_span/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,16 @@ pub enum ExpnKind {
}

impl ExpnKind {
pub fn descr(&self) -> Symbol {
pub fn descr(&self) -> String {
match *self {
ExpnKind::Root => kw::PathRoot,
ExpnKind::Macro(_, descr) => descr,
ExpnKind::AstPass(kind) => Symbol::intern(kind.descr()),
ExpnKind::Desugaring(kind) => Symbol::intern(kind.descr()),
ExpnKind::Root => kw::PathRoot.to_string(),
ExpnKind::Macro(macro_kind, name) => match macro_kind {
MacroKind::Bang => format!("{}!", name),
MacroKind::Attr => format!("#[{}]", name),
MacroKind::Derive => format!("#[derive({})]", name),
},
ExpnKind::AstPass(kind) => kind.descr().to_string(),
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions src/librustc_span/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,19 +455,9 @@ impl Span {
}
// Don't print recursive invocations.
if !expn_data.call_site.source_equal(&prev_span) {
let (pre, post) = match expn_data.kind {
ExpnKind::Root => break,
ExpnKind::Desugaring(..) => ("desugaring of ", ""),
ExpnKind::AstPass(..) => ("", ""),
ExpnKind::Macro(macro_kind, _) => match macro_kind {
MacroKind::Bang => ("", "!"),
MacroKind::Attr => ("#[", "]"),
MacroKind::Derive => ("#[derive(", ")]"),
},
};
result.push(MacroBacktrace {
call_site: expn_data.call_site,
macro_decl_name: format!("{}{}{}", pre, expn_data.kind.descr(), post),
macro_decl_name: expn_data.kind.descr(),
def_site_span: expn_data.def_site,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/recursion_limit_macro.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: recursion limit reached while expanding the macro `recurse`
error: recursion limit reached while expanding `recurse!`
--> $DIR/recursion_limit_macro.rs:10:31
|
LL | ($t:tt $($tail:tt)*) => { recurse!($($tail)*) };
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/infinite/infinite-macro-expansion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
macro_rules! recursive {
() => (recursive!()) //~ ERROR recursion limit reached while expanding the macro `recursive`
() => (recursive!()) //~ ERROR recursion limit reached while expanding `recursive!`
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/infinite/infinite-macro-expansion.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: recursion limit reached while expanding the macro `recursive`
error: recursion limit reached while expanding `recursive!`
--> $DIR/infinite-macro-expansion.rs:2:12
|
LL | () => (recursive!())
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-16098.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ macro_rules! prob1 {
};
($n:expr) => {
if ($n % 3 == 0) || ($n % 5 == 0) {
$n + prob1!($n - 1); //~ ERROR recursion limit reached while expanding the macro `prob1`
$n + prob1!($n - 1); //~ ERROR recursion limit reached while expanding `prob1!`
} else {
prob1!($n - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-16098.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: recursion limit reached while expanding the macro `prob1`
error: recursion limit reached while expanding `prob1!`
--> $DIR/issue-16098.rs:7:18
|
LL | $n + prob1!($n - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/trace_faulty_macros.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | my_faulty_macro!();
= note: to `my_faulty_macro ! (bcd) ;`
= note: expanding `my_faulty_macro! { bcd }`

error: recursion limit reached while expanding the macro `my_recursive_macro`
error: recursion limit reached while expanding `my_recursive_macro!`
--> $DIR/trace_faulty_macros.rs:22:9
|
LL | my_recursive_macro!();
Expand Down