Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 75140e8

Browse files
committed
Fix a style of texts in size_of_in_element_count
1 parent 13c1a01 commit 75140e8

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

clippy_lints/src/size_of_in_element_count.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
1111

1212
declare_clippy_lint! {
1313
/// **What it does:** Detects expressions where
14-
/// size_of::<T> or size_of_val::<T> is used as a
15-
/// count of elements of type T
14+
/// `size_of::<T>` or `size_of_val::<T>` is used as a
15+
/// count of elements of type `T`
1616
///
1717
/// **Why is this bad?** These functions expect a count
18-
/// of T and not a number of bytes
18+
/// of `T` and not a number of bytes
1919
///
2020
/// **Known problems:** None.
2121
///
2222
/// **Example:**
2323
/// ```rust,no_run
2424
/// # use std::ptr::copy_nonoverlapping;
2525
/// # use std::mem::size_of;
26-
///
2726
/// const SIZE: usize = 128;
2827
/// let x = [2u8; SIZE];
2928
/// let mut y = [2u8; SIZE];
3029
/// unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
3130
/// ```
3231
pub SIZE_OF_IN_ELEMENT_COUNT,
3332
correctness,
34-
"using size_of::<T> or size_of_val::<T> where a count of elements of T is expected"
33+
"using `size_of::<T>` or `size_of_val::<T>` where a count of elements of `T` is expected"
3534
}
3635

