mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
fix false negatives introduced in the rustup
This commit is contained in:
parent
7fbc7c0bb2
commit
d198b99472
2 changed files with 14 additions and 0 deletions
|
@ -949,6 +949,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
|
|||
fn may_slice(cx: &LateContext, ty: ty::Ty) -> bool {
|
||||
match ty.sty {
|
||||
ty::TySlice(_) => true,
|
||||
ty::TyAdt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
|
||||
ty::TyAdt(..) => match_type(cx, ty, &paths::VEC),
|
||||
ty::TyArray(_, size) => size < 32,
|
||||
ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => may_slice(cx, inner),
|
||||
|
@ -965,6 +966,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
|
|||
} else {
|
||||
match ty.sty {
|
||||
ty::TySlice(_) => sugg::Sugg::hir_opt(cx, expr),
|
||||
ty::TyAdt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => sugg::Sugg::hir_opt(cx, expr),
|
||||
ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) => {
|
||||
if may_slice(cx, inner) {
|
||||
sugg::Sugg::hir_opt(cx, expr)
|
||||
|
|
|
@ -350,6 +350,7 @@ fn or_fun_call() {
|
|||
/// Checks implementation of `ITER_NTH` lint
|
||||
fn iter_nth() {
|
||||
let mut some_vec = vec![0, 1, 2, 3];
|
||||
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
|
||||
let mut some_vec_deque: VecDeque<_> = some_vec.iter().cloned().collect();
|
||||
|
||||
{
|
||||
|
@ -358,6 +359,8 @@ fn iter_nth() {
|
|||
//~^ERROR called `.iter().nth()` on a Vec. Calling `.get()` is both faster and more readable
|
||||
let bad_slice = &some_vec[..].iter().nth(3);
|
||||
//~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
|
||||
let bad_boxed_slice = boxed_slice.iter().nth(3);
|
||||
//~^ERROR called `.iter().nth()` on a slice. Calling `.get()` is both faster and more readable
|
||||
let bad_vec_deque = some_vec_deque.iter().nth(3);
|
||||
//~^ERROR called `.iter().nth()` on a VecDeque. Calling `.get()` is both faster and more readable
|
||||
}
|
||||
|
@ -414,6 +417,7 @@ impl GetFalsePositive {
|
|||
|
||||
/// Checks implementation of `GET_UNWRAP` lint
|
||||
fn get_unwrap() {
|
||||
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
|
||||
let mut some_slice = &mut [0, 1, 2, 3];
|
||||
let mut some_vec = vec![0, 1, 2, 3];
|
||||
let mut some_vecdeque: VecDeque<_> = some_vec.iter().cloned().collect();
|
||||
|
@ -422,6 +426,10 @@ fn get_unwrap() {
|
|||
let mut false_positive = GetFalsePositive { arr: [0, 1, 2] };
|
||||
|
||||
{ // Test `get().unwrap()`
|
||||
let _ = boxed_slice.get(1).unwrap();
|
||||
//~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
|
||||
//~|HELP try this
|
||||
//~|SUGGESTION boxed_slice[1]
|
||||
let _ = some_slice.get(0).unwrap();
|
||||
//~^ERROR called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
|
||||
//~|HELP try this
|
||||
|
@ -447,6 +455,10 @@ fn get_unwrap() {
|
|||
}
|
||||
|
||||
{ // Test `get_mut().unwrap()`
|
||||
*boxed_slice.get_mut(0).unwrap() = 1;
|
||||
//~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
|
||||
//~|HELP try this
|
||||
//~|SUGGESTION &mut boxed_slice[0]
|
||||
*some_slice.get_mut(0).unwrap() = 1;
|
||||
//~^ERROR called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and more concise
|
||||
//~|HELP try this
|
||||
|
|
Loading…
Reference in a new issue