Skip to content

Commit a87443a

Browse files
committed
Emit map_unit_fn lint in closure case
1 parent ddd7d10 commit a87443a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler/rustc_lint/src/map_unit_fn.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
7272
},
7373
)
7474
}
75+
} else if let ty::Closure(id, subs) = arg_ty.kind() {
76+
let cl_ty = subs.as_closure().sig();
77+
let ret_ty = cl_ty.output().skip_binder();
78+
if is_unit_type(ret_ty) {
79+
cx.emit_spanned_lint(
80+
MAP_UNIT_FN,
81+
span,
82+
MappingToUnit {
83+
function_label: cx.tcx.span_of_impl(*id).unwrap(),
84+
argument_label: args[0].span,
85+
map_label: arg_ty.default_span(cx.tcx),
86+
suggestion: path.ident.span,
87+
replace: "for_each".to_string(),
88+
},
89+
)
90+
}
7591
}
7692
}
7793
}

0 commit comments

Comments
 (0)