1
1
#![ feature( rustc_private) ]
2
2
3
- // NOTE: For the example to compile, you will need to first run the following:
4
- // rustup component add rustc-dev llvm-tools-preview
5
-
6
- // version: 1.62.0-nightly (7c4b47696 2022-04-30)
7
-
8
3
extern crate rustc_ast_pretty;
4
+ extern crate rustc_driver;
9
5
extern crate rustc_error_codes;
10
6
extern crate rustc_errors;
11
7
extern crate rustc_hash;
@@ -43,30 +39,30 @@ fn main() {
43
39
"#
44
40
. to_string ( ) ,
45
41
} ,
46
- diagnostic_output : rustc_session:: DiagnosticOutput :: Default ,
47
42
crate_cfg : rustc_hash:: FxHashSet :: default ( ) ,
48
43
crate_check_cfg : CheckCfg :: default ( ) ,
49
- input_path : None ,
50
44
output_dir : None ,
51
45
output_file : None ,
52
46
file_loader : None ,
47
+ locale_resources : rustc_driver:: DEFAULT_LOCALE_RESOURCES ,
53
48
lint_caps : rustc_hash:: FxHashMap :: default ( ) ,
54
49
parse_sess_created : None ,
55
50
register_lints : None ,
56
51
override_queries : None ,
57
52
make_codegen_backend : None ,
58
53
registry : registry:: Registry :: new ( & rustc_error_codes:: DIAGNOSTICS ) ,
54
+ expanded_args : Vec :: new ( ) ,
55
+ ice_file : None ,
59
56
} ;
60
57
rustc_interface:: run_compiler ( config, |compiler| {
61
58
compiler. enter ( |queries| {
62
59
// TODO: add this to -Z unpretty
63
- let ast_krate = queries. parse ( ) . unwrap ( ) . take ( ) ;
60
+ let ast_krate = queries. parse ( ) . unwrap ( ) . get_mut ( ) . clone ( ) ;
64
61
for item in ast_krate. items {
65
62
println ! ( "{}" , item_to_string( & item) ) ;
66
63
}
67
-
68
64
// Analyze the crate and inspect the types under the cursor.
69
- queries. global_ctxt ( ) . unwrap ( ) . take ( ) . enter ( |tcx| {
65
+ queries. global_ctxt ( ) . unwrap ( ) . enter ( |tcx| {
70
66
// Every compilation contains a single crate.
71
67
let hir_krate = tcx. hir ( ) ;
72
68
// Iterate over the top-level items in the crate, looking for the main function.
@@ -79,7 +75,7 @@ fn main() {
79
75
if let rustc_hir:: StmtKind :: Local ( local) = block. stmts [ 0 ] . kind {
80
76
if let Some ( expr) = local. init {
81
77
let hir_id = expr. hir_id ; // hir_id identifies the string "Hello, world!"
82
- let def_id = tcx . hir ( ) . local_def_id ( item. hir_id ( ) ) ; // def_id identifies the main function
78
+ let def_id = item. hir_id ( ) . owner . def_id ; // def_id identifies the main function
83
79
let ty = tcx. typeck ( def_id) . node_type ( hir_id) ;
84
80
println ! ( "{expr:#?}: {ty:?}" ) ;
85
81
}
0 commit comments