@@ -2971,9 +2971,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
29712971 // we identified that the return expression references only one argument, we
29722972 // would suggest borrowing only that argument, and we'd skip the prior
29732973 // "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
29772981 && let FnKind :: Fn ( _, _, sig, _, _, _) = kind
29782982 && !sig. decl . inputs . is_empty ( )
29792983 && let sugg = sig
@@ -3013,8 +3017,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30133017 Applicability :: MaybeIncorrect ,
30143018 ) ;
30153019 "...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
30183024 && let FnKind :: Fn ( _, _, sig, _, _, _) = kind
30193025 && let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
30203026 && !sig. decl . inputs . is_empty ( )
@@ -3059,7 +3065,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30593065 err,
30603066 None ,
30613067 |err, higher_ranked, span, message, intro_sugg| {
3062- info ! ( ?span, ?message, ?intro_sugg) ;
30633068 err. multipart_suggestion_verbose (
30643069 message,
30653070 std:: iter:: once ( ( span, intro_sugg) )
@@ -3093,7 +3098,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30933098 && segments[ 0 ] . ident . name == sym:: str
30943099 {
30953100 // 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+ ] ;
30973104 }
30983105 if let TyKind :: Slice ( inner_ty) = & ty. kind {
30993106 // Don't suggest `-> [T]`, suggest `-> Vec<T>`.
@@ -3104,11 +3111,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31043111 }
31053112 }
31063113 } ;
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+ }
31123121 }
31133122 }
31143123
0 commit comments