@@ -176,6 +176,33 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
176176 }
177177 } ,
178178
179+ ExprKind :: MethodCall ( path, recv, [ arg] , _) => {
180+ if matches ! (
181+ path. ident. name,
182+ sym:: map | sym:: map_err | sym:: map_break | sym:: map_continue
183+ ) && has_eligible_receiver ( cx, recv, e)
184+ && ( is_trait_item ( cx, arg, sym:: Into ) || is_trait_item ( cx, arg, sym:: From ) )
185+ && let ty:: FnDef ( _, args) = cx. typeck_results ( ) . expr_ty ( arg) . kind ( )
186+ && let & [ from_ty, to_ty] = args. into_type_list ( cx. tcx ) . as_slice ( )
187+ && same_type_and_consts ( from_ty, to_ty)
188+ {
189+ span_lint_and_then (
190+ cx,
191+ USELESS_CONVERSION ,
192+ e. span . with_lo ( recv. span . hi ( ) ) ,
193+ format ! ( "useless conversion to the same type: `{from_ty}`" ) ,
194+ |diag| {
195+ diag. suggest_remove_item (
196+ cx,
197+ e. span . with_lo ( recv. span . hi ( ) ) ,
198+ "consider removing" ,
199+ Applicability :: MachineApplicable ,
200+ ) ;
201+ } ,
202+ ) ;
203+ }
204+ } ,
205+
179206 ExprKind :: MethodCall ( name, recv, [ ] , _) => {
180207 if is_trait_method ( cx, e, sym:: Into ) && name. ident . name == sym:: into {
181208 let a = cx. typeck_results ( ) . expr_ty ( e) ;
@@ -412,32 +439,6 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
412439 }
413440}
414441
415- /// Check if `arg` is a `Into::into` or `From::from` applied to `receiver` to give `expr`, through a
416- /// higher-order mapping function.
417- pub fn check_function_application ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , recv : & Expr < ' _ > , arg : & Expr < ' _ > ) {
418- if has_eligible_receiver ( cx, recv, expr)
419- && ( is_trait_item ( cx, arg, sym:: Into ) || is_trait_item ( cx, arg, sym:: From ) )
420- && let ty:: FnDef ( _, args) = cx. typeck_results ( ) . expr_ty ( arg) . kind ( )
421- && let & [ from_ty, to_ty] = args. into_type_list ( cx. tcx ) . as_slice ( )
422- && same_type_and_consts ( from_ty, to_ty)
423- {
424- span_lint_and_then (
425- cx,
426- USELESS_CONVERSION ,
427- expr. span . with_lo ( recv. span . hi ( ) ) ,
428- format ! ( "useless conversion to the same type: `{from_ty}`" ) ,
429- |diag| {
430- diag. suggest_remove_item (
431- cx,
432- expr. span . with_lo ( recv. span . hi ( ) ) ,
433- "consider removing" ,
434- Applicability :: MachineApplicable ,
435- ) ;
436- } ,
437- ) ;
438- }
439- }
440-
441442fn has_eligible_receiver ( cx : & LateContext < ' _ > , recv : & Expr < ' _ > , expr : & Expr < ' _ > ) -> bool {
442443 if is_inherent_method_call ( cx, expr) {
443444 matches ! (
0 commit comments