Skip to content

Commit 83e0039

Browse files
committed
Swapped plain with so help function is visually attached to method
1 parent 64aae82 commit 83e0039

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

clippy_lints/src/methods/chunks_exact_with_const_size.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(super) fn check(
4040
let mut applicability = Applicability::MachineApplicable;
4141
let arg_str = snippet_with_applicability(cx, arg.span, "_", &mut applicability);
4242

43-
let as_chunks = format!("{suggestion_method}::<{arg_str}>()");
43+
let as_chunks = format_args!("{suggestion_method}::<{arg_str}>()");
4444

4545
span_lint_and_then(
4646
cx,
@@ -49,7 +49,7 @@ pub(super) fn check(
4949
format!("using `{method_name}` with a constant chunk size"),
5050
|diag| {
5151
if let Node::LetStmt(let_stmt) = cx.tcx.parent_hir_node(expr.hir_id) {
52-
diag.help(format!("consider using `{as_chunks}` instead"));
52+
diag.span_help(call_span, format!("consider using `{as_chunks}` instead"));
5353

5454
// Try to extract the variable name to provide a more helpful note
5555
if let PatKind::Binding(_, _, ident, _) = let_stmt.pat.kind {

tests/ui/chunks_exact_with_const_size.stderr

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ error: using `chunks_exact` with a constant chunk size
44
LL | let result = slice.chunks_exact(4);
55
| ^^^^^^^^^^^^^^^
66
|
7-
= help: consider using `as_chunks::<4>()` instead
7+
help: consider using `as_chunks::<4>()` instead
8+
--> tests/ui/chunks_exact_with_const_size.rs:9:24
9+
|
10+
LL | let result = slice.chunks_exact(4);
11+
| ^^^^^^^^^^^^^^^
812
= note: you can access the chunks using `result.0.iter()`, and the remainder using `result.1`
913
= note: `-D clippy::chunks-exact-with-const-size` implied by `-D warnings`
1014
= help: to override `-D warnings` add `#[allow(clippy::chunks_exact_with_const_size)]`
@@ -15,7 +19,11 @@ error: using `chunks_exact` with a constant chunk size
1519
LL | let result = slice.chunks_exact(CHUNK_SIZE);
1620
| ^^^^^^^^^^^^^^^^^^^^^^^^
1721
|
18-
= help: consider using `as_chunks::<CHUNK_SIZE>()` instead
22+
help: consider using `as_chunks::<CHUNK_SIZE>()` instead
23+
--> tests/ui/chunks_exact_with_const_size.rs:14:24
24+
|
25+
LL | let result = slice.chunks_exact(CHUNK_SIZE);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^
1927
= note: you can access the chunks using `result.0.iter()`, and the remainder using `result.1`
2028

2129
error: using `chunks_exact` with a constant chunk size
@@ -24,7 +32,11 @@ error: using `chunks_exact` with a constant chunk size
2432
LL | let result = slice.chunks_exact(3);
2533
| ^^^^^^^^^^^^^^^
2634
|
27-
= help: consider using `as_chunks::<3>()` instead
35+
help: consider using `as_chunks::<3>()` instead
36+
--> tests/ui/chunks_exact_with_const_size.rs:23:24
37+
|
38+
LL | let result = slice.chunks_exact(3);
39+
| ^^^^^^^^^^^^^^^
2840
= note: you can access the chunks using `result.0.iter()`, and the remainder using `result.1`
2941

3042
error: using `chunks_exact_mut` with a constant chunk size
@@ -33,7 +45,11 @@ error: using `chunks_exact_mut` with a constant chunk size
3345
LL | let result = arr.chunks_exact_mut(4);
3446
| ^^^^^^^^^^^^^^^^^^^
3547
|
36-
= help: consider using `as_chunks_mut::<4>()` instead
48+
help: consider using `as_chunks_mut::<4>()` instead
49+
--> tests/ui/chunks_exact_with_const_size.rs:28:22
50+
|
51+
LL | let result = arr.chunks_exact_mut(4);
52+
| ^^^^^^^^^^^^^^^^^^^
3753
= note: you can access the chunks using `result.0.iter()`, and the remainder using `result.1`
3854

3955
error: using `chunks_exact` with a constant chunk size
@@ -42,7 +58,11 @@ error: using `chunks_exact` with a constant chunk size
4258
LL | .chunks_exact(2);
4359
| ^^^^^^^^^^^^^^^
4460
|
45-
= help: consider using `as_chunks::<2>()` instead
61+
help: consider using `as_chunks::<2>()` instead
62+
--> tests/ui/chunks_exact_with_const_size.rs:37:10
63+
|
64+
LL | .chunks_exact(2);
65+
| ^^^^^^^^^^^^^^^
4666
= note: you can access the chunks using `result.0.iter()`, and the remainder using `result.1`
4767

4868
error: aborting due to 5 previous errors

tests/ui/chunks_exact_with_const_size_unfixable.stderr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ error: using `chunks_exact` with a constant chunk size
44
LL | let mut chunk_iter = slice.chunks_exact(CHUNK_SIZE);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: consider using `as_chunks::<CHUNK_SIZE>()` instead
7+
help: consider using `as_chunks::<CHUNK_SIZE>()` instead
8+
--> tests/ui/chunks_exact_with_const_size_unfixable.rs:9:32
9+
|
10+
LL | let mut chunk_iter = slice.chunks_exact(CHUNK_SIZE);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
812
= note: you can access the chunks using `chunk_iter.0.iter()`, and the remainder using `chunk_iter.1`
913
= note: `-D clippy::chunks-exact-with-const-size` implied by `-D warnings`
1014
= help: to override `-D warnings` add `#[allow(clippy::chunks_exact_with_const_size)]`
@@ -15,7 +19,11 @@ error: using `chunks_exact_mut` with a constant chunk size
1519
LL | let mut chunk_iter = arr2.chunks_exact_mut(CHUNK_SIZE);
1620
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1721
|
18-
= help: consider using `as_chunks_mut::<CHUNK_SIZE>()` instead
22+
help: consider using `as_chunks_mut::<CHUNK_SIZE>()` instead
23+
--> tests/ui/chunks_exact_with_const_size_unfixable.rs:16:31
24+
|
25+
LL | let mut chunk_iter = arr2.chunks_exact_mut(CHUNK_SIZE);
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1927
= note: you can access the chunks using `chunk_iter.0.iter()`, and the remainder using `chunk_iter.1`
2028

2129
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)