@@ -55,58 +55,42 @@ impl LintPass for UseLast {
55
55
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UseLast {
56
56
fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
57
57
if_chain ! {
58
- // let _ = println!("Starting UseLast");
59
58
// Is a method call
60
59
if let ExprKind :: MethodCall ( ref path, _, ref args) = expr. node;
61
- // let _ = println!("It is a MethodCall");
62
60
63
61
// Method name is "get"
64
62
if path. ident. name == "get" ;
65
- // let _ = println!("The name is get");
66
63
67
64
// Argument 0 (the struct we're calling the method on) is a vector
68
65
if let Some ( struct_calling_on) = args. get( 0 ) ;
69
- // let _ = println!("It had an argument");
70
66
let struct_ty = cx. tables. expr_ty( struct_calling_on) ;
71
67
if match_type( cx, struct_ty, & paths:: VEC ) ;
72
- // let _ = println!("It was a vector");
73
68
74
69
// Argument to "get" is a binary operation
75
70
if let Some ( get_index_arg) = args. get( 1 ) ;
76
- // let _ = println!("It had an argument");
77
71
if let rustc:: hir:: ExprKind :: Binary ( ref op, ref lhs, ref rhs) = get_index_arg. node;
78
- // let _ = println!("It was a vector");
79
72
80
73
// Binary operation is a subtraction
81
74
if op. node == rustc:: hir:: BinOpKind :: Sub ;
82
- // let _ = println!("It was a subtraction");
83
75
84
76
// LHS of subtraction is "x.len()"
85
77
if let ExprKind :: MethodCall ( ref arg_lhs_path, _, ref lhs_args) = lhs. node;
86
- // let _ = println!("LHS of sub is a method call");
87
78
if arg_lhs_path. ident. name == "len" ;
88
- // let _ = println!("LHS of sub was method named len");
89
79
if let Some ( arg_lhs_struct) = lhs_args. get( 0 ) ;
90
- // let _ = println!("LHS of sub method has an arg");
91
80
92
81
// TODO: Is this a valid way to check if they reference the same vector?
93
82
if let ExprKind :: Path ( arg_lhs_struct_path) = arg_lhs_struct. node;
94
83
if let ExprKind :: Path ( struct_calling_on_path) = struct_calling_on. nod
95
84
if arg_lhs_struct_path == struct_calling_on_path;
96
- // let _ = println!("The vector in .get and .len were the same");
97
85
98
86
// RHS of subtraction is 1
99
87
if let ExprKind :: Lit ( ref rhs_lit) = rhs. node;
100
- // let _ = println!("RHS of sub was literal");
101
88
if let LitKind :: Int ( rhs_value, ..) = rhs_lit. node;
102
- // let _ = println!("RHS of sub was int");
103
89
if rhs_value == 1 ;
104
- // let _ = println!("RHS of sub was 1");
105
90
106
91
let mut applicability = Applicability :: MachineApplicable ;
107
92
let vec_name = snippet_with_applicability(
108
93
cx, struct_calling_on. span, "x" , & mut applicability) ;
109
- // let _ = println!("About to span_lint on \"{}\"", vec_name);
110
94
111
95
then {
112
96
span_lint_and_sugg(
0 commit comments