Skip to content

Commit 8dd249e

Browse files
committed
hotfix: prevent linting raw int
1 parent cf0e405 commit 8dd249e

File tree

2 files changed

+9
-63
lines changed

2 files changed

+9
-63
lines changed

clippy_lints/src/unnecessary_reserve.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryReserve {
5252
return;
5353
}
5454

55-
if let ExprKind::MethodCall(PathSegment { ident: method, .. }, struct_calling_on, _, _) = expr.kind
55+
if let ExprKind::MethodCall(PathSegment { ident: method, .. }, struct_calling_on, args_a, _) = expr.kind
5656
&& method.name.as_str() == "reserve"
5757
&& acceptable_type(cx, struct_calling_on)
5858
&& let Some(block) = get_enclosing_block(cx, expr.hir_id)
59-
&& let Some(next_stmt_span) = check_extend_method(cx, block, struct_calling_on)
59+
&& let Some(next_stmt_span) = check_extend_method(cx, block, struct_calling_on, &args_a[0])
6060
&& !next_stmt_span.from_expansion()
6161
{
6262
span_lint_and_then(
@@ -95,13 +95,17 @@ fn check_extend_method(
9595
cx: &LateContext<'_>,
9696
block: &Block<'_>,
9797
struct_expr: &rustc_hir::Expr<'_>,
98+
args_a: &rustc_hir::Expr<'_>,
9899
) -> Option<rustc_span::Span> {
100+
let args_a_kind = &args_a.kind;
99101
let mut read_found = false;
100102
let mut spanless_eq = SpanlessEq::new(cx);
101103

102104
let _: Option<!> = for_each_expr(block, |expr| {
103105
if let ExprKind::MethodCall(_, struct_calling_on, _,_) = expr.kind
104106
&& let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
107+
&& let ExprKind::MethodCall(PathSegment { ident: method_call_a, .. },..) = args_a_kind
108+
&& method_call_a.name.as_str() == "len"
105109
&& match_def_path(cx, expr_def_id, &paths::ITER_EXTEND)
106110
&& acceptable_type(cx, struct_calling_on)
107111
// Check that both expr are equal

tests/ui/unnecessary_reserve.stderr

+3-61
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
error: unnecessary call to `reserve`
2-
--> $DIR/unnecessary_reserve.rs:14:18
3-
|
4-
LL | fn vec_reserve() {
5-
| __________________^
6-
LL | | let mut vec: Vec<usize> = vec![];
7-
LL | | let array: &[usize] = &[1, 2];
8-
LL | |
9-
LL | | // do not lint
10-
LL | | vec.reserve(1);
11-
| | -------------- help: remove this line
12-
... |
13-
LL | | vec.extend([1])
14-
LL | | }
15-
| |_^
16-
|
17-
= note: `-D clippy::unnecessary-reserve` implied by `-D warnings`
18-
191
error: unnecessary call to `reserve`
202
--> $DIR/unnecessary_reserve.rs:14:18
213
|
@@ -31,6 +13,8 @@ LL | | vec.reserve(array.len());
3113
LL | | vec.extend([1])
3214
LL | | }
3315
| |_^
16+
|
17+
= note: `-D clippy::unnecessary-reserve` implied by `-D warnings`
3418

3519
error: unnecessary call to `reserve`
3620
--> $DIR/unnecessary_reserve.rs:27:5
@@ -58,22 +42,6 @@ LL | | vec.extend([1])
5842
LL | | }
5943
| |_^
6044

61-
error: unnecessary call to `reserve`
62-
--> $DIR/unnecessary_reserve.rs:43:24
63-
|
64-
LL | fn vec_deque_reserve() {
65-
| ________________________^
66-
LL | | let mut vec_deque: VecDeque<usize> = [1].into();
67-
LL | | let array: &[usize] = &[1, 2];
68-
LL | |
69-
LL | | // do not lint
70-
LL | | vec_deque.reserve(1);
71-
| | -------------------- help: remove this line
72-
... |
73-
LL | | vec_deque.extend([1])
74-
LL | | }
75-
| |_^
76-
7745
error: unnecessary call to `reserve`
7846
--> $DIR/unnecessary_reserve.rs:43:24
7947
|
@@ -90,31 +58,5 @@ LL | | vec_deque.extend([1])
9058
LL | | }
9159
| |_^
9260

93-
error: unnecessary call to `reserve`
94-
--> $DIR/unnecessary_reserve.rs:56:5
95-
|
96-
LL | / {
97-
LL | | vec_deque.reserve(1);
98-
| | -------------------- help: remove this line
99-
LL | | vec_deque.extend([1])
100-
LL | | };
101-
| |_____^
102-
103-
error: unnecessary call to `reserve`
104-
--> $DIR/unnecessary_reserve.rs:43:24
105-
|
106-
LL | fn vec_deque_reserve() {
107-
| ________________________^
108-
LL | | let mut vec_deque: VecDeque<usize> = [1].into();
109-
LL | | let array: &[usize] = &[1, 2];
110-
LL | |
111-
... |
112-
LL | | vec_deque.reserve(array.len() + 1);
113-
| | ---------------------------------- help: remove this line
114-
... |
115-
LL | | vec_deque.extend([1])
116-
LL | | }
117-
| |_^
118-
119-
error: aborting due to 8 previous errors
61+
error: aborting due to 4 previous errors
12062

0 commit comments

Comments
 (0)