rename lint to manual_while_let_some
This commit is contained in:
parent
f10e39fd2b
commit
8d8178f931
@ -4797,6 +4797,7 @@ Released 2018-09-13
|
|||||||
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
|
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
|
||||||
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
|
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
|
||||||
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
|
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
|
||||||
|
[`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some
|
||||||
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
|
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
|
||||||
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
|
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
|
||||||
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
|
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
|
||||||
@ -5160,7 +5161,6 @@ Released 2018-09-13
|
|||||||
[`while_immutable_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition
|
[`while_immutable_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition
|
||||||
[`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop
|
[`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop
|
||||||
[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
|
[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
|
||||||
[`while_pop_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_pop_unwrap
|
|
||||||
[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
|
[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
|
||||||
[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm
|
[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm
|
||||||
[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
|
[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
|
||||||
|
@ -249,6 +249,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
|
|||||||
crate::loops::MANUAL_FIND_INFO,
|
crate::loops::MANUAL_FIND_INFO,
|
||||||
crate::loops::MANUAL_FLATTEN_INFO,
|
crate::loops::MANUAL_FLATTEN_INFO,
|
||||||
crate::loops::MANUAL_MEMCPY_INFO,
|
crate::loops::MANUAL_MEMCPY_INFO,
|
||||||
|
crate::loops::MANUAL_WHILE_LET_SOME_INFO,
|
||||||
crate::loops::MISSING_SPIN_LOOP_INFO,
|
crate::loops::MISSING_SPIN_LOOP_INFO,
|
||||||
crate::loops::MUT_RANGE_BOUND_INFO,
|
crate::loops::MUT_RANGE_BOUND_INFO,
|
||||||
crate::loops::NEEDLESS_RANGE_LOOP_INFO,
|
crate::loops::NEEDLESS_RANGE_LOOP_INFO,
|
||||||
@ -258,7 +259,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
|
|||||||
crate::loops::WHILE_IMMUTABLE_CONDITION_INFO,
|
crate::loops::WHILE_IMMUTABLE_CONDITION_INFO,
|
||||||
crate::loops::WHILE_LET_LOOP_INFO,
|
crate::loops::WHILE_LET_LOOP_INFO,
|
||||||
crate::loops::WHILE_LET_ON_ITERATOR_INFO,
|
crate::loops::WHILE_LET_ON_ITERATOR_INFO,
|
||||||
crate::loops::WHILE_POP_UNWRAP_INFO,
|
|
||||||
crate::macro_use::MACRO_USE_IMPORTS_INFO,
|
crate::macro_use::MACRO_USE_IMPORTS_INFO,
|
||||||
crate::main_recursion::MAIN_RECURSION_INFO,
|
crate::main_recursion::MAIN_RECURSION_INFO,
|
||||||
crate::manual_assert::MANUAL_ASSERT_INFO,
|
crate::manual_assert::MANUAL_ASSERT_INFO,
|
||||||
|
@ -10,7 +10,7 @@ use rustc_lint::LateContext;
|
|||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use super::WHILE_POP_UNWRAP;
|
use super::MANUAL_WHILE_LET_SOME;
|
||||||
|
|
||||||
/// The kind of statement that the `pop()` call appeared in.
|
/// The kind of statement that the `pop()` call appeared in.
|
||||||
///
|
///
|
||||||
@ -31,7 +31,7 @@ enum PopStmt<'hir> {
|
|||||||
fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>, loop_span: Span, receiver_span: Span) {
|
fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>, loop_span: Span, receiver_span: Span) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
WHILE_POP_UNWRAP,
|
MANUAL_WHILE_LET_SOME,
|
||||||
pop_span,
|
pop_span,
|
||||||
"you seem to be trying to pop elements from a `Vec` in a loop",
|
"you seem to be trying to pop elements from a `Vec` in a loop",
|
||||||
|diag| {
|
|diag| {
|
@ -7,6 +7,7 @@ mod iter_next_loop;
|
|||||||
mod manual_find;
|
mod manual_find;
|
||||||
mod manual_flatten;
|
mod manual_flatten;
|
||||||
mod manual_memcpy;
|
mod manual_memcpy;
|
||||||
|
mod manual_while_let_some;
|
||||||
mod missing_spin_loop;
|
mod missing_spin_loop;
|
||||||
mod mut_range_bound;
|
mod mut_range_bound;
|
||||||
mod needless_range_loop;
|
mod needless_range_loop;
|
||||||
@ -17,7 +18,6 @@ mod utils;
|
|||||||
mod while_immutable_condition;
|
mod while_immutable_condition;
|
||||||
mod while_let_loop;
|
mod while_let_loop;
|
||||||
mod while_let_on_iterator;
|
mod while_let_on_iterator;
|
||||||
mod while_pop_unwrap;
|
|
||||||
|
|
||||||
use clippy_utils::higher;
|
use clippy_utils::higher;
|
||||||
use rustc_hir::{Expr, ExprKind, LoopSource, Pat};
|
use rustc_hir::{Expr, ExprKind, LoopSource, Pat};
|
||||||
@ -582,7 +582,7 @@ declare_clippy_lint! {
|
|||||||
/// in the body as a separate operation.
|
/// in the body as a separate operation.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
/// Such loops can be written in a more idiomatic way by using a while..let loop and directly
|
/// Such loops can be written in a more idiomatic way by using a while-let loop and directly
|
||||||
/// pattern matching on the return value of `Vec::pop()`.
|
/// pattern matching on the return value of `Vec::pop()`.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
@ -601,7 +601,7 @@ declare_clippy_lint! {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[clippy::version = "1.70.0"]
|
#[clippy::version = "1.70.0"]
|
||||||
pub WHILE_POP_UNWRAP,
|
pub MANUAL_WHILE_LET_SOME,
|
||||||
style,
|
style,
|
||||||
"checking for emptiness of a `Vec` in the loop condition and popping an element in the body"
|
"checking for emptiness of a `Vec` in the loop condition and popping an element in the body"
|
||||||
}
|
}
|
||||||
@ -625,7 +625,7 @@ declare_lint_pass!(Loops => [
|
|||||||
SINGLE_ELEMENT_LOOP,
|
SINGLE_ELEMENT_LOOP,
|
||||||
MISSING_SPIN_LOOP,
|
MISSING_SPIN_LOOP,
|
||||||
MANUAL_FIND,
|
MANUAL_FIND,
|
||||||
WHILE_POP_UNWRAP
|
MANUAL_WHILE_LET_SOME
|
||||||
]);
|
]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for Loops {
|
impl<'tcx> LateLintPass<'tcx> for Loops {
|
||||||
@ -675,7 +675,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
|
|||||||
if let Some(higher::While { condition, body, span }) = higher::While::hir(expr) {
|
if let Some(higher::While { condition, body, span }) = higher::While::hir(expr) {
|
||||||
while_immutable_condition::check(cx, condition, body);
|
while_immutable_condition::check(cx, condition, body);
|
||||||
missing_spin_loop::check(cx, condition, body);
|
missing_spin_loop::check(cx, condition, body);
|
||||||
while_pop_unwrap::check(cx, condition, body, span);
|
manual_while_let_some::check(cx, condition, body, span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![warn(clippy::while_pop_unwrap)]
|
#![warn(clippy::manual_while_let_some)]
|
||||||
|
|
||||||
struct VecInStruct {
|
struct VecInStruct {
|
||||||
numbers: Vec<i32>,
|
numbers: Vec<i32>,
|
||||||
@ -73,7 +73,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Do not warn if the loop is in a macro.
|
// Do not warn if the loop comes from a macro.
|
||||||
generate_loop!();
|
generate_loop!();
|
||||||
|
|
||||||
// Try other kinds of patterns
|
// Try other kinds of patterns
|
@ -1,7 +1,7 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![warn(clippy::while_pop_unwrap)]
|
#![warn(clippy::manual_while_let_some)]
|
||||||
|
|
||||||
struct VecInStruct {
|
struct VecInStruct {
|
||||||
numbers: Vec<i32>,
|
numbers: Vec<i32>,
|
||||||
@ -73,7 +73,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Do not warn if the loop is in a macro.
|
// Do not warn if the loop comes from a macro.
|
||||||
generate_loop!();
|
generate_loop!();
|
||||||
|
|
||||||
// Try other kinds of patterns
|
// Try other kinds of patterns
|
@ -1,10 +1,10 @@
|
|||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:23:9
|
--> $DIR/manual_while_let_some.rs:23:9
|
||||||
|
|
|
|
||||||
LL | let number = numbers.pop().unwrap();
|
LL | let number = numbers.pop().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::while-pop-unwrap` implied by `-D warnings`
|
= note: `-D clippy::manual-while-let-some` implied by `-D warnings`
|
||||||
help: consider using a `while..let` loop
|
help: consider using a `while..let` loop
|
||||||
|
|
|
|
||||||
LL ~ while let Some(number) = numbers.pop() {
|
LL ~ while let Some(number) = numbers.pop() {
|
||||||
@ -12,7 +12,7 @@ LL ~
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:31:9
|
--> $DIR/manual_while_let_some.rs:31:9
|
||||||
|
|
|
|
||||||
LL | let number = val.numbers.pop().unwrap();
|
LL | let number = val.numbers.pop().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -24,7 +24,7 @@ LL ~
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:35:20
|
--> $DIR/manual_while_let_some.rs:35:20
|
||||||
|
|
|
|
||||||
LL | accept_i32(numbers.pop().unwrap());
|
LL | accept_i32(numbers.pop().unwrap());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -36,7 +36,7 @@ LL ~ accept_i32(element);
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:39:20
|
--> $DIR/manual_while_let_some.rs:39:20
|
||||||
|
|
|
|
||||||
LL | accept_i32(numbers.pop().expect(""));
|
LL | accept_i32(numbers.pop().expect(""));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -48,7 +48,7 @@ LL ~ accept_i32(element);
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:82:9
|
--> $DIR/manual_while_let_some.rs:82:9
|
||||||
|
|
|
|
||||||
LL | let (a, b) = numbers.pop().unwrap();
|
LL | let (a, b) = numbers.pop().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -60,7 +60,7 @@ LL ~
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:86:26
|
--> $DIR/manual_while_let_some.rs:86:26
|
||||||
|
|
|
|
||||||
LL | accept_i32_tuple(numbers.pop().unwrap());
|
LL | accept_i32_tuple(numbers.pop().unwrap());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -72,7 +72,7 @@ LL ~ accept_i32_tuple(element);
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: you seem to be trying to pop elements from a `Vec` in a loop
|
error: you seem to be trying to pop elements from a `Vec` in a loop
|
||||||
--> $DIR/while_pop_unwrap.rs:91:9
|
--> $DIR/manual_while_let_some.rs:91:9
|
||||||
|
|
|
|
||||||
LL | let Foo { a, b } = results.pop().unwrap();
|
LL | let Foo { a, b } = results.pop().unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
Loading…
x
Reference in New Issue
Block a user