@@ -68,10 +68,10 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
68
68
}
69
69
}
70
70
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 )
73
73
} else if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( result_type) ) {
74
- & paths:: RESULT_OK
74
+ ( "Result" , & paths:: RESULT_OK )
75
75
} else {
76
76
return ;
77
77
} ;
@@ -98,23 +98,26 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
98
98
UNNECESSARY_WRAP ,
99
99
span,
100
100
"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
+ } ) ;
102
118
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,
118
121
Applicability :: MachineApplicable ,
119
122
) ;
120
123
} ,
0 commit comments