1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use clippy_utils::ty::{get_iterator_item_ty, is_copy};
3 use clippy_utils::{is_trait_method, meets_msrv};
4 use rustc_errors::Applicability;
6 use rustc_lint::LateContext;
8 use rustc_semver::RustcVersion;
9 use rustc_span::{sym, Span};
11 use super::CLONED_INSTEAD_OF_COPIED;
13 const ITERATOR_COPIED_MSRV: RustcVersion = RustcVersion::new(1, 36, 0);
14 const OPTION_COPIED_MSRV: RustcVersion = RustcVersion::new(1, 35, 0);
16 pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, msrv: Option<&RustcVersion>) {
17 let recv_ty = cx.typeck_results().expr_ty_adjusted(recv);
18 let inner_ty = match recv_ty.kind() {
21 if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) && meets_msrv(msrv, &OPTION_COPIED_MSRV) =>
25 _ if is_trait_method(cx, expr, sym::Iterator) && meets_msrv(msrv, &ITERATOR_COPIED_MSRV) => {
26 match get_iterator_item_ty(cx, recv_ty) {
27 // <T as Iterator>::Item
34 match inner_ty.kind() {
36 ty::Ref(_, ty, _) if is_copy(cx, ty) => {},
41 CLONED_INSTEAD_OF_COPIED,
43 "used `cloned` where `copied` could be used instead",
46 Applicability::MachineApplicable,