Skip to content

Commit ef7ae6d

Browse files
committed
Add -Zast and -Zast-noexpand to dump AST w/o JSON
-Zast behaves like -Zast-json but uses {:#?} pretty-printing instead of converting to JSON. -Zast-noexpand is the pretty-printing counterpart to -Zast-json-noexpand.
1 parent 94d4589 commit ef7ae6d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/librustc/session/config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
862862
"print the arguments passed to the linker"),
863863
print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
864864
"prints the llvm optimization passes being run"),
865+
ast: bool = (false, parse_bool, [UNTRACKED],
866+
"pretty-print the AST and halt"),
867+
ast_noexpand: bool = (false, parse_bool, [UNTRACKED],
868+
"pretty-print the pre-expansion AST and halt"),
865869
ast_json: bool = (false, parse_bool, [UNTRACKED],
866870
"print the AST as JSON and halt"),
867871
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
@@ -2404,6 +2408,10 @@ mod tests {
24042408
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24052409
opts.debugging_opts.print_llvm_passes = true;
24062410
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2411+
opts.debugging_opts.ast = true;
2412+
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2413+
opts.debugging_opts.ast_noexpand = true;
2414+
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24072415
opts.debugging_opts.ast_json = true;
24082416
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
24092417
opts.debugging_opts.ast_json_noexpand = true;

src/librustc_driver/driver.rs

+8
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a,
501501

502502
sess.diagnostic().set_continue_after_error(true);
503503

504+
if sess.opts.debugging_opts.ast_noexpand {
505+
println!("{:#?}", &krate);
506+
}
507+
504508
if sess.opts.debugging_opts.ast_json_noexpand {
505509
println!("{}", json::as_json(&krate));
506510
}
@@ -733,6 +737,10 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
733737
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS");
734738
}
735739

740+
if sess.opts.debugging_opts.ast {
741+
println!("{:#?}", &krate);
742+
}
743+
736744
if sess.opts.debugging_opts.ast_json {
737745
println!("{}", json::as_json(&krate));
738746
}

src/librustc_driver/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
484484

485485
if sess.opts.debugging_opts.parse_only ||
486486
sess.opts.debugging_opts.show_span.is_some() ||
487+
sess.opts.debugging_opts.ast_noexpand ||
487488
sess.opts.debugging_opts.ast_json_noexpand {
488489
control.after_parse.stop = Compilation::Stop;
489490
}
490491

491492
if sess.opts.debugging_opts.no_analysis ||
493+
sess.opts.debugging_opts.ast ||
492494
sess.opts.debugging_opts.ast_json {
493495
control.after_hir_lowering.stop = Compilation::Stop;
494496
}

0 commit comments

Comments
 (0)