@@ -17,7 +17,7 @@ use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind
1717use rustc_middle:: mir:: { Field , ProjectionElem , Promoted , Rvalue , Statement , StatementKind } ;
1818use rustc_middle:: mir:: { InlineAsmOperand , Terminator , TerminatorKind } ;
1919use rustc_middle:: ty:: query:: Providers ;
20- use rustc_middle:: ty:: { self , RegionVid , TyCtxt } ;
20+ use rustc_middle:: ty:: { self , InstanceDef , RegionVid , TyCtxt } ;
2121use rustc_session:: lint:: builtin:: { MUTABLE_BORROW_RESERVATION_CONFLICT , UNUSED_MUT } ;
2222use rustc_span:: { Span , Symbol , DUMMY_SP } ;
2323
@@ -87,17 +87,32 @@ crate struct Upvar {
8787const DEREF_PROJECTION : & [ PlaceElem < ' _ > ; 1 ] = & [ ProjectionElem :: Deref ] ;
8888
8989pub fn provide ( providers : & mut Providers ) {
90- * providers = Providers { mir_borrowck, ..* providers } ;
90+ * providers = Providers {
91+ mir_borrowck : |tcx, did| mir_borrowck ( tcx, ty:: WithOptParam :: dummy ( did) ) ,
92+ mir_borrowck_const_arg : |tcx, def| {
93+ if def. param_did . is_none ( ) { tcx. mir_borrowck ( def. did ) } else { mir_borrowck ( tcx, def) }
94+ } ,
95+ ..* providers
96+ } ;
9197}
9298
93- fn mir_borrowck < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> & ' tcx BorrowCheckResult < ' tcx > {
94- let ( input_body, promoted) = tcx. mir_validated ( def_id) ;
95- debug ! ( "run query mir_borrowck: {}" , tcx. def_path_str( def_id. to_def_id( ) ) ) ;
99+ fn mir_borrowck < ' tcx > (
100+ tcx : TyCtxt < ' tcx > ,
101+ def : ty:: WithOptParam < LocalDefId > ,
102+ ) -> & ' tcx BorrowCheckResult < ' tcx > {
103+ if def. param_did . is_none ( ) {
104+ if let param_did @ Some ( _) = tcx. opt_const_param_of ( def. did ) {
105+ return tcx. mir_borrowck_const_arg ( ty:: WithOptParam { param_did, ..def } ) ;
106+ }
107+ }
108+
109+ let ( input_body, promoted) = tcx. mir_validated ( def) ;
110+ debug ! ( "run query mir_borrowck: {}" , tcx. def_path_str( def. did. to_def_id( ) ) ) ;
96111
97112 let opt_closure_req = tcx. infer_ctxt ( ) . enter ( |infcx| {
98113 let input_body: & Body < ' _ > = & input_body. borrow ( ) ;
99114 let promoted: & IndexVec < _ , _ > = & promoted. borrow ( ) ;
100- do_mir_borrowck ( & infcx, input_body, promoted, def_id )
115+ do_mir_borrowck ( & infcx, input_body, promoted, def )
101116 } ) ;
102117 debug ! ( "mir_borrowck done" ) ;
103118
@@ -108,13 +123,13 @@ fn do_mir_borrowck<'a, 'tcx>(
108123 infcx : & InferCtxt < ' a , ' tcx > ,
109124 input_body : & Body < ' tcx > ,
110125 input_promoted : & IndexVec < Promoted , Body < ' tcx > > ,
111- def_id : LocalDefId ,
126+ def : ty :: WithOptParam < LocalDefId > ,
112127) -> BorrowCheckResult < ' tcx > {
113- debug ! ( "do_mir_borrowck(def_id = {:?})" , def_id ) ;
128+ debug ! ( "do_mir_borrowck(def = {:?})" , def ) ;
114129
115130 let tcx = infcx. tcx ;
116- let param_env = tcx. param_env ( def_id ) ;
117- let id = tcx. hir ( ) . as_local_hir_id ( def_id ) ;
131+ let param_env = tcx. param_env ( def . did ) ;
132+ let id = tcx. hir ( ) . as_local_hir_id ( def . did ) ;
118133
119134 let mut local_names = IndexVec :: from_elem ( None , & input_body. local_decls ) ;
120135 for var_debug_info in & input_body. var_debug_info {
@@ -135,13 +150,13 @@ fn do_mir_borrowck<'a, 'tcx>(
135150 }
136151
137152 // Gather the upvars of a closure, if any.
138- let tables = tcx. typeck_tables_of ( def_id ) ;
153+ let tables = tcx. typeck_tables_of_const_arg ( def ) ;
139154 if let Some ( ErrorReported ) = tables. tainted_by_errors {
140155 infcx. set_tainted_by_errors ( ) ;
141156 }
142157 let upvars: Vec < _ > = tables
143158 . closure_captures
144- . get ( & def_id . to_def_id ( ) )
159+ . get ( & def . did . to_def_id ( ) )
145160 . into_iter ( )
146161 . flat_map ( |v| v. values ( ) )
147162 . map ( |upvar_id| {
@@ -171,8 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>(
171186 // will have a lifetime tied to the inference context.
172187 let mut body = input_body. clone ( ) ;
173188 let mut promoted = input_promoted. clone ( ) ;
174- let free_regions =
175- nll:: replace_regions_in_mir ( infcx, def_id, param_env, & mut body, & mut promoted) ;
189+ let free_regions = nll:: replace_regions_in_mir ( infcx, def, param_env, & mut body, & mut promoted) ;
176190 let body = & body; // no further changes
177191
178192 let location_table = & LocationTable :: new ( & body) ;
@@ -190,7 +204,7 @@ fn do_mir_borrowck<'a, 'tcx>(
190204 let mdpe = MoveDataParamEnv { move_data, param_env } ;
191205
192206 let mut flow_inits = MaybeInitializedPlaces :: new ( tcx, & body, & mdpe)
193- . into_engine ( tcx, & body, def_id . to_def_id ( ) )
207+ . into_engine ( tcx, & body, def . did . to_def_id ( ) )
194208 . iterate_to_fixpoint ( )
195209 . into_results_cursor ( & body) ;
196210
@@ -207,7 +221,7 @@ fn do_mir_borrowck<'a, 'tcx>(
207221 nll_errors,
208222 } = nll:: compute_regions (
209223 infcx,
210- def_id ,
224+ def . did ,
211225 free_regions,
212226 body,
213227 & promoted,
@@ -223,7 +237,7 @@ fn do_mir_borrowck<'a, 'tcx>(
223237 // write unit-tests, as well as helping with debugging.
224238 nll:: dump_mir_results (
225239 infcx,
226- MirSource :: item ( def_id . to_def_id ( ) ) ,
240+ MirSource { instance : InstanceDef :: Item ( def . to_global ( ) ) , promoted : None } ,
227241 & body,
228242 & regioncx,
229243 & opt_closure_req,
@@ -234,7 +248,7 @@ fn do_mir_borrowck<'a, 'tcx>(
234248 nll:: dump_annotation (
235249 infcx,
236250 & body,
237- def_id . to_def_id ( ) ,
251+ def . did . to_def_id ( ) ,
238252 & regioncx,
239253 & opt_closure_req,
240254 & opaque_type_values,
@@ -249,13 +263,13 @@ fn do_mir_borrowck<'a, 'tcx>(
249263 let regioncx = Rc :: new ( regioncx) ;
250264
251265 let flow_borrows = Borrows :: new ( tcx, & body, regioncx. clone ( ) , & borrow_set)
252- . into_engine ( tcx, & body, def_id . to_def_id ( ) )
266+ . into_engine ( tcx, & body, def . did . to_def_id ( ) )
253267 . iterate_to_fixpoint ( ) ;
254268 let flow_uninits = MaybeUninitializedPlaces :: new ( tcx, & body, & mdpe)
255- . into_engine ( tcx, & body, def_id . to_def_id ( ) )
269+ . into_engine ( tcx, & body, def . did . to_def_id ( ) )
256270 . iterate_to_fixpoint ( ) ;
257271 let flow_ever_inits = EverInitializedPlaces :: new ( tcx, & body, & mdpe)
258- . into_engine ( tcx, & body, def_id . to_def_id ( ) )
272+ . into_engine ( tcx, & body, def . did . to_def_id ( ) )
259273 . iterate_to_fixpoint ( ) ;
260274
261275 let movable_generator = match tcx. hir ( ) . get ( id) {
@@ -274,7 +288,7 @@ fn do_mir_borrowck<'a, 'tcx>(
274288 let mut promoted_mbcx = MirBorrowckCtxt {
275289 infcx,
276290 body : promoted_body,
277- mir_def_id : def_id ,
291+ mir_def_id : def . did ,
278292 move_data : & move_data,
279293 location_table : & LocationTable :: new ( promoted_body) ,
280294 movable_generator,
@@ -307,7 +321,7 @@ fn do_mir_borrowck<'a, 'tcx>(
307321 let mut mbcx = MirBorrowckCtxt {
308322 infcx,
309323 body,
310- mir_def_id : def_id ,
324+ mir_def_id : def . did ,
311325 move_data : & mdpe. move_data ,
312326 location_table,
313327 movable_generator,
0 commit comments