Skip to content

Commit

Permalink
Rollup merge of rust-lang#83050 - osa1:issue83048, r=matthewjasper
Browse files Browse the repository at this point in the history
Run analyses before thir-tree dumps

Fixes rust-lang#83048
  • Loading branch information
Dylan-DPC committed Mar 23, 2021
2 parents 673d0db + b24902e commit e26635a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
53 changes: 30 additions & 23 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,6 @@ pub fn print_after_hir_lowering<'tcx>(
format!("{:#?}", krate)
}),

ThirTree => {
let mut out = String::new();
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
debug!("pretty printing THIR tree");
for did in tcx.body_owners() {
let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
let arena = thir::Arena::default();
let thir =
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
}
out
}

_ => unreachable!(),
};

Expand All @@ -501,18 +486,40 @@ fn print_with_analysis(
ppm: PpMode,
ofile: Option<&Path>,
) -> Result<(), ErrorReported> {
let mut out = Vec::new();

tcx.analysis(LOCAL_CRATE)?;

match ppm {
Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
let out = match ppm {
Mir => {
let mut out = Vec::new();
write_mir_pretty(tcx, None, &mut out).unwrap();
String::from_utf8(out).unwrap()
}

MirCFG => {
let mut out = Vec::new();
write_mir_graphviz(tcx, None, &mut out).unwrap();
String::from_utf8(out).unwrap()
}

ThirTree => {
let mut out = String::new();
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
debug!("pretty printing THIR tree");
for did in tcx.body_owners() {
let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
let arena = thir::Arena::default();
let thir =
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
}
out
}

_ => unreachable!(),
}
};

let out = std::str::from_utf8(&out).unwrap();
write_or_print(out, ofile);
write_or_print(&out, ofile);

Ok(())
}
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ impl PpMode {

pub fn needs_analysis(&self) -> bool {
use PpMode::*;
matches!(*self, Mir | MirCFG)
matches!(*self, Mir | MirCFG | ThirTree)
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue-83048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// compile-flags: -Z unpretty=thir-tree

pub fn main() {
break; //~ ERROR: `break` outside of a loop [E0268]
}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-83048.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0268]: `break` outside of a loop
--> $DIR/issue-83048.rs:4:5
|
LL | break;
| ^^^^^ cannot `break` outside of a loop

error: aborting due to previous error

For more information about this error, try `rustc --explain E0268`.

0 comments on commit e26635a

Please sign in to comment.