You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the type of the result of a call to `IntoIterator::into_iter()`
and the type of the receiver are the same, then the receiver
implements `Iterator` and `into_iter()` is the identity function.
There is only one context in which the call to `into_iter()` cannot be
safely removed: when the receiver is a immutable local variable, calling
`into_iter()` consumes the variable and returns its value as a temporary
expression (which is mutable). It would not be always safe to remove the
call to `into_iter()` if this temporary expression is used in the context
of a larger expression, for example as the receiver of a mutable method.
In a non-expression contexts this is safe though, for example as the RHS
of an assignment statement.
Another case that we want to avoid is omitting the call to
`into_iter()` when the receiver is a `const` item used in a larger
expression. In some cases, the compiler would give a warning although
the code is equivalent:
const R: std::ops::Range<i32> = 1..10;
let _ = R.into_iter().next(); // No compiler warning
let _ = R.next(); // Warning (const_item_migration)
To avoid those two cases, we choose to skip all situations where:
- the receiver of `into_iter()` is of kind `ExprKind::Path` and does
not denote a mutable local variable;
- and the result of `into_iter()` is used in a larger expression.
0 commit comments