@@ -2976,8 +2976,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2976
2976
|| lt. kind == MissingLifetimeKind :: Underscore )
2977
2977
{
2978
2978
let pre = if lt. kind == MissingLifetimeKind :: Ampersand
2979
- && let Some ( ( kind, _span) ) =
2980
- self . diagnostic_metadata . current_function
2979
+ && let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
2981
2980
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2982
2981
&& !sig. decl . inputs . is_empty ( )
2983
2982
&& let sugg = sig
@@ -3002,7 +3001,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3002
3001
. collect :: < Vec < _ > > ( )
3003
3002
&& !sugg. is_empty ( )
3004
3003
{
3005
-
3006
3004
let ( the, s) = if sig. decl . inputs . len ( ) == 1 {
3007
3005
( "the" , "" )
3008
3006
} else {
@@ -3018,9 +3016,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3018
3016
) ;
3019
3017
"...or alternatively, you might want"
3020
3018
} else if ( lt. kind == MissingLifetimeKind :: Ampersand
3021
- || lt. kind == MissingLifetimeKind :: Underscore )
3022
- && let Some ( ( kind, _span) ) =
3023
- self . diagnostic_metadata . current_function
3019
+ || lt. kind == MissingLifetimeKind :: Underscore )
3020
+ && let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
3024
3021
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
3025
3022
&& let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
3026
3023
&& !sig. decl . inputs . is_empty ( )
@@ -3041,26 +3038,25 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3041
3038
// So we look at every ref in the trait bound. If there's any, we
3042
3039
// suggest
3043
3040
// fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()>
3044
- let mut lt_finder = LifetimeFinder {
3045
- lifetime : lt. span ,
3046
- found : None ,
3047
- seen : vec ! [ ] ,
3048
- } ;
3041
+ let mut lt_finder =
3042
+ LifetimeFinder { lifetime : lt. span , found : None , seen : vec ! [ ] } ;
3049
3043
for bound in arg_refs {
3050
3044
if let ast:: GenericBound :: Trait ( trait_ref, _) = bound {
3051
3045
lt_finder. visit_trait_ref ( & trait_ref. trait_ref ) ;
3052
3046
}
3053
3047
}
3054
3048
lt_finder. visit_ty ( ret_ty) ;
3055
- let spans_suggs: Vec < _ > = lt_finder. seen . iter ( ) . filter_map ( |ty| {
3056
- match & ty. kind {
3049
+ let spans_suggs: Vec < _ > = lt_finder
3050
+ . seen
3051
+ . iter ( )
3052
+ . filter_map ( |ty| match & ty. kind {
3057
3053
TyKind :: Ref ( _, mut_ty) => {
3058
3054
let span = ty. span . with_hi ( mut_ty. ty . span . lo ( ) ) ;
3059
3055
Some ( ( span, "&'a " . to_string ( ) ) )
3060
3056
}
3061
- _ => None
3062
- }
3063
- } ) . collect ( ) ;
3057
+ _ => None ,
3058
+ } )
3059
+ . collect ( ) ;
3064
3060
self . suggest_introducing_lifetime (
3065
3061
err,
3066
3062
None ,
@@ -3081,20 +3077,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3081
3077
} ;
3082
3078
let mut owned_sugg = lt. kind == MissingLifetimeKind :: Ampersand ;
3083
3079
let mut sugg = vec ! [ ( lt. span, String :: new( ) ) ] ;
3084
- if let Some ( ( kind, _span) ) =
3085
- self . diagnostic_metadata . current_function
3080
+ if let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
3086
3081
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
3087
3082
&& let ast:: FnRetTy :: Ty ( ty) = & sig. decl . output
3088
3083
{
3089
- let mut lt_finder = LifetimeFinder {
3090
- lifetime : lt. span ,
3091
- found : None ,
3092
- seen : vec ! [ ] ,
3093
- } ;
3084
+ let mut lt_finder =
3085
+ LifetimeFinder { lifetime : lt. span , found : None , seen : vec ! [ ] } ;
3094
3086
lt_finder. visit_ty ( & ty) ;
3095
3087
3096
- if let [ Ty { span, kind : TyKind :: Ref ( _, mut_ty) , ..} ]
3097
- = & lt_finder. seen [ ..]
3088
+ if let [ Ty { span, kind : TyKind :: Ref ( _, mut_ty) , .. } ] =
3089
+ & lt_finder. seen [ ..]
3098
3090
{
3099
3091
// We might have a situation like
3100
3092
// fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()>
@@ -3109,9 +3101,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3109
3101
// Check if the path being borrowed is likely to be owned.
3110
3102
let path: Vec < _ > = Segment :: from_path ( path) ;
3111
3103
match self . resolve_path ( & path, Some ( TypeNS ) , None ) {
3112
- PathResult :: Module (
3113
- ModuleOrUniformRoot :: Module ( module) ,
3114
- ) => {
3104
+ PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
3115
3105
match module. res ( ) {
3116
3106
Some ( Res :: PrimTy ( PrimTy :: Str ) ) => {
3117
3107
// Don't suggest `-> str`, suggest `-> String`.
@@ -3131,7 +3121,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3131
3121
| DefKind :: TyParam ,
3132
3122
_,
3133
3123
) ) => { }
3134
- _ => { // Do not suggest in all other cases.
3124
+ _ => {
3125
+ // Do not suggest in all other cases.
3135
3126
owned_sugg = false ;
3136
3127
}
3137
3128
}
@@ -3156,12 +3147,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3156
3147
| DefKind :: TyParam ,
3157
3148
_,
3158
3149
) => { }
3159
- _ => { // Do not suggest in all other cases.
3150
+ _ => {
3151
+ // Do not suggest in all other cases.
3160
3152
owned_sugg = false ;
3161
3153
}
3162
3154
}
3163
3155
}
3164
- _ => { // Do not suggest in all other cases.
3156
+ _ => {
3157
+ // Do not suggest in all other cases.
3165
3158
owned_sugg = false ;
3166
3159
}
3167
3160
}
0 commit comments