Skip to content

Commit 0ef10a6

Browse files
committed
Fixed issue
Fixed issue by adding changing the help_text
1 parent ba947c5 commit 0ef10a6

File tree

5 files changed

+54
-23
lines changed

5 files changed

+54
-23
lines changed

clippy_lints/src/large_enum_variant.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint_and_then;
3+
use clippy_utils::is_no_std_crate;
34
use clippy_utils::source::snippet_with_applicability;
45
use clippy_utils::ty::{AdtVariantInfo, approx_ty_size, is_copy};
56
use rustc_errors::Applicability;
@@ -83,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
8384

8485
let mut difference = variants_size[0].size - variants_size[1].size;
8586
if difference > self.maximum_size_difference_allowed {
86-
let help_text = "consider boxing the large fields to reduce the total size of the enum";
87+
let help_text = "consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum";
8788
span_lint_and_then(
8889
cx,
8990
LARGE_ENUM_VARIANT,
@@ -117,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
117118
ident.span,
118119
"boxing a variant would require the type no longer be `Copy`",
119120
);
120-
} else {
121+
} else if !is_no_std_crate(cx) {
121122
let sugg: Vec<(Span, String)> = variants_size[0]
122123
.fields_size
123124
.iter()

tests/ui-toml/enum_variant_size/enum_variant_size.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | | }
1212
|
1313
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
1414
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
15-
help: consider boxing the large fields to reduce the total size of the enum
15+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
1616
|
1717
LL - B([u8; 501]),
1818
LL + B(Box<[u8; 501]>),

