@@ -13,6 +13,7 @@ extern crate rustc_hir;
13
13
extern crate rustc_interface;
14
14
extern crate rustc_session;
15
15
extern crate rustc_span;
16
+ extern crate rustc_driver;
16
17
17
18
use std:: { path, process, str} ;
18
19
@@ -45,7 +46,6 @@ fn main() {
45
46
} ,
46
47
crate_cfg : rustc_hash:: FxHashSet :: default ( ) ,
47
48
crate_check_cfg : CheckCfg :: default ( ) ,
48
- input_path : None ,
49
49
output_dir : None ,
50
50
output_file : None ,
51
51
file_loader : None ,
@@ -59,13 +59,12 @@ fn main() {
59
59
rustc_interface:: run_compiler ( config, |compiler| {
60
60
compiler. enter ( |queries| {
61
61
// TODO: add this to -Z unpretty
62
- let ast_krate = queries. parse ( ) . unwrap ( ) . take ( ) ;
62
+ let ast_krate = queries. parse ( ) . unwrap ( ) . get_mut ( ) . clone ( ) ;
63
63
for item in ast_krate. items {
64
64
println ! ( "{}" , item_to_string( & item) ) ;
65
65
}
66
-
67
66
// 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| {
69
68
// Every compilation contains a single crate.
70
69
let hir_krate = tcx. hir ( ) ;
71
70
// Iterate over the top-level items in the crate, looking for the main function.
@@ -78,7 +77,7 @@ fn main() {
78
77
if let rustc_hir:: StmtKind :: Local ( local) = block. stmts [ 0 ] . kind {
79
78
if let Some ( expr) = local. init {
80
79
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
82
81
let ty = tcx. typeck ( def_id) . node_type ( hir_id) ;
83
82
println ! ( "{expr:#?}: {ty:?}" ) ;
84
83
}
0 commit comments