19
19
use build;
20
20
use rustc:: dep_graph:: DepNode ;
21
21
use rustc:: mir:: repr:: Mir ;
22
+ use rustc:: mir:: transform:: MirSource ;
22
23
use pretty;
23
24
use hair:: cx:: Cx ;
24
25
@@ -55,20 +56,20 @@ struct BuildMir<'a, 'tcx: 'a> {
55
56
}
56
57
57
58
impl < ' a , ' tcx > BuildMir < ' a , ' tcx > {
58
- fn build < F > ( & mut self , id : ast :: NodeId , f : F )
59
+ fn build < F > ( & mut self , src : MirSource , f : F )
59
60
where F : for < ' b > FnOnce ( Cx < ' b , ' tcx > ) -> ( Mir < ' tcx > , build:: ScopeAuxiliaryVec )
60
61
{
61
- let param_env = ty:: ParameterEnvironment :: for_item ( self . tcx , id ) ;
62
+ let param_env = ty:: ParameterEnvironment :: for_item ( self . tcx , src . item_id ( ) ) ;
62
63
let infcx = infer:: new_infer_ctxt ( self . tcx ,
63
64
& self . tcx . tables ,
64
65
Some ( param_env) ,
65
66
ProjectionMode :: AnyFinal ) ;
66
67
67
68
let ( mir, scope_auxiliary) = f ( Cx :: new ( & infcx) ) ;
68
69
69
- pretty:: dump_mir ( self . tcx , "mir_map" , & 0 , id , & mir, Some ( & scope_auxiliary) ) ;
70
+ pretty:: dump_mir ( self . tcx , "mir_map" , & 0 , src , & mir, Some ( & scope_auxiliary) ) ;
70
71
71
- assert ! ( self . map. map. insert( id , mir) . is_none( ) )
72
+ assert ! ( self . map. map. insert( src . item_id ( ) , mir) . is_none( ) )
72
73
}
73
74
74
75
fn build_const_integer ( & mut self , expr : & ' tcx hir:: Expr ) {
@@ -79,17 +80,25 @@ impl<'a, 'tcx> BuildMir<'a, 'tcx> {
79
80
if let hir:: ExprClosure ( ..) = expr. node {
80
81
return ;
81
82
}
82
- self . build ( expr. id , |cx| build:: construct_const ( cx, expr. id , expr) ) ;
83
+ self . build ( MirSource :: Const ( expr. id ) , |cx| {
84
+ build:: construct_const ( cx, expr. id , expr)
85
+ } ) ;
83
86
}
84
87
}
85
88
86
89
impl < ' a , ' tcx > Visitor < ' tcx > for BuildMir < ' a , ' tcx > {
87
90
// Const and static items.
88
91
fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
89
92
match item. node {
90
- hir:: ItemConst ( _, ref expr) |
91
- hir:: ItemStatic ( _, _, ref expr) => {
92
- self . build ( item. id , |cx| build:: construct_const ( cx, item. id , expr) ) ;
93
+ hir:: ItemConst ( _, ref expr) => {
94
+ self . build ( MirSource :: Const ( item. id ) , |cx| {
95
+ build:: construct_const ( cx, item. id , expr)
96
+ } ) ;
97
+ }
98
+ hir:: ItemStatic ( _, m, ref expr) => {
99
+ self . build ( MirSource :: Static ( item. id , m) , |cx| {
100
+ build:: construct_const ( cx, item. id , expr)
101
+ } ) ;
93
102
}
94
103
_ => { }
95
104
}
@@ -99,15 +108,19 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
99
108
// Trait associated const defaults.
100
109
fn visit_trait_item ( & mut self , item : & ' tcx hir:: TraitItem ) {
101
110
if let hir:: ConstTraitItem ( _, Some ( ref expr) ) = item. node {
102
- self . build ( item. id , |cx| build:: construct_const ( cx, item. id , expr) ) ;
111
+ self . build ( MirSource :: Const ( item. id ) , |cx| {
112
+ build:: construct_const ( cx, item. id , expr)
113
+ } ) ;
103
114
}
104
115
intravisit:: walk_trait_item ( self , item) ;
105
116
}
106
117
107
118
// Impl associated const.
108
119
fn visit_impl_item ( & mut self , item : & ' tcx hir:: ImplItem ) {
109
120
if let hir:: ImplItemKind :: Const ( _, ref expr) = item. node {
110
- self . build ( item. id , |cx| build:: construct_const ( cx, item. id , expr) ) ;
121
+ self . build ( MirSource :: Const ( item. id ) , |cx| {
122
+ build:: construct_const ( cx, item. id , expr)
123
+ } ) ;
111
124
}
112
125
intravisit:: walk_impl_item ( self , item) ;
113
126
}
@@ -166,7 +179,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
166
179
( fn_sig. inputs [ index] , Some ( & * arg. pat ) )
167
180
} ) ;
168
181
169
- self . build ( id , |cx| {
182
+ self . build ( MirSource :: Fn ( id ) , |cx| {
170
183
let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
171
184
build:: construct_fn ( cx, id, arguments, fn_sig. output , body)
172
185
} ) ;
0 commit comments