1
1
#![ feature( rustc_private) ]
2
2
3
3
// NOTE: For the example to compile, you will need to first run the following:
4
- // rustup component add rustc-dev
4
+ // rustup component add rustc-dev llvm-tools-preview
5
5
6
+ extern crate rustc_ast_pretty;
6
7
extern crate rustc_error_codes;
7
8
extern crate rustc_errors;
8
9
extern crate rustc_hash;
@@ -11,8 +12,11 @@ extern crate rustc_interface;
11
12
extern crate rustc_session;
12
13
extern crate rustc_span;
13
14
15
+ use rustc_ast_pretty:: pprust:: item_to_string;
14
16
use rustc_errors:: registry;
15
17
use rustc_session:: config;
18
+ use rustc_session:: config:: PpMode :: PpmSource ;
19
+ use rustc_session:: config:: PpSourceMode :: PpmExpanded ;
16
20
use rustc_span:: source_map;
17
21
use std:: path;
18
22
use std:: process;
@@ -46,16 +50,24 @@ fn main() {
46
50
lint_caps : rustc_hash:: FxHashMap :: default ( ) ,
47
51
register_lints : None ,
48
52
override_queries : None ,
53
+ make_codegen_backend : None ,
49
54
registry : registry:: Registry :: new ( & rustc_error_codes:: DIAGNOSTICS ) ,
50
55
} ;
51
56
rustc_interface:: run_compiler ( config, |compiler| {
52
57
compiler. enter ( |queries| {
58
+ // TODO: add this to -Z unpretty
59
+ let ast_krate = queries. parse ( ) . unwrap ( ) . take ( ) ;
60
+ let ast_krate_mod = ast_krate. module ;
61
+ for item in ast_krate_mod. items {
62
+ println ! ( "{}" , item_to_string( & item) ) ;
63
+ }
64
+
53
65
// Analyze the crate and inspect the types under the cursor.
54
66
queries. global_ctxt ( ) . unwrap ( ) . take ( ) . enter ( |tcx| {
55
67
// Every compilation contains a single crate.
56
- let krate = tcx. hir ( ) . krate ( ) ;
68
+ let hir_krate = tcx. hir ( ) . krate ( ) ;
57
69
// Iterate over the top-level items in the crate, looking for the main function.
58
- for ( _, item) in & krate . items {
70
+ for ( _, item) in & hir_krate . items {
59
71
// Use pattern-matching to find a specific node inside the main function.
60
72
if let rustc_hir:: ItemKind :: Fn ( _, _, body_id) = item. kind {
61
73
let expr = & tcx. hir ( ) . body ( body_id) . value ;
0 commit comments