@@ -2777,8 +2777,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2777
2777
|| lt. kind == MissingLifetimeKind :: Underscore )
2778
2778
{
2779
2779
let pre = if lt. kind == MissingLifetimeKind :: Ampersand
2780
- && let Some ( ( kind, _span) ) =
2781
- self . diagnostic_metadata . current_function
2780
+ && let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
2782
2781
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2783
2782
&& !sig. decl . inputs . is_empty ( )
2784
2783
&& let sugg = sig
@@ -2803,7 +2802,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2803
2802
. collect :: < Vec < _ > > ( )
2804
2803
&& !sugg. is_empty ( )
2805
2804
{
2806
-
2807
2805
let ( the, s) = if sig. decl . inputs . len ( ) == 1 {
2808
2806
( "the" , "" )
2809
2807
} else {
@@ -2819,9 +2817,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2819
2817
) ;
2820
2818
"...or alternatively, you might want"
2821
2819
} else if ( lt. kind == MissingLifetimeKind :: Ampersand
2822
- || lt. kind == MissingLifetimeKind :: Underscore )
2823
- && let Some ( ( kind, _span) ) =
2824
- self . diagnostic_metadata . current_function
2820
+ || lt. kind == MissingLifetimeKind :: Underscore )
2821
+ && let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
2825
2822
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2826
2823
&& let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
2827
2824
&& !sig. decl . inputs . is_empty ( )
@@ -2842,26 +2839,25 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2842
2839
// So we look at every ref in the trait bound. If there's any, we
2843
2840
// suggest
2844
2841
// fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()>
2845
- let mut lt_finder = LifetimeFinder {
2846
- lifetime : lt. span ,
2847
- found : None ,
2848
- seen : vec ! [ ] ,
2849
- } ;
2842
+ let mut lt_finder =
2843
+ LifetimeFinder { lifetime : lt. span , found : None , seen : vec ! [ ] } ;
2850
2844
for bound in arg_refs {
2851
2845
if let ast:: GenericBound :: Trait ( trait_ref, _) = bound {
2852
2846
lt_finder. visit_trait_ref ( & trait_ref. trait_ref ) ;
2853
2847
}
2854
2848
}
2855
2849
lt_finder. visit_ty ( ret_ty) ;
2856
- let spans_suggs: Vec < _ > = lt_finder. seen . iter ( ) . filter_map ( |ty| {
2857
- match & ty. kind {
2850
+ let spans_suggs: Vec < _ > = lt_finder
2851
+ . seen
2852
+ . iter ( )
2853
+ . filter_map ( |ty| match & ty. kind {
2858
2854
TyKind :: Ref ( _, mut_ty) => {
2859
2855
let span = ty. span . with_hi ( mut_ty. ty . span . lo ( ) ) ;
2860
2856
Some ( ( span, "&'a " . to_string ( ) ) )
2861
2857
}
2862
- _ => None
2863
- }
2864
- } ) . collect ( ) ;
2858
+ _ => None ,
2859
+ } )
2860
+ . collect ( ) ;
2865
2861
self . suggest_introducing_lifetime (
2866
2862
err,
2867
2863
None ,
@@ -2882,20 +2878,16 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2882
2878
} ;
2883
2879
let mut owned_sugg = lt. kind == MissingLifetimeKind :: Ampersand ;
2884
2880
let mut sugg = vec ! [ ( lt. span, String :: new( ) ) ] ;
2885
- if let Some ( ( kind, _span) ) =
2886
- self . diagnostic_metadata . current_function
2881
+ if let Some ( ( kind, _span) ) = self . diagnostic_metadata . current_function
2887
2882
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2888
2883
&& let ast:: FnRetTy :: Ty ( ty) = & sig. decl . output
2889
2884
{
2890
- let mut lt_finder = LifetimeFinder {
2891
- lifetime : lt. span ,
2892
- found : None ,
2893
- seen : vec ! [ ] ,
2894
- } ;
2885
+ let mut lt_finder =
2886
+ LifetimeFinder { lifetime : lt. span , found : None , seen : vec ! [ ] } ;
2895
2887
lt_finder. visit_ty ( & ty) ;
2896
2888
2897
- if let [ Ty { span, kind : TyKind :: Ref ( _, mut_ty) , ..} ]
2898
- = & lt_finder. seen [ ..]
2889
+ if let [ Ty { span, kind : TyKind :: Ref ( _, mut_ty) , .. } ] =
2890
+ & lt_finder. seen [ ..]
2899
2891
{
2900
2892
// We might have a situation like
2901
2893
// fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()>
@@ -2910,9 +2902,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2910
2902
// Check if the path being borrowed is likely to be owned.
2911
2903
let path: Vec < _ > = Segment :: from_path ( path) ;
2912
2904
match self . resolve_path ( & path, Some ( TypeNS ) , None ) {
2913
- PathResult :: Module (
2914
- ModuleOrUniformRoot :: Module ( module) ,
2915
- ) => {
2905
+ PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) => {
2916
2906
match module. res ( ) {
2917
2907
Some ( Res :: PrimTy ( PrimTy :: Str ) ) => {
2918
2908
// Don't suggest `-> str`, suggest `-> String`.
@@ -2932,7 +2922,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2932
2922
| DefKind :: TyParam ,
2933
2923
_,
2934
2924
) ) => { }
2935
- _ => { // Do not suggest in all other cases.
2925
+ _ => {
2926
+ // Do not suggest in all other cases.
2936
2927
owned_sugg = false ;
2937
2928
}
2938
2929
}
@@ -2957,12 +2948,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2957
2948
| DefKind :: TyParam ,
2958
2949
_,
2959
2950
) => { }
2960
- _ => { // Do not suggest in all other cases.
2951
+ _ => {
2952
+ // Do not suggest in all other cases.
2961
2953
owned_sugg = false ;
2962
2954
}
2963
2955
}
2964
2956
}
2965
- _ => { // Do not suggest in all other cases.
2957
+ _ => {
2958
+ // Do not suggest in all other cases.
2966
2959
owned_sugg = false ;
2967
2960
}
2968
2961
}
0 commit comments