Skip to content

Commit aafe7aa

Browse files
committed
Get it to compile
1 parent d0bfaea commit aafe7aa

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

clippy_lints/src/use_last.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseLast {
8383

8484
// LHS of subtraction is "x.len()"
8585
if let ExprKind::MethodCall(ref arg_lhs_path, _, ref lhs_args) = lhs.node;
86-
// let _ = println!("LHS of sub is a method call");
86+
// let _ = println!("LHS of sub is a method call");
8787
if arg_lhs_path.ident.name == "len";
8888
// let _ = println!("LHS of sub was method named len");
8989
if let Some(arg_lhs_struct) = lhs_args.get(0);
9090
// let _ = println!("LHS of sub method has an arg");
9191

9292
// TODO: Is this a valid way to check if they reference the same vector?
93-
if let ExprKind::Path(arg_lhs_struct_path) = arg_lhs_struct.node;
94-
if let ExprKind::Path(struct_calling_on_path) = struct_calling_on.nod
95-
if arg_lhs_struct_path == struct_calling_on_path;
93+
// if let ExprKind::Path(arg_lhs_struct_path) = arg_lhs_struct.node;
94+
// if let ExprKind::Path(struct_calling_on_path) = struct_calling_on.nod
95+
// if arg_lhs_struct_path == struct_calling_on_path;
9696
// let _ = println!("The vector in .get and .len were the same");
9797

9898
// RHS of subtraction is 1
@@ -120,6 +120,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseLast {
120120
applicability,
121121
);
122122
}
123+
// then {
124+
// let _ = println!("got here");
125+
// }
123126
}
124127
}
125128
}

tests/ui/use_last.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ fn index_into_last() -> i32 {
1919
}
2020

2121
// False positive test (currently failing)
22-
// fn use_last_with_different_vec_length() -> Option<i32> {
23-
// let x = vec![2, 3, 5];
24-
// let y = vec!['a', 'b', 'c'];
25-
// let last_element = x.get(y.len() - 1);
26-
// last_element.map(|val| val + 1)
27-
// }
22+
fn use_last_with_different_vec_length() -> Option<i32> {
23+
let x = vec![2, 3, 5];
24+
let y = vec!['a', 'b', 'c'];
25+
let last_element = x.get(y.len() - 1);
26+
last_element.map(|val| val + 1)
27+
}
2828

2929
fn main() {
3030
let expected_value: i32 = 6;
3131
println!("Working...");
3232
assert_eq!(dont_use_last(), Some(expected_value));
3333
assert_eq!(indexing_two_from_end(), Some(expected_value));
3434
assert_eq!(index_into_last(), expected_value);
35-
// assert_eq!(use_last_with_different_vec_length(), Some(expected_value));
35+
assert_eq!(use_last_with_different_vec_length(), Some(expected_value));
3636
}

0 commit comments

Comments
 (0)