diff options
| author | bors <bors@rust-lang.org> | 2017-05-27 17:38:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-27 17:38:11 +0000 |
| commit | 9337ad5baec6e63ac6231193b2c0a4d810198b1d (patch) | |
| tree | 8368a95a55bc8b8fc5a48a6383a0db974c184ff3 /src/libsyntax | |
| parent | a11c26f6acb1b8890c36196e88371840c01e201d (diff) | |
| parent | f8b66a001d74946565ee2e7df58afc9918455da1 (diff) | |
| download | rust-9337ad5baec6e63ac6231193b2c0a4d810198b1d.tar.gz rust-9337ad5baec6e63ac6231193b2c0a4d810198b1d.zip | |
Auto merge of #42103 - jorendorff:master, r=estebank
trace_macro: Show both the macro call and its expansion. #42072. See #42072 for the initial motivation behind this. The change is not the minimal fix, but I want this behavior almost every time I use `trace_macros`.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index a9252d0818e..15042e529e5 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -84,6 +84,12 @@ impl TTMacroExpander for MacroRulesMacroExpander { } } +fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) { + let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp); + let mut values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new); + values.push(message); +} + /// Given `lhses` and `rhses`, this is the new macro we create fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, sp: Span, @@ -93,9 +99,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, rhses: &[quoted::TokenTree]) -> Box<MacResult+'cx> { if cx.trace_macros() { - let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp); - let mut values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new); - values.push(format!("expands to `{}! {{ {} }}`", name, arg)); + trace_macros_note(cx, sp, format!("expanding `{}! {{ {} }}`", name, arg)); } // Which arm's failure should we report? (the one furthest along) @@ -117,6 +121,11 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt, }; // rhs has holes ( `$id` and `$(...)` that need filled) let tts = transcribe(&cx.parse_sess.span_diagnostic, Some(named_matches), rhs); + + if cx.trace_macros() { + trace_macros_note(cx, sp, format!("to `{}`", tts)); + } + let directory = Directory { path: cx.current_expansion.module.directory.clone(), ownership: cx.current_expansion.directory_ownership, |
