@@ -13,6 +13,7 @@ extern crate rustc_hir;
1313extern crate rustc_interface;
1414extern crate rustc_session;
1515extern crate rustc_span;
16+ extern crate rustc_driver;
1617
1718use std:: { path, process, str} ;
1819
@@ -45,7 +46,6 @@ fn main() {
4546 } ,
4647 crate_cfg : rustc_hash:: FxHashSet :: default ( ) ,
4748 crate_check_cfg : CheckCfg :: default ( ) ,
48- input_path : None ,
4949 output_dir : None ,
5050 output_file : None ,
5151 file_loader : None ,
@@ -59,13 +59,12 @@ fn main() {
5959 rustc_interface:: run_compiler ( config, |compiler| {
6060 compiler. enter ( |queries| {
6161 // TODO: add this to -Z unpretty
62- let ast_krate = queries. parse ( ) . unwrap ( ) . take ( ) ;
62+ let ast_krate = queries. parse ( ) . unwrap ( ) . get_mut ( ) . clone ( ) ;
6363 for item in ast_krate. items {
6464 println ! ( "{}" , item_to_string( & item) ) ;
6565 }
66-
6766 // Analyze the crate and inspect the types under the cursor.
68- queries. global_ctxt ( ) . unwrap ( ) . take ( ) . enter ( |tcx| {
67+ queries. global_ctxt ( ) . unwrap ( ) . enter ( |tcx| {
6968 // Every compilation contains a single crate.
7069 let hir_krate = tcx. hir ( ) ;
7170 // Iterate over the top-level items in the crate, looking for the main function.
@@ -78,7 +77,7 @@ fn main() {
7877 if let rustc_hir:: StmtKind :: Local ( local) = block. stmts [ 0 ] . kind {
7978 if let Some ( expr) = local. init {
8079 let hir_id = expr. hir_id ; // hir_id identifies the string "Hello, world!"
81- let def_id = tcx . hir ( ) . local_def_id ( item. hir_id ( ) ) ; // def_id identifies the main function
80+ let def_id = item. hir_id ( ) . owner . def_id ; // def_id identifies the main function
8281 let ty = tcx. typeck ( def_id) . node_type ( hir_id) ;
8382 println ! ( "{expr:#?}: {ty:?}" ) ;
8483 }
0 commit comments