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