|
1 | 1 | use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; |
2 | 2 | use clippy_utils::source::snippet_with_applicability; |
3 | | -use clippy_utils::ty::is_type_diagnostic_item; |
| 3 | +use clippy_utils::ty::{is_copy, is_type_diagnostic_item}; |
4 | 4 | use clippy_utils::{is_expr_untyped_identity_function, is_mutable, is_trait_method, path_to_local_with_projections}; |
5 | 5 | use rustc_errors::Applicability; |
6 | 6 | use rustc_hir::{self as hir, ExprKind, Node, PatKind}; |
@@ -28,7 +28,14 @@ pub(super) fn check( |
28 | 28 | && let Some(call_span) = expr.span.trim_start(caller.span) |
29 | 29 | { |
30 | 30 | let main_sugg = (call_span, String::new()); |
31 | | - let mut app = Applicability::MachineApplicable; |
| 31 | + let mut app = if is_copy(cx, caller_ty) { |
| 32 | + // there is technically a behavioral change here for `Copy` iterators, where |
| 33 | + // `iter.map(|x| x).next()` would mutate a temporary copy of the iterator and |
| 34 | + // changing it to `iter.next()` mutates iter directly |
| 35 | + Applicability::Unspecified |
| 36 | + } else { |
| 37 | + Applicability::MachineApplicable |
| 38 | + }; |
32 | 39 |
|
33 | 40 | let needs_to_be_mutable = cx.typeck_results().expr_ty_adjusted(expr).is_mutable_ptr(); |
34 | 41 | if needs_to_be_mutable && !is_mutable(cx, caller) { |
|
0 commit comments