port compiletest to use JSON output
This uncovered a lot of bugs in compiletest and also some shortcomings of our existing JSON output. We had to add information to the JSON output, such as suggested text and macro backtraces. We also had to fix various bugs in the existing tests. Joint work with jntrnr.
This commit is contained in:
parent
95545e7adc
commit
01d2b4ab6b
63 changed files with 605 additions and 473 deletions
|
@ -1394,6 +1394,56 @@ impl CodeMap {
|
|||
pub fn count_lines(&self) -> usize {
|
||||
self.files.borrow().iter().fold(0, |a, f| a + f.count_lines())
|
||||
}
|
||||
|
||||
pub fn macro_backtrace(&self, span: Span) -> Vec<MacroBacktrace> {
|
||||
let mut last_span = DUMMY_SP;
|
||||
let mut span = span;
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
let span_name_span = self.with_expn_info(span.expn_id, |expn_info| {
|
||||
expn_info.map(|ei| {
|
||||
let (pre, post) = match ei.callee.format {
|
||||
MacroAttribute(..) => ("#[", "]"),
|
||||
MacroBang(..) => ("", "!"),
|
||||
};
|
||||
let macro_decl_name = format!("{}{}{}",
|
||||
pre,
|
||||
ei.callee.name(),
|
||||
post);
|
||||
let def_site_span = ei.callee.span;
|
||||
(ei.call_site, macro_decl_name, def_site_span)
|
||||
})
|
||||
});
|
||||
|
||||
match span_name_span {
|
||||
None => break,
|
||||
Some((call_site, macro_decl_name, def_site_span)) => {
|
||||
// Don't print recursive invocations
|
||||
if !call_site.source_equal(&last_span) {
|
||||
result.push(MacroBacktrace {
|
||||
call_site: call_site,
|
||||
macro_decl_name: macro_decl_name,
|
||||
def_site_span: def_site_span,
|
||||
});
|
||||
}
|
||||
last_span = span;
|
||||
span = call_site;
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MacroBacktrace {
|
||||
/// span where macro was applied to generate this code
|
||||
pub call_site: Span,
|
||||
|
||||
/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]")
|
||||
pub macro_decl_name: String,
|
||||
|
||||
/// span where macro was defined (if known)
|
||||
pub def_site_span: Option<Span>,
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue