Skip to content

Run analyses before thir-tree dumps #83050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -2293,7 +2293,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`.