@@ -2971,9 +2971,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2971
2971
// we identified that the return expression references only one argument, we
2972
2972
// would suggest borrowing only that argument, and we'd skip the prior
2973
2973
// "use `'static`" suggestion entirely.
2974
- if let [ lt] = & lifetime_refs[ ..] && lt. kind == MissingLifetimeKind :: Ampersand {
2975
- let pre = if let Some ( ( kind, _span) ) =
2976
- self . diagnostic_metadata . current_function
2974
+ if let [ lt] = & lifetime_refs[ ..]
2975
+ && ( lt. kind == MissingLifetimeKind :: Ampersand
2976
+ || lt. kind == MissingLifetimeKind :: Underscore )
2977
+ {
2978
+ let pre = if lt. kind == MissingLifetimeKind :: Ampersand
2979
+ && let Some ( ( kind, _span) ) =
2980
+ self . diagnostic_metadata . current_function
2977
2981
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
2978
2982
&& !sig. decl . inputs . is_empty ( )
2979
2983
&& let sugg = sig
@@ -3013,8 +3017,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3013
3017
Applicability :: MaybeIncorrect ,
3014
3018
) ;
3015
3019
"...or alternatively, you might want"
3016
- } else if let Some ( ( kind, _span) ) =
3017
- self . diagnostic_metadata . current_function
3020
+ } else if ( lt. kind == MissingLifetimeKind :: Ampersand
3021
+ || lt. kind == MissingLifetimeKind :: Underscore )
3022
+ && let Some ( ( kind, _span) ) =
3023
+ self . diagnostic_metadata . current_function
3018
3024
&& let FnKind :: Fn ( _, _, sig, _, _, _) = kind
3019
3025
&& let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
3020
3026
&& !sig. decl . inputs . is_empty ( )
@@ -3059,7 +3065,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3059
3065
err,
3060
3066
None ,
3061
3067
|err, higher_ranked, span, message, intro_sugg| {
3062
- info ! ( ?span, ?message, ?intro_sugg) ;
3063
3068
err. multipart_suggestion_verbose (
3064
3069
message,
3065
3070
std:: iter:: once ( ( span, intro_sugg) )
@@ -3093,7 +3098,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3093
3098
&& segments[ 0 ] . ident . name == sym:: str
3094
3099
{
3095
3100
// Don't suggest `-> str`, suggest `-> String`.
3096
- sugg = vec ! [ ( lt. span. with_hi( ty. span. hi( ) ) , "String" . to_string( ) ) ] ;
3101
+ sugg = vec ! [
3102
+ ( lt. span. with_hi( ty. span. hi( ) ) , "String" . to_string( ) ) ,
3103
+ ] ;
3097
3104
}
3098
3105
if let TyKind :: Slice ( inner_ty) = & ty. kind {
3099
3106
// Don't suggest `-> [T]`, suggest `-> Vec<T>`.
@@ -3104,11 +3111,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3104
3111
}
3105
3112
}
3106
3113
} ;
3107
- err. multipart_suggestion_verbose (
3108
- format ! ( "{pre} to return an owned value" ) ,
3109
- sugg,
3110
- Applicability :: MaybeIncorrect ,
3111
- ) ;
3114
+ if lt. kind == MissingLifetimeKind :: Ampersand {
3115
+ err. multipart_suggestion_verbose (
3116
+ format ! ( "{pre} to return an owned value" ) ,
3117
+ sugg,
3118
+ Applicability :: MaybeIncorrect ,
3119
+ ) ;
3120
+ }
3112
3121
}
3113
3122
}
3114
3123
0 commit comments