@@ -35,7 +35,7 @@ use rustc_infer::infer::{
35
35
} ;
36
36
use rustc_middle:: mir:: * ;
37
37
use rustc_middle:: query:: Providers ;
38
- use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt , TypingMode , fold_regions } ;
38
+ use rustc_middle:: ty:: { self , ParamEnv , RegionVid , TyCtxt , TypingMode } ;
39
39
use rustc_middle:: { bug, span_bug} ;
40
40
use rustc_mir_dataflow:: impls:: {
41
41
EverInitializedPlaces , MaybeInitializedPlaces , MaybeUninitializedPlaces ,
@@ -73,6 +73,7 @@ mod def_use;
73
73
mod diagnostics;
74
74
mod member_constraints;
75
75
mod nll;
76
+ mod opaque_types;
76
77
mod path_utils;
77
78
mod place_ext;
78
79
mod places_conflict;
@@ -102,11 +103,8 @@ pub fn provide(providers: &mut Providers) {
102
103
}
103
104
104
105
fn mir_borrowck ( tcx : TyCtxt < ' _ > , def : LocalDefId ) -> & BorrowCheckResult < ' _ > {
105
- let ( input_body, promoted) = tcx. mir_promoted ( def) ;
106
- debug ! ( "run query mir_borrowck: {}" , tcx. def_path_str( def) ) ;
107
-
106
+ let ( input_body, _0) = tcx. mir_promoted ( def) ;
108
107
let input_body: & Body < ' _ > = & input_body. borrow ( ) ;
109
-
110
108
if input_body. should_skip ( ) || input_body. tainted_by_errors . is_some ( ) {
111
109
debug ! ( "Skipping borrowck because of injected body or tainted body" ) ;
112
110
// Let's make up a borrowck result! Fun times!
@@ -119,7 +117,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
119
117
return tcx. arena . alloc ( result) ;
120
118
}
121
119
122
- let borrowck_result = do_mir_borrowck ( tcx, input_body , & * promoted . borrow ( ) , None ) . 0 ;
120
+ let borrowck_result = do_mir_borrowck ( tcx, def , None ) . 0 ;
123
121
debug ! ( "mir_borrowck done" ) ;
124
122
125
123
tcx. arena . alloc ( borrowck_result)
@@ -130,15 +128,16 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
130
128
/// Use `consumer_options: None` for the default behavior of returning
131
129
/// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
132
130
/// to the given [`ConsumerOptions`].
133
- #[ instrument( skip( tcx, input_body , input_promoted ) , fields ( id=?input_body . source . def_id ( ) ) , level = "debug" ) ]
131
+ #[ instrument( skip( tcx) , level = "debug" ) ]
134
132
fn do_mir_borrowck < ' tcx > (
135
133
tcx : TyCtxt < ' tcx > ,
136
- input_body : & Body < ' tcx > ,
137
- input_promoted : & IndexSlice < Promoted , Body < ' tcx > > ,
134
+ def : LocalDefId ,
138
135
consumer_options : Option < ConsumerOptions > ,
139
136
) -> ( BorrowCheckResult < ' tcx > , Option < Box < BodyWithBorrowckFacts < ' tcx > > > ) {
140
- let def = input_body. source . def_id ( ) . expect_local ( ) ;
141
137
let infcx = BorrowckInferCtxt :: new ( tcx, def) ;
138
+ let ( input_body, promoted) = tcx. mir_promoted ( def) ;
139
+ let input_body: & Body < ' _ > = & input_body. borrow ( ) ;
140
+ let input_promoted: & IndexSlice < _ , _ > = & promoted. borrow ( ) ;
142
141
if let Some ( e) = input_body. tainted_by_errors {
143
142
infcx. set_tainted_by_errors ( e) ;
144
143
}
@@ -172,12 +171,6 @@ fn do_mir_borrowck<'tcx>(
172
171
let free_regions = nll:: replace_regions_in_mir ( & infcx, & mut body_owned, & mut promoted) ;
173
172
let body = & body_owned; // no further changes
174
173
175
- // FIXME(-Znext-solver): A bit dubious that we're only registering
176
- // predefined opaques in the typeck root.
177
- if infcx. next_trait_solver ( ) && !infcx. tcx . is_typeck_child ( body. source . def_id ( ) ) {
178
- infcx. register_predefined_opaques_for_next_solver ( def) ;
179
- }
180
-
181
174
let location_table = PoloniusLocationTable :: new ( body) ;
182
175
183
176
let move_data = MoveData :: gather_moves ( body, tcx, |_| true ) ;
@@ -192,7 +185,7 @@ fn do_mir_borrowck<'tcx>(
192
185
// Compute non-lexical lifetimes.
193
186
let nll:: NllOutput {
194
187
regioncx,
195
- opaque_type_values ,
188
+ concrete_opaque_types ,
196
189
polonius_input,
197
190
polonius_output,
198
191
opt_closure_req,
@@ -222,7 +215,7 @@ fn do_mir_borrowck<'tcx>(
222
215
body,
223
216
& regioncx,
224
217
& opt_closure_req,
225
- & opaque_type_values ,
218
+ & concrete_opaque_types ,
226
219
diags_buffer,
227
220
) ;
228
221
@@ -357,7 +350,7 @@ fn do_mir_borrowck<'tcx>(
357
350
let tainted_by_errors = mbcx. emit_errors ( ) ;
358
351
359
352
let result = BorrowCheckResult {
360
- concrete_opaque_types : opaque_type_values ,
353
+ concrete_opaque_types : concrete_opaque_types . into_inner ( ) ,
361
354
closure_requirements : opt_closure_req,
362
355
used_mut_upvars : mbcx. used_mut_upvars ,
363
356
tainted_by_errors,
@@ -432,7 +425,7 @@ pub(crate) struct BorrowckInferCtxt<'tcx> {
432
425
433
426
impl < ' tcx > BorrowckInferCtxt < ' tcx > {
434
427
pub ( crate ) fn new ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> Self {
435
- let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: analysis_in_body ( tcx, def_id) ) ;
428
+ let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: borrowck ( tcx, def_id) ) ;
436
429
let param_env = tcx. param_env ( def_id) ;
437
430
BorrowckInferCtxt { infcx, reg_var_to_origin : RefCell :: new ( Default :: default ( ) ) , param_env }
438
431
}
@@ -479,28 +472,6 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
479
472
480
473
next_region
481
474
}
482
-
483
- /// With the new solver we prepopulate the opaque type storage during
484
- /// MIR borrowck with the hidden types from HIR typeck. This is necessary
485
- /// to avoid ambiguities as earlier goals can rely on the hidden type
486
- /// of an opaque which is only constrained by a later goal.
487
- fn register_predefined_opaques_for_next_solver ( & self , def_id : LocalDefId ) {
488
- let tcx = self . tcx ;
489
- // OK to use the identity arguments for each opaque type key, since
490
- // we remap opaques from HIR typeck back to their definition params.
491
- for data in tcx. typeck ( def_id) . concrete_opaque_types . iter ( ) . map ( |( k, v) | ( * k, * v) ) {
492
- // HIR typeck did not infer the regions of the opaque, so we instantiate
493
- // them with fresh inference variables.
494
- let ( key, hidden_ty) = fold_regions ( tcx, data, |_, _| {
495
- self . next_nll_region_var_in_universe (
496
- NllRegionVariableOrigin :: Existential { from_forall : false } ,
497
- ty:: UniverseIndex :: ROOT ,
498
- )
499
- } ) ;
500
-
501
- self . inject_new_hidden_type_unchecked ( key, hidden_ty) ;
502
- }
503
- }
504
475
}
505
476
506
477
impl < ' tcx > Deref for BorrowckInferCtxt < ' tcx > {
0 commit comments