@@ -2772,9 +2772,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2772
2772
// we identified that the return expression references only one argument, we
2773
2773
// would suggest borrowing only that argument, and we'd skip the prior
2774
2774
// "use `'static`" suggestion entirely.
2775
- if let [ lt] = & lifetime_refs[ ..] && lt. kind == MissingLifetimeKind :: Ampersand {
2776
- let pre = if let Some ( ( kind, _span) ) =
2777
- self . diagnostic_metadata . current_function
2775
+ if let [ lt] = & lifetime_refs[ ..]
2776
+ && ( lt. kind == MissingLifetimeKind :: Ampersand
2777
+ || lt. kind == MissingLifetimeKind :: Underscore )
2778
+ {
2779
+ let pre = if lt. kind == MissingLifetimeKind :: Ampersand
2780
+ && let Some ( ( kind, _span) ) =
2781
+ self . diagnostic_metadata . current_function
2778
2782
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2779
2783
&& !sig. decl . inputs . is_empty ( )
2780
2784
&& let sugg = sig
@@ -2814,8 +2818,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2814
2818
Applicability :: MaybeIncorrect ,
2815
2819
) ;
2816
2820
"...or alternatively, you might want"
2817
- } else if let Some ( ( kind, _span) ) =
2818
- self . diagnostic_metadata . current_function
2821
+ } else if ( lt. kind == MissingLifetimeKind :: Ampersand
2822
+ || lt. kind == MissingLifetimeKind :: Underscore )
2823
+ && let Some ( ( kind, _span) ) =
2824
+ self . diagnostic_metadata . current_function
2819
2825
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2820
2826
&& let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
2821
2827
&& !sig. decl . inputs . is_empty ( )
@@ -2860,7 +2866,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2860
2866
err,
2861
2867
None ,
2862
2868
|err, higher_ranked, span, message, intro_sugg| {
2863
- info ! ( ?span, ?message, ?intro_sugg) ;
2864
2869
err. multipart_suggestion_verbose (
2865
2870
message,
2866
2871
std:: iter:: once ( ( span, intro_sugg) )
@@ -2894,7 +2899,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2894
2899
&& segments[ 0 ] . ident . name == sym:: str
2895
2900
{
2896
2901
// Don't suggest `-> str`, suggest `-> String`.
2897
- sugg = vec ! [ ( lt. span. with_hi( ty. span. hi( ) ) , "String" . to_string( ) ) ] ;
2902
+ sugg = vec ! [
2903
+ ( lt. span. with_hi( ty. span. hi( ) ) , "String" . to_string( ) ) ,
2904
+ ] ;
2898
2905
}
2899
2906
if let TyKind :: Slice ( inner_ty) = & ty. kind {
2900
2907
// Don't suggest `-> [T]`, suggest `-> Vec<T>`.
@@ -2905,11 +2912,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2905
2912
}
2906
2913
}
2907
2914
} ;
2908
- err. multipart_suggestion_verbose (
2909
- format ! ( "{pre} to return an owned value" ) ,
2910
- sugg,
2911
- Applicability :: MaybeIncorrect ,
2912
- ) ;
2915
+ if lt. kind == MissingLifetimeKind :: Ampersand {
2916
+ err. multipart_suggestion_verbose (
2917
+ format ! ( "{pre} to return an owned value" ) ,
2918
+ sugg,
2919
+ Applicability :: MaybeIncorrect ,
2920
+ ) ;
2921
+ }
2913
2922
}
2914
2923
}
2915
2924
0 commit comments