12
12
13
13
use infer:: error_reporting:: nice_region_error:: NiceRegionError ;
14
14
use infer:: lexical_region_resolve:: RegionResolutionError ;
15
- use ty:: RegionKind ;
15
+ use ty:: { BoundRegion , FreeRegion , RegionKind } ;
16
16
use util:: common:: ErrorReported ;
17
17
18
18
impl < ' a , ' gcx , ' tcx > NiceRegionError < ' a , ' gcx , ' tcx > {
@@ -29,7 +29,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
29
29
) => {
30
30
let anon_reg_sup = self . is_suitable_region ( sup_r) ?;
31
31
if sub_r == & RegionKind :: ReStatic &&
32
- self . _is_return_type_impl_trait ( anon_reg_sup. def_id )
32
+ self . is_return_type_impl_trait ( anon_reg_sup. def_id )
33
33
{
34
34
let sp = var_origin. span ( ) ;
35
35
let return_sp = sub_origin. span ( ) ;
@@ -54,6 +54,12 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
54
54
) ;
55
55
}
56
56
57
+ let lifetime_name = match sup_r {
58
+ RegionKind :: ReFree ( FreeRegion {
59
+ bound_region : BoundRegion :: BrNamed ( _, ref name) , ..
60
+ } ) => format ! ( "{}" , name) ,
61
+ _ => "'_" . to_owned ( ) ,
62
+ } ;
57
63
if let Ok ( snippet) = self . tcx . sess . codemap ( ) . span_to_snippet ( return_sp) {
58
64
err. span_suggestion (
59
65
return_sp,
@@ -62,7 +68,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
62
68
less than `'static` and match {}",
63
69
lifetime,
64
70
) ,
65
- format ! ( "{} + '_ " , snippet) ,
71
+ format ! ( "{} + {} " , snippet, lifetime_name ) ,
66
72
) ;
67
73
}
68
74
err. emit ( ) ;
0 commit comments