@@ -336,21 +336,35 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
336
336
337
337
let arg_ty = self . regioncx . universal_regions ( ) . unnormalized_input_tys
338
338
[ implicit_inputs + argument_index] ;
339
- if let Some ( region_name ) =
339
+ if let Some ( highlight ) =
340
340
self . give_name_if_we_can_match_hir_ty_from_argument ( fr, arg_ty, argument_index)
341
341
{
342
- return Some ( region_name) ;
342
+ return Some ( RegionName {
343
+ name : self . synthesize_region_name ( ) ,
344
+ source : RegionNameSource :: AnonRegionFromArgument ( highlight) ,
345
+ } ) ;
343
346
}
344
347
345
- self . give_name_if_we_cannot_match_hir_ty ( fr, arg_ty)
348
+ let counter = * self . next_region_name . try_borrow ( ) . unwrap ( ) ;
349
+ if let Some ( highlight) = self . give_name_if_we_cannot_match_hir_ty ( fr, arg_ty, counter) {
350
+ Some ( RegionName {
351
+ // This counter value will already have been used, so this function will increment
352
+ // it so the next value will be used next and return the region name that would
353
+ // have been used.
354
+ name : self . synthesize_region_name ( ) ,
355
+ source : RegionNameSource :: AnonRegionFromArgument ( highlight) ,
356
+ } )
357
+ } else {
358
+ None
359
+ }
346
360
}
347
361
348
362
fn give_name_if_we_can_match_hir_ty_from_argument (
349
363
& self ,
350
364
needle_fr : RegionVid ,
351
365
argument_ty : Ty < ' tcx > ,
352
366
argument_index : usize ,
353
- ) -> Option < RegionName > {
367
+ ) -> Option < RegionNameHighlight > {
354
368
let mir_hir_id = self . infcx . tcx . hir ( ) . as_local_hir_id ( self . mir_def_id ) ;
355
369
let fn_decl = self . infcx . tcx . hir ( ) . fn_decl_by_hir_id ( mir_hir_id) ?;
356
370
let argument_hir_ty: & hir:: Ty < ' _ > = fn_decl. inputs . get ( argument_index) ?;
@@ -381,8 +395,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
381
395
& self ,
382
396
needle_fr : RegionVid ,
383
397
argument_ty : Ty < ' tcx > ,
384
- ) -> Option < RegionName > {
385
- let counter = * self . next_region_name . try_borrow ( ) . unwrap ( ) ;
398
+ counter : usize ,
399
+ ) -> Option < RegionNameHighlight > {
386
400
let mut highlight = RegionHighlightMode :: default ( ) ;
387
401
highlight. highlighting_region_vid ( needle_fr, counter) ;
388
402
let type_name = self . infcx . extract_type_name ( & argument_ty, Some ( highlight) ) . 0 ;
@@ -391,7 +405,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
391
405
"give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}" ,
392
406
type_name, needle_fr
393
407
) ;
394
- let assigned_region_name = if type_name. find ( & format ! ( "'{}" , counter) ) . is_some ( ) {
408
+ if type_name. find ( & format ! ( "'{}" , counter) ) . is_some ( ) {
395
409
// Only add a label if we can confirm that a region was labelled.
396
410
let argument_index =
397
411
self . regioncx . get_argument_index_for_region ( self . infcx . tcx , needle_fr) ?;
@@ -401,20 +415,10 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
401
415
argument_index,
402
416
) ;
403
417
404
- Some ( RegionName {
405
- // This counter value will already have been used, so this function will increment
406
- // it so the next value will be used next and return the region name that would
407
- // have been used.
408
- name : self . synthesize_region_name ( ) ,
409
- source : RegionNameSource :: AnonRegionFromArgument (
410
- RegionNameHighlight :: CannotMatchHirTy ( span, type_name) ,
411
- ) ,
412
- } )
418
+ Some ( RegionNameHighlight :: CannotMatchHirTy ( span, type_name) )
413
419
} else {
414
420
None
415
- } ;
416
-
417
- assigned_region_name
421
+ }
418
422
}
419
423
420
424
/// Attempts to highlight the specific part of a type annotation
@@ -443,7 +447,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
443
447
needle_fr : RegionVid ,
444
448
argument_ty : Ty < ' tcx > ,
445
449
argument_hir_ty : & hir:: Ty < ' _ > ,
446
- ) -> Option < RegionName > {
450
+ ) -> Option < RegionNameHighlight > {
447
451
let search_stack: & mut Vec < ( Ty < ' tcx > , & hir:: Ty < ' _ > ) > =
448
452
& mut vec ! [ ( argument_ty, argument_hir_ty) ] ;
449
453
@@ -460,18 +464,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
460
464
hir:: TyKind :: Rptr ( _lifetime, referent_hir_ty) ,
461
465
) => {
462
466
if region. to_region_vid ( ) == needle_fr {
463
- let region_name = self . synthesize_region_name ( ) ;
464
-
465
467
// Just grab the first character, the `&`.
466
468
let source_map = self . infcx . tcx . sess . source_map ( ) ;
467
469
let ampersand_span = source_map. start_point ( hir_ty. span ) ;
468
470
469
- return Some ( RegionName {
470
- name : region_name,
471
- source : RegionNameSource :: AnonRegionFromArgument (
472
- RegionNameHighlight :: MatchedHirTy ( ampersand_span) ,
473
- ) ,
474
- } ) ;
471
+ return Some ( RegionNameHighlight :: MatchedHirTy ( ampersand_span) ) ;
475
472
}
476
473
477
474
// Otherwise, let's descend into the referent types.
@@ -491,13 +488,13 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
491
488
Res :: Def ( DefKind :: TyAlias , _) => ( ) ,
492
489
_ => {
493
490
if let Some ( last_segment) = path. segments . last ( ) {
494
- if let Some ( name ) = self . match_adt_and_segment (
491
+ if let Some ( highlight ) = self . match_adt_and_segment (
495
492
substs,
496
493
needle_fr,
497
494
last_segment,
498
495
search_stack,
499
496
) {
500
- return Some ( name ) ;
497
+ return Some ( highlight ) ;
501
498
}
502
499
}
503
500
}
@@ -540,7 +537,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
540
537
needle_fr : RegionVid ,
541
538
last_segment : & ' hir hir:: PathSegment < ' hir > ,
542
539
search_stack : & mut Vec < ( Ty < ' tcx > , & ' hir hir:: Ty < ' hir > ) > ,
543
- ) -> Option < RegionName > {
540
+ ) -> Option < RegionNameHighlight > {
544
541
// Did the user give explicit arguments? (e.g., `Foo<..>`)
545
542
let args = last_segment. args . as_ref ( ) ?;
546
543
let lifetime =
@@ -550,14 +547,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
550
547
| hir:: LifetimeName :: Error
551
548
| hir:: LifetimeName :: Static
552
549
| hir:: LifetimeName :: Underscore => {
553
- let region_name = self . synthesize_region_name ( ) ;
554
550
let lifetime_span = lifetime. span ;
555
- Some ( RegionName {
556
- name : region_name,
557
- source : RegionNameSource :: AnonRegionFromArgument (
558
- RegionNameHighlight :: MatchedAdtAndSegment ( lifetime_span) ,
559
- ) ,
560
- } )
551
+ Some ( RegionNameHighlight :: MatchedAdtAndSegment ( lifetime_span) )
561
552
}
562
553
563
554
hir:: LifetimeName :: ImplicitObjectLifetimeDefault | hir:: LifetimeName :: Implicit => {
0 commit comments