3736
declare_lint_pass!(SizeOfInElementCount => [SIZE_OF_IN_ELEMENT_COUNT]);
@@ -120,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount {
120119
, it already gets multiplied by the size of the type";
121120

122121
const LINT_MSG: &str = "found a count of bytes \
123-
instead of a count of elements of T";
122+
instead of a count of elements of `T`";
124123

125124
if_chain! {
126125
// Find calls to functions with an element count parameter and get

tests/ui/size_of_in_element_count.stderr

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: found a count of bytes instead of a count of elements of T
1+
error: found a count of bytes instead of a count of elements of `T`
22
--> $DIR/size_of_in_element_count.rs:18:68
33
|
44
LL | unsafe { copy_nonoverlapping::<u8>(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
@@ -7,183 +7,183 @@ LL | unsafe { copy_nonoverlapping::<u8>(x.as_ptr(), y.as_mut_ptr(), size_of:
77
= note: `-D clippy::size-of-in-element-count` implied by `-D warnings`
88
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
99

10-
error: found a count of bytes instead of a count of elements of T
10+
error: found a count of bytes instead of a count of elements of `T`
1111
--> $DIR/size_of_in_element_count.rs:19:62
1212
|
1313
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
1414
| ^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
1717

18-
error: found a count of bytes instead of a count of elements of T
18+
error: found a count of bytes instead of a count of elements of `T`
1919
--> $DIR/size_of_in_element_count.rs:21:49
2020
|
2121
LL | unsafe { x.as_ptr().copy_to(y.as_mut_ptr(), size_of::<u8>()) };
2222
| ^^^^^^^^^^^^^^^
2323
|
2424
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
2525

26-
error: found a count of bytes instead of a count of elements of T
26+
error: found a count of bytes instead of a count of elements of `T`
2727
--> $DIR/size_of_in_element_count.rs:22:64
2828
|
2929
LL | unsafe { x.as_ptr().copy_to_nonoverlapping(y.as_mut_ptr(), size_of::<u8>()) };
3030
| ^^^^^^^^^^^^^^^
3131
|
3232
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
3333

34-
error: found a count of bytes instead of a count of elements of T
34+
error: found a count of bytes instead of a count of elements of `T`
3535
--> $DIR/size_of_in_element_count.rs:23:51
3636
|
3737
LL | unsafe { y.as_mut_ptr().copy_from(x.as_ptr(), size_of::<u8>()) };
3838
| ^^^^^^^^^^^^^^^
3939
|
4040
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
4141

42-
error: found a count of bytes instead of a count of elements of T
42+
error: found a count of bytes instead of a count of elements of `T`
4343
--> $DIR/size_of_in_element_count.rs:24:66
4444
|
4545
LL | unsafe { y.as_mut_ptr().copy_from_nonoverlapping(x.as_ptr(), size_of::<u8>()) };
4646
| ^^^^^^^^^^^^^^^
4747
|
4848
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
4949

50-
error: found a count of bytes instead of a count of elements of T
50+
error: found a count of bytes instead of a count of elements of `T`
5151
--> $DIR/size_of_in_element_count.rs:26:47
5252
|
5353
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
5454
| ^^^^^^^^^^^^^^^
5555
|
5656
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
5757

58-
error: found a count of bytes instead of a count of elements of T
58+
error: found a count of bytes instead of a count of elements of `T`
5959
--> $DIR/size_of_in_element_count.rs:27:47
6060
|
6161
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), size_of_val(&x[0])) };
6262
| ^^^^^^^^^^^^^^^^^^
6363
|
6464
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
6565

66-
error: found a count of bytes instead of a count of elements of T
66+
error: found a count of bytes instead of a count of elements of `T`
6767
--> $DIR/size_of_in_element_count.rs:29:46
6868
|
6969
LL | unsafe { y.as_mut_ptr().write_bytes(0u8, size_of::<u8>() * SIZE) };
7070
| ^^^^^^^^^^^^^^^^^^^^^^
7171
|
7272
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
7373

74-
error: found a count of bytes instead of a count of elements of T
74+
error: found a count of bytes instead of a count of elements of `T`
7575
--> $DIR/size_of_in_element_count.rs:30:47
7676
|
7777
LL | unsafe { write_bytes(y.as_mut_ptr(), 0u8, size_of::<u8>() * SIZE) };
7878
| ^^^^^^^^^^^^^^^^^^^^^^
7979
|
8080
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
8181

82-
error: found a count of bytes instead of a count of elements of T
82+
error: found a count of bytes instead of a count of elements of `T`
8383
--> $DIR/size_of_in_element_count.rs:32:66
8484
|
8585
LL | unsafe { swap_nonoverlapping(y.as_mut_ptr(), x.as_mut_ptr(), size_of::<u8>() * SIZE) };
8686
| ^^^^^^^^^^^^^^^^^^^^^^
8787
|
8888
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
8989

90-
error: found a count of bytes instead of a count of elements of T
90+
error: found a count of bytes instead of a count of elements of `T`
9191
--> $DIR/size_of_in_element_count.rs:34:46
9292
|
9393
LL | slice_from_raw_parts_mut(y.as_mut_ptr(), size_of::<u8>() * SIZE);
9494
| ^^^^^^^^^^^^^^^^^^^^^^
9595
|
9696
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
9797

98-
error: found a count of bytes instead of a count of elements of T
98+
error: found a count of bytes instead of a count of elements of `T`
9999
--> $DIR/size_of_in_element_count.rs:35:38
100100
|
101101
LL | slice_from_raw_parts(y.as_ptr(), size_of::<u8>() * SIZE);
102102
| ^^^^^^^^^^^^^^^^^^^^^^
103103
|
104104
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
105105

106-
error: found a count of bytes instead of a count of elements of T
106+
error: found a count of bytes instead of a count of elements of `T`
107107
--> $DIR/size_of_in_element_count.rs:37:49
108108
|
109109
LL | unsafe { from_raw_parts_mut(y.as_mut_ptr(), size_of::<u8>() * SIZE) };
110110
| ^^^^^^^^^^^^^^^^^^^^^^
111111
|
112112
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
113113

114-
error: found a count of bytes instead of a count of elements of T
114+
error: found a count of bytes instead of a count of elements of `T`
115115
--> $DIR/size_of_in_element_count.rs:38:41
116116
|
117117
LL | unsafe { from_raw_parts(y.as_ptr(), size_of::<u8>() * SIZE) };
118118
| ^^^^^^^^^^^^^^^^^^^^^^
119119
|
120120
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
121121

122-
error: found a count of bytes instead of a count of elements of T
122+
error: found a count of bytes instead of a count of elements of `T`
123123
--> $DIR/size_of_in_element_count.rs:40:33
124124
|
125125
LL | unsafe { y.as_mut_ptr().sub(size_of::<u8>()) };
126126
| ^^^^^^^^^^^^^^^
127127
|
128128
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
129129

130-
error: found a count of bytes instead of a count of elements of T
130+
error: found a count of bytes instead of a count of elements of `T`
131131
--> $DIR/size_of_in_element_count.rs:41:29
132132
|
133133
LL | y.as_ptr().wrapping_sub(size_of::<u8>());
134134
| ^^^^^^^^^^^^^^^
135135
|
136136
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
137137

138-
error: found a count of bytes instead of a count of elements of T
138+
error: found a count of bytes instead of a count of elements of `T`
139139
--> $DIR/size_of_in_element_count.rs:42:29
140140
|
141141
LL | unsafe { y.as_ptr().add(size_of::<u8>()) };
142142
| ^^^^^^^^^^^^^^^
143143
|
144144
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
145145

146-
error: found a count of bytes instead of a count of elements of T
146+
error: found a count of bytes instead of a count of elements of `T`
147147
--> $DIR/size_of_in_element_count.rs:43:33
148148
|
149149
LL | y.as_mut_ptr().wrapping_add(size_of::<u8>());
150150
| ^^^^^^^^^^^^^^^
151151
|
152152
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
153153

154-
error: found a count of bytes instead of a count of elements of T
154+
error: found a count of bytes instead of a count of elements of `T`
155155
--> $DIR/size_of_in_element_count.rs:44:32
156156
|
157157
LL | unsafe { y.as_ptr().offset(size_of::<u8>() as isize) };
158158
| ^^^^^^^^^^^^^^^^^^^^^^^^
159159
|
160160
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
161161

162-
error: found a count of bytes instead of a count of elements of T
162+
error: found a count of bytes instead of a count of elements of `T`
163163
--> $DIR/size_of_in_element_count.rs:45:36
164164
|
165165
LL | y.as_mut_ptr().wrapping_offset(size_of::<u8>() as isize);
166166
| ^^^^^^^^^^^^^^^^^^^^^^^^
167167
|
168168
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
169169

170-
error: found a count of bytes instead of a count of elements of T
170+
error: found a count of bytes instead of a count of elements of `T`
171171
--> $DIR/size_of_in_element_count.rs:48:62
172172
|
173173
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
174174
| ^^^^^^^^^^^^^^^^^^^^^^
175175
|
176176
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
177177

178-
error: found a count of bytes instead of a count of elements of T
178+
error: found a count of bytes instead of a count of elements of `T`
179179
--> $DIR/size_of_in_element_count.rs:51:62
180180
|
181181
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), HALF_SIZE * size_of_val(&x[0]) * 2) };
182182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
183183
|
184184
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
185185

186-
error: found a count of bytes instead of a count of elements of T
186+
error: found a count of bytes instead of a count of elements of `T`
187187
--> $DIR/size_of_in_element_count.rs:54:47
188188
|
189189
LL | unsafe { copy(x.as_ptr(), y.as_mut_ptr(), DOUBLE_SIZE * size_of::<u8>() / 2) };

0 commit comments

Comments
 (0)