2
2
3
3
use std:: collections:: VecDeque ;
4
4
5
+ use rustc:: infer:: NLLRegionVariableOrigin ;
5
6
use rustc:: mir:: {
6
7
Body , CastKind , ConstraintCategory , FakeReadCause , Local , Location , Operand , Place , Rvalue ,
7
8
Statement , StatementKind , TerminatorKind ,
8
9
} ;
9
10
use rustc:: ty:: adjustment:: PointerCast ;
10
- use rustc:: ty:: { self , TyCtxt } ;
11
+ use rustc:: ty:: { self , RegionVid , TyCtxt } ;
11
12
use rustc_data_structures:: fx:: FxHashSet ;
12
13
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
13
14
use rustc_index:: vec:: IndexVec ;
14
15
use rustc_span:: symbol:: Symbol ;
15
16
use rustc_span:: Span ;
16
17
17
18
use crate :: borrow_check:: {
18
- borrow_set:: BorrowData , nll :: ConstraintDescription , region_infer :: Cause , MirBorrowckCtxt ,
19
- WriteKind ,
19
+ borrow_set:: BorrowData , diagnostics :: RegionErrorNamingCtx , nll :: ConstraintDescription ,
20
+ region_infer :: Cause , MirBorrowckCtxt , WriteKind ,
20
21
} ;
21
22
22
23
use super :: { find_use, RegionName , UseSpans } ;
@@ -254,6 +255,32 @@ impl BorrowExplanation {
254
255
}
255
256
256
257
impl < ' cx , ' tcx > MirBorrowckCtxt < ' cx , ' tcx > {
258
+ fn free_region_constraint_info (
259
+ & self ,
260
+ borrow_region : RegionVid ,
261
+ outlived_region : RegionVid ,
262
+ ) -> ( ConstraintCategory , bool , Span , Option < RegionName > ) {
263
+ let ( category, from_closure, span) = self . nonlexical_regioncx . best_blame_constraint (
264
+ & self . body ,
265
+ borrow_region,
266
+ NLLRegionVariableOrigin :: FreeRegion ,
267
+ |r| {
268
+ self . nonlexical_regioncx . provides_universal_region (
269
+ r,
270
+ borrow_region,
271
+ outlived_region,
272
+ )
273
+ } ,
274
+ ) ;
275
+
276
+ let mut renctx = RegionErrorNamingCtx :: new ( ) ;
277
+ let outlived_fr_name =
278
+ self . nonlexical_regioncx . give_region_a_name ( self , & mut renctx, outlived_region) ;
279
+ // TODO(mark-i-m): just return the region and let the caller name it
280
+
281
+ ( category, from_closure, span, outlived_fr_name)
282
+ }
283
+
257
284
/// Returns structured explanation for *why* the borrow contains the
258
285
/// point from `location`. This is key for the "3-point errors"
259
286
/// [described in the NLL RFC][d].
@@ -285,7 +312,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
285
312
let borrow_region_vid = borrow. region ;
286
313
debug ! ( "explain_why_borrow_contains_point: borrow_region_vid={:?}" , borrow_region_vid) ;
287
314
288
- let region_sub = regioncx. find_sub_region_live_at ( borrow_region_vid, location) ;
315
+ let region_sub =
316
+ self . nonlexical_regioncx . find_sub_region_live_at ( borrow_region_vid, location) ;
289
317
debug ! ( "explain_why_borrow_contains_point: region_sub={:?}" , region_sub) ;
290
318
291
319
match find_use:: find ( body, regioncx, tcx, region_sub, location) {
@@ -330,9 +358,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
330
358
331
359
None => {
332
360
if let Some ( region) = regioncx. to_error_region_vid ( borrow_region_vid) {
333
- let ( category, from_closure, span, region_name) = self
334
- . nonlexical_regioncx
335
- . free_region_constraint_info ( self , borrow_region_vid, region) ;
361
+ let ( category, from_closure, span, region_name) =
362
+ self . free_region_constraint_info ( borrow_region_vid, region) ;
336
363
if let Some ( region_name) = region_name {
337
364
let opt_place_desc = self . describe_place ( borrow. borrowed_place . as_ref ( ) ) ;
338
365
BorrowExplanation :: MustBeValidFor {
@@ -345,14 +372,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
345
372
} else {
346
373
debug ! (
347
374
"explain_why_borrow_contains_point: \
348
- Could not generate a region name"
375
+ Could not generate a region name"
349
376
) ;
350
377
BorrowExplanation :: Unexplained
351
378
}
352
379
} else {
353
380
debug ! (
354
381
"explain_why_borrow_contains_point: \
355
- Could not generate an error region vid"
382
+ Could not generate an error region vid"
356
383
) ;
357
384
BorrowExplanation :: Unexplained
358
385
}
0 commit comments