9
9
// except according to those terms.
10
10
11
11
use borrow_check:: nll:: region_infer:: RegionInferenceContext ;
12
- use borrow_check:: nll:: ToRegionVid ;
13
12
use borrow_check:: nll:: universal_regions:: DefiningTy ;
13
+ use borrow_check:: nll:: ToRegionVid ;
14
14
use rustc:: hir;
15
15
use rustc:: hir:: def_id:: DefId ;
16
16
use rustc:: infer:: InferCtxt ;
@@ -107,23 +107,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
107
107
} else {
108
108
None
109
109
}
110
- } ,
110
+ }
111
111
112
112
ty:: ReStatic => Some ( keywords:: StaticLifetime . name ( ) . as_interned_str ( ) ) ,
113
113
114
114
ty:: ReFree ( free_region) => match free_region. bound_region {
115
115
ty:: BoundRegion :: BrNamed ( _, name) => {
116
116
self . highlight_named_span ( tcx, error_region, & name, diag) ;
117
117
Some ( name)
118
- } ,
118
+ }
119
119
120
120
ty:: BoundRegion :: BrEnv => {
121
121
let mir_node_id = tcx. hir . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
122
122
let def_ty = self . universal_regions . defining_ty ;
123
123
124
124
if let DefiningTy :: Closure ( def_id, substs) = def_ty {
125
- let args_span = if let hir:: ExprKind :: Closure ( _, _, _, span, _)
126
- = tcx. hir . expect_expr ( mir_node_id) . node
125
+ let args_span = if let hir:: ExprKind :: Closure ( _, _, _, span, _) =
126
+ tcx. hir . expect_expr ( mir_node_id) . node
127
127
{
128
128
span
129
129
} else {
@@ -201,16 +201,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
201
201
let node = tcx. hir . as_local_node_id ( scope) . unwrap_or ( DUMMY_NODE_ID ) ;
202
202
203
203
let mut sp = cm. def_span ( tcx. hir . span ( node) ) ;
204
- if let Some ( param) = tcx. hir . get_generics ( scope) . and_then ( |generics| {
205
- generics. get_named ( name)
206
- } ) {
204
+ if let Some ( param) = tcx. hir
205
+ . get_generics ( scope)
206
+ . and_then ( |generics| generics. get_named ( name) )
207
+ {
207
208
sp = param. span ;
208
209
}
209
210
210
- diag. span_label (
211
- sp,
212
- format ! ( "lifetime `{}` defined here" , name) ,
213
- ) ;
211
+ diag. span_label ( sp, format ! ( "lifetime `{}` defined here" , name) ) ;
214
212
}
215
213
216
214
/// Find an argument that contains `fr` and label it with a fully
@@ -248,14 +246,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
248
246
return Some ( region_name) ;
249
247
}
250
248
251
- self . give_name_if_we_cannot_match_hir_ty (
252
- infcx,
253
- mir,
254
- fr,
255
- arg_ty,
256
- counter,
257
- diag,
258
- )
249
+ self . give_name_if_we_cannot_match_hir_ty ( infcx, mir, fr, arg_ty, counter, diag)
259
250
}
260
251
261
252
fn give_name_if_we_can_match_hir_ty_from_argument (
@@ -320,8 +311,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
320
311
infcx. extract_type_name ( & argument_ty)
321
312
} ) ;
322
313
323
- debug ! ( "give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}" ,
324
- type_name, needle_fr) ;
314
+ debug ! (
315
+ "give_name_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}" ,
316
+ type_name, needle_fr
317
+ ) ;
325
318
let assigned_region_name = if type_name. find ( & format ! ( "'{}" , counter) ) . is_some ( ) {
326
319
// Only add a label if we can confirm that a region was labelled.
327
320
let argument_index = self . get_argument_index_for_region ( infcx. tcx , needle_fr) ?;
@@ -553,13 +546,16 @@ impl<'tcx> RegionInferenceContext<'tcx> {
553
546
diag : & mut DiagnosticBuilder < ' _ > ,
554
547
) -> Option < InternedString > {
555
548
let upvar_index = self . get_upvar_index_for_region ( tcx, fr) ?;
556
- let ( upvar_name, upvar_span) = self . get_upvar_name_and_span_for_region ( tcx , mir ,
557
- upvar_index) ;
549
+ let ( upvar_name, upvar_span) =
550
+ self . get_upvar_name_and_span_for_region ( tcx , mir , upvar_index) ;
558
551
let region_name = self . synthesize_region_name ( counter) ;
559
552
560
553
diag. span_label (
561
554
upvar_span,
562
- format ! ( "lifetime `{}` appears in the type of `{}`" , region_name, upvar_name) ,
555
+ format ! (
556
+ "lifetime `{}` appears in the type of `{}`" ,
557
+ region_name, upvar_name
558
+ ) ,
563
559
) ;
564
560
565
561
Some ( region_name)
@@ -585,27 +581,33 @@ impl<'tcx> RegionInferenceContext<'tcx> {
585
581
"give_name_if_anonymous_region_appears_in_output: return_ty = {:?}" ,
586
582
return_ty
587
583
) ;
588
- if !infcx. tcx . any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr) {
584
+ if !infcx
585
+ . tcx
586
+ . any_free_region_meets ( & return_ty, |r| r. to_region_vid ( ) == fr)
587
+ {
589
588
return None ;
590
589
}
591
590
592
- let type_name = with_highlight_region ( fr, * counter, || {
593
- infcx. extract_type_name ( & return_ty)
594
- } ) ;
591
+ let type_name = with_highlight_region ( fr, * counter, || infcx. extract_type_name ( & return_ty) ) ;
595
592
596
593
let mir_node_id = tcx. hir . as_local_node_id ( mir_def_id) . expect ( "non-local mir" ) ;
597
594
598
- let ( return_span, mir_description) = if let hir:: ExprKind :: Closure ( _, _, _, span, gen_move)
599
- = tcx. hir . expect_expr ( mir_node_id) . node
600
- {
601
- (
602
- tcx. sess . source_map ( ) . end_point ( span) ,
603
- if gen_move. is_some ( ) { " of generator" } else { " of closure" }
604
- )
605
- } else {
606
- // unreachable?
607
- ( mir. span , "" )
608
- } ;
595
+ let ( return_span, mir_description) =
596
+ if let hir:: ExprKind :: Closure ( _, _, _, span, gen_move) =
597
+ tcx. hir . expect_expr ( mir_node_id) . node
598
+ {
599
+ (
600
+ tcx. sess . source_map ( ) . end_point ( span) ,
601
+ if gen_move. is_some ( ) {
602
+ " of generator"
603
+ } else {
604
+ " of closure"
605
+ } ,
606
+ )
607
+ } else {
608
+ // unreachable?
609
+ ( mir. span , "" )
610
+ } ;
609
611
610
612
diag. span_label (
611
613
return_span,
0 commit comments