1919use build;
2020use rustc:: dep_graph:: DepNode ;
2121use rustc:: mir:: repr:: Mir ;
22+ use rustc:: mir:: transform:: MirSource ;
2223use pretty;
2324use hair:: cx:: Cx ;
2425
@@ -55,20 +56,20 @@ struct BuildMir<'a, 'tcx: 'a> {
5556}
5657
5758impl < ' 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 )
5960 where F : for < ' b > FnOnce ( Cx < ' b , ' tcx > ) -> ( Mir < ' tcx > , build:: ScopeAuxiliaryVec )
6061 {
61- let param_env = ty:: ParameterEnvironment :: for_item ( self . tcx , id ) ;
62+ let param_env = ty:: ParameterEnvironment :: for_item ( self . tcx , src . item_id ( ) ) ;
6263 let infcx = infer:: new_infer_ctxt ( self . tcx ,
6364 & self . tcx . tables ,
6465 Some ( param_env) ,
6566 ProjectionMode :: AnyFinal ) ;
6667
6768 let ( mir, scope_auxiliary) = f ( Cx :: new ( & infcx) ) ;
6869
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) ) ;
7071
71- assert ! ( self . map. map. insert( id , mir) . is_none( ) )
72+ assert ! ( self . map. map. insert( src . item_id ( ) , mir) . is_none( ) )
7273 }
7374
7475 fn build_const_integer ( & mut self , expr : & ' tcx hir:: Expr ) {
@@ -79,17 +80,25 @@ impl<'a, 'tcx> BuildMir<'a, 'tcx> {
7980 if let hir:: ExprClosure ( ..) = expr. node {
8081 return ;
8182 }
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+ } ) ;
8386 }
8487}
8588
8689impl < ' a , ' tcx > Visitor < ' tcx > for BuildMir < ' a , ' tcx > {
8790 // Const and static items.
8891 fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
8992 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+ } ) ;
93102 }
94103 _ => { }
95104 }
@@ -99,15 +108,19 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
99108 // Trait associated const defaults.
100109 fn visit_trait_item ( & mut self , item : & ' tcx hir:: TraitItem ) {
101110 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+ } ) ;
103114 }
104115 intravisit:: walk_trait_item ( self , item) ;
105116 }
106117
107118 // Impl associated const.
108119 fn visit_impl_item ( & mut self , item : & ' tcx hir:: ImplItem ) {
109120 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+ } ) ;
111124 }
112125 intravisit:: walk_impl_item ( self , item) ;
113126 }
@@ -166,7 +179,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
166179 ( fn_sig. inputs [ index] , Some ( & * arg. pat ) )
167180 } ) ;
168181
169- self . build ( id , |cx| {
182+ self . build ( MirSource :: Fn ( id ) , |cx| {
170183 let arguments = implicit_argument. into_iter ( ) . chain ( explicit_arguments) ;
171184 build:: construct_fn ( cx, id, arguments, fn_sig. output , body)
172185 } ) ;
0 commit comments