Skip to content

Commit

Permalink
iter conservation efforts: save the endangered .iter() and .into_iter()
Browse files Browse the repository at this point in the history
Make explicit_iter_loop and explicit_into_iter_loop allow-by-default, so
that people can turn them on if they want to enforce that style; avoid
presenting them as *the* idiomatic Rust style, rather than just *a* style.
  • Loading branch information
joshtriplett committed Sep 3, 2018
1 parent 2b7a530 commit 8f30cb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
if_not_else::IF_NOT_ELSE,
infinite_iter::MAYBE_INFINITE_ITER,
items_after_statements::ITEMS_AFTER_STATEMENTS,
loops::EXPLICIT_INTO_ITER_LOOP,
loops::EXPLICIT_ITER_LOOP,
matches::SINGLE_MATCH_ELSE,
methods::FILTER_MAP,
methods::OPTION_MAP_UNWRAP_OR,
Expand Down Expand Up @@ -546,8 +548,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
literal_representation::UNREADABLE_LITERAL,
loops::EMPTY_LOOP,
loops::EXPLICIT_COUNTER_LOOP,
loops::EXPLICIT_INTO_ITER_LOOP,
loops::EXPLICIT_ITER_LOOP,
loops::FOR_KV_MAP,
loops::FOR_LOOP_OVER_OPTION,
loops::FOR_LOOP_OVER_RESULT,
Expand Down Expand Up @@ -718,8 +718,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
literal_representation::LARGE_DIGIT_GROUPS,
literal_representation::UNREADABLE_LITERAL,
loops::EMPTY_LOOP,
loops::EXPLICIT_INTO_ITER_LOOP,
loops::EXPLICIT_ITER_LOOP,
loops::FOR_KV_MAP,
loops::NEEDLESS_RANGE_LOOP,
loops::WHILE_LET_ON_ITERATOR,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ declare_clippy_lint! {
/// ```
declare_clippy_lint! {
pub EXPLICIT_ITER_LOOP,
style,
pedantic,
"for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do"
}

Expand All @@ -107,7 +107,7 @@ declare_clippy_lint! {
/// ```
declare_clippy_lint! {
pub EXPLICIT_INTO_ITER_LOOP,
style,
pedantic,
"for-looping over `_.into_iter()` when `_` would do"
}

Expand Down Expand Up @@ -1209,7 +1209,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_
cx,
EXPLICIT_ITER_LOOP,
arg.span,
"it is more idiomatic to loop over references to containers instead of using explicit \
"it is more concise to loop over references to containers instead of using explicit \
iteration methods",
"to write this more concisely, try",
format!("&{}{}", muta, object),
Expand Down Expand Up @@ -1247,7 +1247,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
cx,
EXPLICIT_INTO_ITER_LOOP,
arg.span,
"it is more idiomatic to loop over containers instead of using explicit \
"it is more concise to loop over containers instead of using explicit \
iteration methods`",
"to write this more concisely, try",
object.to_string(),
Expand Down

0 comments on commit 8f30cb2

Please sign in to comment.