tests/ui/large_enum_variant.64bit.stderr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | | }
1212
|
1313
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
1414
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
15-
help: consider boxing the large fields to reduce the total size of the enum
15+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
1616
|
1717
LL - B([i32; 8000]),
1818
LL + B(Box<[i32; 8000]>),
@@ -30,7 +30,7 @@ LL | | ContainingLargeEnum(LargeEnum),
3030
LL | | }
3131
| |_^ the entire enum is at least 32004 bytes
3232
|
33-
help: consider boxing the large fields to reduce the total size of the enum
33+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
3434
|
3535
LL - ContainingLargeEnum(LargeEnum),
3636
LL + ContainingLargeEnum(Box<LargeEnum>),
@@ -49,7 +49,7 @@ LL | | StructLikeLittle { x: i32, y: i32 },
4949
LL | | }
5050
| |_^ the entire enum is at least 70008 bytes
5151
|
52-
help: consider boxing the large fields to reduce the total size of the enum
52+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
5353
|
5454
LL - ContainingMoreThanOneField(i32, [i32; 8000], [i32; 9500]),
5555
LL + ContainingMoreThanOneField(i32, Box<[i32; 8000]>, Box<[i32; 9500]>),
@@ -67,7 +67,7 @@ LL | | StructLikeLarge { x: [i32; 8000], y: i32 },
6767
LL | | }
6868
| |_^ the entire enum is at least 32008 bytes
6969
|
70-
help: consider boxing the large fields to reduce the total size of the enum
70+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
7171
|
7272
LL - StructLikeLarge { x: [i32; 8000], y: i32 },
7373
LL + StructLikeLarge { x: Box<[i32; 8000]>, y: i32 },
@@ -85,7 +85,7 @@ LL | | StructLikeLarge2 { x: [i32; 8000] },
8585
LL | | }
8686
| |_^ the entire enum is at least 32004 bytes
8787
|
88-
help: consider boxing the large fields to reduce the total size of the enum
88+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
8989
|
9090
LL - StructLikeLarge2 { x: [i32; 8000] },
9191
LL + StructLikeLarge2 { x: Box<[i32; 8000]> },
@@ -104,7 +104,7 @@ LL | | C([u8; 200]),
104104
LL | | }
105105
| |_^ the entire enum is at least 1256 bytes
106106
|
107-
help: consider boxing the large fields to reduce the total size of the enum
107+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
108108
|
109109
LL - B([u8; 1255]),
110110
LL + B(Box<[u8; 1255]>),
@@ -122,7 +122,7 @@ LL | | ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32;
122122
LL | | }
123123
| |_^ the entire enum is at least 70132 bytes
124124
|
125-
help: consider boxing the large fields to reduce the total size of the enum
125+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
126126
|
127127
LL - ContainingMoreThanOneField([i32; 8000], [i32; 2], [i32; 9500], [i32; 30]),
128128
LL + ContainingMoreThanOneField(Box<[i32; 8000]>, [i32; 2], Box<[i32; 9500]>, [i32; 30]),
@@ -140,7 +140,7 @@ LL | | B(Struct2),
140140
LL | | }
141141
| |_^ the entire enum is at least 32004 bytes
142142
|
143-
help: consider boxing the large fields to reduce the total size of the enum
143+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
144144
|
145145
LL - B(Struct2),
146146
LL + B(Box<Struct2>),
@@ -158,7 +158,7 @@ LL | | B(Struct2),
158158
LL | | }
159159
| |_^ the entire enum is at least 32000 bytes
160160
|
161-
help: consider boxing the large fields to reduce the total size of the enum
161+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
162162
|
163163
LL - B(Struct2),
164164
LL + B(Box<Struct2>),
@@ -176,7 +176,7 @@ LL | | B(Struct2),
176176
LL | | }
177177
| |_^ the entire enum is at least 32000 bytes
178178
|
179-
help: consider boxing the large fields to reduce the total size of the enum
179+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
180180
|
181181
LL - B(Struct2),
182182
LL + B(Box<Struct2>),
@@ -199,7 +199,7 @@ note: boxing a variant would require the type no longer be `Copy`
199199
|
200200
LL | enum CopyableLargeEnum {
201201
| ^^^^^^^^^^^^^^^^^
202-
help: consider boxing the large fields to reduce the total size of the enum
202+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
203203
--> tests/ui/large_enum_variant.rs:118:5
204204
|
205205
LL | B([u64; 8000]),
@@ -222,7 +222,7 @@ note: boxing a variant would require the type no longer be `Copy`
222222
|
223223
LL | enum ManuallyCopyLargeEnum {
224224
| ^^^^^^^^^^^^^^^^^^^^^
225-
help: consider boxing the large fields to reduce the total size of the enum
225+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
226226
--> tests/ui/large_enum_variant.rs:124:5
227227
|
228228
LL | B([u64; 8000]),
@@ -245,7 +245,7 @@ note: boxing a variant would require the type no longer be `Copy`
245245
|
246246
LL | enum SomeGenericPossiblyCopyEnum<T> {
247247
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
248-
help: consider boxing the large fields to reduce the total size of the enum
248+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
249249
--> tests/ui/large_enum_variant.rs:138:5
250250
|
251251
LL | B([u64; 4000]),
@@ -263,7 +263,7 @@ LL | | Large((T, [u8; 512])),
263263
LL | | }
264264
| |_^ the entire enum is at least 512 bytes
265265
|
266-
help: consider boxing the large fields to reduce the total size of the enum
266+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
267267
|
268268
LL - Large((T, [u8; 512])),
269269
LL + Large(Box<(T, [u8; 512])>),
@@ -281,7 +281,7 @@ LL | | Small(u8),
281281
LL | | }
282282
| |_^ the entire enum is at least 520 bytes
283283
|
284-
help: consider boxing the large fields to reduce the total size of the enum
284+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
285285
|
286286
LL - Large([Foo<u64>; 64]),
287287
LL + Large(Box<[Foo<u64>; 64]>),
@@ -299,7 +299,7 @@ LL | | Error(PossiblyLargeEnumWithConst<256>),
299299
LL | | }
300300
| |_^ the entire enum is at least 514 bytes
301301
|
302-
help: consider boxing the large fields to reduce the total size of the enum
302+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
303303
|
304304
LL - Error(PossiblyLargeEnumWithConst<256>),
305305
LL + Error(Box<PossiblyLargeEnumWithConst<256>>),
@@ -317,7 +317,7 @@ LL | | Recursive(Box<WithRecursion>),
317317
LL | | }
318318
| |_^ the entire enum is at least 520 bytes
319319
|
320-
help: consider boxing the large fields to reduce the total size of the enum
320+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
321321
|
322322
LL - Large([u64; 64]),
323323
LL + Large(Box<[u64; 64]>),
@@ -335,7 +335,7 @@ LL | | Error(WithRecursionAndGenerics<u64>),
335335
LL | | }
336336
| |_^ the entire enum is at least 520 bytes
337337
|
338-
help: consider boxing the large fields to reduce the total size of the enum
338+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
339339
|
340340
LL - Error(WithRecursionAndGenerics<u64>),
341341
LL + Error(Box<WithRecursionAndGenerics<u64>>),
@@ -353,7 +353,7 @@ LL | | _SmallBoi(u8),
353353
LL | | }
354354
| |_____^ the entire enum is at least 296 bytes
355355
|
356-
help: consider boxing the large fields to reduce the total size of the enum
356+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
357357
|
358358
LL - BigBoi(PublishWithBytes),
359359
LL + BigBoi(Box<PublishWithBytes>),
@@ -371,7 +371,7 @@ LL | | _SmallBoi(u8),
371371
LL | | }
372372
| |_____^ the entire enum is at least 224 bytes
373373
|
374-
help: consider boxing the large fields to reduce the total size of the enum
374+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
375375
|
376376
LL - BigBoi(PublishWithVec),
377377
LL + BigBoi(Box<PublishWithVec>),

tests/ui/large_enum_variant_no_std.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_std]
2+
#![warn(clippy::large_enum_variant)]
3+
4+
enum Myenum {
5+
//~^ ERROR: large size difference between variants
6+
Small(u8),
7+
Large([u8; 1024]),
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: large size difference between variants
2+
--> tests/ui/large_enum_variant_no_std.rs:4:1
3+
|
4+
LL | / enum Myenum {
5+
LL | |
6+
LL | | Small(u8),
7+
| | --------- the second-largest variant contains at least 1 bytes
8+
LL | | Large([u8; 1024]),
9+
| | ----------------- the largest variant contains at least 1024 bytes
10+
LL | | }
11+
| |_^ the entire enum is at least 1025 bytes
12+
|
13+
help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum
14+
--> tests/ui/large_enum_variant_no_std.rs:7:5
15+
|
16+
LL | Large([u8; 1024]),
17+
| ^^^^^^^^^^^^^^^^^
18+
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
19+
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
20+
21+
error: aborting due to 1 previous error
22+

0 commit comments

Comments
 (0)