@@ -13,13 +13,12 @@ extern crate rustc_interface;
1313extern crate rustc_session;
1414extern crate rustc_span;
1515
16+ use std:: { path, process, str} ;
17+
1618use rustc_errors:: registry;
1719use rustc_hash:: { FxHashMap , FxHashSet } ;
1820use rustc_session:: config:: { self , CheckCfg } ;
1921use rustc_span:: source_map;
20- use std:: path;
21- use std:: process;
22- use std:: str;
2322
2423fn main ( ) {
2524 let out = process:: Command :: new ( "rustc" )
@@ -38,9 +37,14 @@ fn main() {
3837 crate_cfg : FxHashSet :: default ( ) , // FxHashSet<(String, Option<String>)>
3938 crate_check_cfg : CheckCfg :: default ( ) , // CheckCfg
4039 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 ( ) ,
4448 } ,
4549 input_path : None , // Option<PathBuf>
4650 output_dir : None , // Option<PathBuf>
@@ -69,16 +73,17 @@ fn main() {
6973 compiler. enter ( |queries| {
7074 // Parse the program and print the syntax tree.
7175 let parse = queries. parse ( ) . unwrap ( ) . take ( ) ;
72- println ! ( "{:# ?}" , parse ) ;
76+ println ! ( "{parse: ?}" ) ;
7377 // Analyze the program and inspect the types of definitions.
7478 queries. global_ctxt ( ) . unwrap ( ) . take ( ) . enter ( |tcx| {
7579 for id in tcx. hir ( ) . items ( ) {
76- let item = tcx. hir ( ) . item ( id) ;
80+ let hir = tcx. hir ( ) ;
81+ let item = hir. item ( id) ;
7782 match item. kind {
7883 rustc_hir:: ItemKind :: Static ( _, _, _) | rustc_hir:: ItemKind :: Fn ( _, _, _) => {
7984 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 :?}" )
8287 }
8388 _ => ( ) ,
8489 }
0 commit comments