Skip to content

Commit cbfa74b

Browse files
committed
Consider raw pointers fields as normalizable
This is only used to determine the layout, and the layout of a raw pointer is known, whatever the designated type is. As a side effect, this makes the layout of `Box<T>` known, even inside `T`, and enables recursive types.
1 parent 42a0263 commit cbfa74b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clippy_utils/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ fn is_normalizable_helper<'tcx>(
375375
.iter()
376376
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), cache))
377377
}),
378+
ty::RawPtr(..) => true,
378379
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
379380
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
380381
is_normalizable_helper(cx, param_env, inner_ty, cache)

tests/ui/large_enum_variant.64bit.stderr

+19-3
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,30 @@ LL | / enum WithRecursion {
283283
LL | | Large([u64; 64]),
284284
| | ---------------- the largest variant contains at least 512 bytes
285285
LL | | Recursive(Box<WithRecursion>),
286-
| | ----------------------------- the second-largest variant contains at least 0 bytes
286+
| | ----------------------------- the second-largest variant contains at least 8 bytes
287287
LL | | }
288-
| |_^ the entire enum is at least 0 bytes
288+
| |_^ the entire enum is at least 520 bytes
289289
|
290290
help: consider boxing the large fields to reduce the total size of the enum
291291
|
292292
LL | Large(Box<[u64; 64]>),
293293
| ~~~~~~~~~~~~~~
294294

295-
error: aborting due to 17 previous errors
295+
error: large size difference between variants
296+
--> tests/ui/large_enum_variant.rs:168:1
297+
|
298+
LL | / enum LargeEnumWithGenericsAndRecursive {
299+
LL | | Ok(),
300+
| | ---- the second-largest variant carries no data at all
301+
LL | | Error(WithRecursionAndGenerics<u64>),
302+
| | ------------------------------------ the largest variant contains at least 520 bytes
303+
LL | | }
304+
| |_^ the entire enum is at least 520 bytes
305+
|
306+
help: consider boxing the large fields to reduce the total size of the enum
307+
|
308+
LL | Error(Box<WithRecursionAndGenerics<u64>>),
309+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310+
311+
error: aborting due to 18 previous errors
296312

0 commit comments

Comments
 (0)