Skip to content

Commit bb4b0d8

Browse files
committed
Auto merge of #33020 - nikomatsakis:compiletest-json, r=alexcrichton
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 @jonathandturner. r? @alexcrichton
2 parents 66ff163 + 10d4cda commit bb4b0d8

File tree

71 files changed

+646
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+646
-484
lines changed

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
128128
test rustc_lint rustc_const_eval
129129

130130

131-
TOOL_DEPS_compiletest := test getopts log
131+
TOOL_DEPS_compiletest := test getopts log serialize
132132
TOOL_DEPS_rustdoc := rustdoc
133133
TOOL_DEPS_rustc := rustc_driver
134134
TOOL_DEPS_rustbook := std rustdoc

src/libsyntax/codemap.rs

+50
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,56 @@ impl CodeMap {
13941394
pub fn count_lines(&self) -> usize {
13951395
self.files.borrow().iter().fold(0, |a, f| a + f.count_lines())
13961396
}
1397+
1398+
pub fn macro_backtrace(&self, span: Span) -> Vec<MacroBacktrace> {
1399+
let mut last_span = DUMMY_SP;
1400+
let mut span = span;
1401+
let mut result = vec![];
1402+
loop {
1403+
let span_name_span = self.with_expn_info(span.expn_id, |expn_info| {
1404+
expn_info.map(|ei| {
1405+
let (pre, post) = match ei.callee.format {
1406+
MacroAttribute(..) => ("#[", "]"),
1407+
MacroBang(..) => ("", "!"),
1408+
};
1409+
let macro_decl_name = format!("{}{}{}",
1410+
pre,
1411+
ei.callee.name(),
1412+
post);
1413+
let def_site_span = ei.callee.span;
1414+
(ei.call_site, macro_decl_name, def_site_span)
1415+
})
1416+
});
1417+
1418+
match span_name_span {
1419+
None => break,
1420+
Some((call_site, macro_decl_name, def_site_span)) => {
1421+
// Don't print recursive invocations
1422+
if !call_site.source_equal(&last_span) {
1423+
result.push(MacroBacktrace {
1424+
call_site: call_site,
1425+
macro_decl_name: macro_decl_name,
1426+
def_site_span: def_site_span,
1427+
});
1428+
}
1429+
last_span = span;
1430+
span = call_site;
1431+
}
1432+
}
1433+
}
1434+
result
1435+
}
1436+
}
1437+
1438+
pub struct MacroBacktrace {
1439+
/// span where macro was applied to generate this code
1440+
pub call_site: Span,
1441+
1442+
/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]")
1443+
pub macro_decl_name: String,
1444+
1445+
/// span where macro was defined (if known)
1446+
pub def_site_span: Option<Span>,
13971447
}
13981448

13991449
// _____________________________________________________________________________

src/libsyntax/errors/emitter.rs

+9-38
Original file line numberDiff line numberDiff line change
@@ -577,46 +577,17 @@ impl EmitterWriter {
577577
fn print_macro_backtrace(&mut self,
578578
sp: Span)
579579
-> io::Result<()> {
580-
let mut last_span = codemap::DUMMY_SP;
581-
let mut span = sp;
582-
583-
loop {
584-
let span_name_span = self.cm.with_expn_info(span.expn_id, |expn_info| {
585-
expn_info.map(|ei| {
586-
let (pre, post) = match ei.callee.format {
587-
codemap::MacroAttribute(..) => ("#[", "]"),
588-
codemap::MacroBang(..) => ("", "!"),
589-
};
590-
let macro_decl_name = format!("in this expansion of {}{}{}",
591-
pre,
592-
ei.callee.name(),
593-
post);
594-
let def_site_span = ei.callee.span;
595-
(ei.call_site, macro_decl_name, def_site_span)
596-
})
597-
});
598-
let (macro_decl_name, def_site_span) = match span_name_span {
599-
None => break,
600-
Some((sp, macro_decl_name, def_site_span)) => {
601-
span = sp;
602-
(macro_decl_name, def_site_span)
603-
}
604-
};
605-
606-
// Don't print recursive invocations
607-
if !span.source_equal(&last_span) {
608-
let mut diag_string = macro_decl_name;
609-
if let Some(def_site_span) = def_site_span {
610-
diag_string.push_str(&format!(" (defined in {})",
611-
self.cm.span_to_filename(def_site_span)));
612-
}
613-
614-
let snippet = self.cm.span_to_string(span);
615-
print_diagnostic(&mut self.dst, &snippet, Note, &diag_string, None)?;
580+
for trace in self.cm.macro_backtrace(sp) {
581+
let mut diag_string =
582+
format!("in this expansion of {}", trace.macro_decl_name);
583+
if let Some(def_site_span) = trace.def_site_span {
584+
diag_string.push_str(
585+
&format!(" (defined in {})",
586+
self.cm.span_to_filename(def_site_span)));
616587
}
617-
last_span = span;
588+
let snippet = self.cm.span_to_string(sp);
589+
print_diagnostic(&mut self.dst, &snippet, Note, &diag_string, None)?;
618590
}
619-
620591
Ok(())
621592
}
622593
}

0 commit comments

Comments
 (0)