@@ -13,13 +13,12 @@ extern crate rustc_interface;
13
13
extern crate rustc_session;
14
14
extern crate rustc_span;
15
15
16
+ use std:: { path, process, str} ;
17
+
16
18
use rustc_errors:: registry;
17
19
use rustc_hash:: { FxHashMap , FxHashSet } ;
18
20
use rustc_session:: config:: { self , CheckCfg } ;
19
21
use rustc_span:: source_map;
20
- use std:: path;
21
- use std:: process;
22
- use std:: str;
23
22
24
23
fn main ( ) {
25
24
let out = process:: Command :: new ( "rustc" )
@@ -38,9 +37,14 @@ fn main() {
38
37
crate_cfg : FxHashSet :: default ( ) , // FxHashSet<(String, Option<String>)>
39
38
crate_check_cfg : CheckCfg :: default ( ) , // CheckCfg
40
39
input : config:: Input :: Str {
41
- name : source_map:: FileName :: Custom ( "main.rs" . to_string ( ) ) ,
42
- input : "static HELLO: &str = \" Hello, world!\" ; fn main() { println!(\" {}\" , HELLO); }"
43
- . to_string ( ) ,
40
+ name : source_map:: FileName :: Custom ( "main.rs" . into ( ) ) ,
41
+ input : r#"
42
+ static HELLO: &str = "Hello, world!";
43
+ fn main() {
44
+ println!("{HELLO}");
45
+ }
46
+ "#
47
+ . into ( ) ,
44
48
} ,
45
49
input_path : None , // Option<PathBuf>
46
50
output_dir : None , // Option<PathBuf>
@@ -69,16 +73,17 @@ fn main() {
69
73
compiler. enter ( |queries| {
70
74
// Parse the program and print the syntax tree.
71
75
let parse = queries. parse ( ) . unwrap ( ) . take ( ) ;
72
- println ! ( "{:# ?}" , parse ) ;
76
+ println ! ( "{parse: ?}" ) ;
73
77
// Analyze the program and inspect the types of definitions.
74
78
queries. global_ctxt ( ) . unwrap ( ) . take ( ) . enter ( |tcx| {
75
79
for id in tcx. hir ( ) . items ( ) {
76
- let item = tcx. hir ( ) . item ( id) ;
80
+ let hir = tcx. hir ( ) ;
81
+ let item = hir. item ( id) ;
77
82
match item. kind {
78
83
rustc_hir:: ItemKind :: Static ( _, _, _) | rustc_hir:: ItemKind :: Fn ( _, _, _) => {
79
84
let name = item. ident ;
80
- let ty = tcx. type_of ( tcx . hir ( ) . local_def_id ( item. hir_id ( ) ) ) ;
81
- println ! ( "{:?}:\t {:?}" , name , ty )
85
+ let ty = tcx. type_of ( hir. local_def_id ( item. hir_id ( ) ) ) ;
86
+ println ! ( "{name :?}:\t {ty :?}" )
82
87
}
83
88
_ => ( ) ,
84
89
}
0 commit comments