Skip to content

Commit

Permalink
Consider raw pointers fields as normalizable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samueltardieu committed Dec 15, 2024
1 parent 42a0263 commit cbfa74b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions clippy_utils/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ fn is_normalizable_helper<'tcx>(
.iter()
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), cache))
}),
ty::RawPtr(..) => true,
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
is_normalizable_helper(cx, param_env, inner_ty, cache)
Expand Down
22 changes: 19 additions & 3 deletions tests/ui/large_enum_variant.64bit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,30 @@ LL | / enum WithRecursion {
LL | | Large([u64; 64]),
| | ---------------- the largest variant contains at least 512 bytes
LL | | Recursive(Box<WithRecursion>),
| | ----------------------------- the second-largest variant contains at least 0 bytes
| | ----------------------------- the second-largest variant contains at least 8 bytes
LL | | }
| |_^ the entire enum is at least 0 bytes
| |_^ the entire enum is at least 520 bytes
|
help: consider boxing the large fields to reduce the total size of the enum
|
LL | Large(Box<[u64; 64]>),
| ~~~~~~~~~~~~~~

error: aborting due to 17 previous errors
error: large size difference between variants
--> tests/ui/large_enum_variant.rs:168:1
|
LL | / enum LargeEnumWithGenericsAndRecursive {
LL | | Ok(),
| | ---- the second-largest variant carries no data at all
LL | | Error(WithRecursionAndGenerics<u64>),
| | ------------------------------------ the largest variant contains at least 520 bytes
LL | | }
| |_^ the entire enum is at least 520 bytes
|
help: consider boxing the large fields to reduce the total size of the enum
|
LL | Error(Box<WithRecursionAndGenerics<u64>>),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to 18 previous errors

0 comments on commit cbfa74b

Please sign in to comment.