This commit is contained in:
Catherine 2023-06-24 09:40:58 -05:00
parent b1acbde618
commit 95b24d44a6
3 changed files with 12 additions and 23 deletions

View file

@ -5,6 +5,7 @@ use clippy_utils::{
path_to_local,
};
use itertools::Itertools;
use rustc_ast::LitKind;
use rustc_hir::{Expr, ExprKind, Node, Pat};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::{lint::in_external_macro, ty};
@ -82,8 +83,9 @@ fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
if let Some(elements) = elements
.iter()
.map(|expr| {
if let ExprKind::Field(path, _) = expr.kind {
.enumerate()
.map(|(i, expr)| {
if let ExprKind::Field(path, field) = expr.kind && field.as_str() == i.to_string() {
return Some(path);
};
@ -146,8 +148,13 @@ fn check_tuple<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
if let Some(elements) = elements
.iter()
.map(|expr| {
if let ExprKind::Index(path, _) = expr.kind {
.enumerate()
.map(|(i, expr)| {
if let ExprKind::Index(path, index) = expr.kind
&& let ExprKind::Lit(lit) = index.kind
&& let LitKind::Int(val, _) = lit.node
&& val as usize == i
{
return Some(path);
};

View file

@ -39,10 +39,8 @@ fn main() {
let y = (1, 2);
[x.0, y.0];
[x.0, y.1];
// FP
let x = [x.0, x.0];
let x = (x[0], x[0]);
// How can this be fixed?
external! {
let t1: &[(u32, u32)] = &[(1, 2), (3, 4)];
let v1: Vec<[u32; 2]> = t1.iter().map(|&(a, b)| [a, b]).collect();

View file

@ -55,22 +55,6 @@ LL | t1.iter().for_each(|&(a, b)| _ = [a, b]);
|
= help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
error: it looks like you're trying to convert a tuple to an array
--> $DIR/tuple_array_conversions.rs:43:13
|
LL | let x = [x.0, x.0];
| ^^^^^^^^^^
|
= help: use `.into()` instead, or `<[T; N]>::from` if type annotations are needed
error: it looks like you're trying to convert an array to a tuple
--> $DIR/tuple_array_conversions.rs:44:13
|
LL | let x = (x[0], x[0]);
| ^^^^^^^^^^^^
|
= help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
error: it looks like you're trying to convert an array to a tuple
--> $DIR/tuple_array_conversions.rs:71:13
|
@ -95,5 +79,5 @@ LL | let x = (x[0], x[1]);
|
= help: use `.into()` instead, or `<(T0, T1, ..., Tn)>::from` if type annotations are needed
error: aborting due to 12 previous errors
error: aborting due to 10 previous errors