@@ -68,10 +68,10 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
6868 }
6969 }
7070
71- let path = if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( option_type) ) {
72- & paths:: OPTION_SOME
71+ let ( return_type , path) = if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( option_type) ) {
72+ ( "Option" , & paths:: OPTION_SOME )
7373 } else if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( result_type) ) {
74- & paths:: RESULT_OK
74+ ( "Result" , & paths:: RESULT_OK )
7575 } else {
7676 return ;
7777 } ;
@@ -98,23 +98,26 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
9898 UNNECESSARY_WRAP ,
9999 span,
100100 "this function returns unnecessarily wrapping data" ,
101- move |diag| {
101+ |diag| {
102+ let inner_ty = return_ty ( cx, hir_id)
103+ . walk ( )
104+ . skip ( 1 ) // skip `std::option::Option` or `std::result::Result`
105+ . take ( 1 ) // take the first outermost inner type
106+ . filter_map ( |inner| match inner. unpack ( ) {
107+ GenericArgKind :: Type ( inner_ty) => Some ( inner_ty. to_string ( ) ) ,
108+ _ => None ,
109+ } ) ;
110+ inner_ty. for_each ( |inner_ty| {
111+ diag. span_suggestion (
112+ fn_decl. output . span ( ) ,
113+ format ! ( "remove `{}` from the return type..." , return_type) . as_str ( ) ,
114+ inner_ty,
115+ Applicability :: MachineApplicable ,
116+ ) ;
117+ } ) ;
102118 diag. multipart_suggestion (
103- "factor this out to" ,
104- suggs
105- . into_iter ( )
106- . chain ( {
107- let inner_ty = return_ty ( cx, hir_id)
108- . walk ( )
109- . skip ( 1 ) // skip `std::option::Option` or `std::result::Result`
110- . take ( 1 ) // take the first outermost inner type
111- . filter_map ( |inner| match inner. unpack ( ) {
112- GenericArgKind :: Type ( inner_ty) => Some ( inner_ty. to_string ( ) ) ,
113- _ => None ,
114- } ) ;
115- inner_ty. map ( |inner_ty| ( fn_decl. output . span ( ) , inner_ty) )
116- } )
117- . collect ( ) ,
119+ "...and change the returning expressions" ,
120+ suggs,
118121 Applicability :: MachineApplicable ,
119122 ) ;
120123 } ,
0 commit comments