@@ -2772,9 +2772,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
27722772 // we identified that the return expression references only one argument, we
27732773 // would suggest borrowing only that argument, and we'd skip the prior
27742774 // "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
27782782 && let FnKind :: Fn ( _, _, sig, _, _, _) = kind
27792783 && !sig. decl . inputs . is_empty ( )
27802784 && let sugg = sig
@@ -2814,8 +2818,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
28142818 Applicability :: MaybeIncorrect ,
28152819 ) ;
28162820 "...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
28192825 && let FnKind :: Fn ( _, _, sig, _, _, _) = kind
28202826 && let ast:: FnRetTy :: Ty ( ret_ty) = & sig. decl . output
28212827 && !sig. decl . inputs . is_empty ( )
@@ -2860,7 +2866,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
28602866 err,
28612867 None ,
28622868 |err, higher_ranked, span, message, intro_sugg| {
2863- info ! ( ?span, ?message, ?intro_sugg) ;
28642869 err. multipart_suggestion_verbose (
28652870 message,
28662871 std:: iter:: once ( ( span, intro_sugg) )
@@ -2894,7 +2899,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
28942899 && segments[ 0 ] . ident . name == sym:: str
28952900 {
28962901 // 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+ ] ;
28982905 }
28992906 if let TyKind :: Slice ( inner_ty) = & ty. kind {
29002907 // Don't suggest `-> [T]`, suggest `-> Vec<T>`.
@@ -2905,11 +2912,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
29052912 }
29062913 }
29072914 } ;
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+ }
29132922 }
29142923 }
29152924
0 commit comments