-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clippy doesn't generate large_enum_variant
warning when using bytes::Bytes
#11915
Comments
@rustbot claim |
It seems that |
pub struct Bytes {
ptr: *const u8,
len: usize,
// inlined "trait object"
data: AtomicPtr<()>,
vtable: &'static Vtable,
}
pub(crate) struct Vtable {
/// fn(data, ptr, len)
pub clone: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> Bytes,
/// fn(data, ptr, len)
///
/// takes `Bytes` to value
pub to_vec: unsafe fn(&AtomicPtr<()>, *const u8, usize) -> Vec<u8>,
/// fn(data, ptr, len)
pub drop: unsafe fn(&mut AtomicPtr<()>, *const u8, usize),
} Seems that the |
I'm unsure since I'm not familiar with |
I add a simple match arm rust-clippy/clippy_utils/src/ty.rs Line 391 in a859e5c
Generally I believe I need some help :) |
@anall @flip1995 It seems that you contribute a lot at this function. It'll be a great help if you can give some suggestion. Thanks! The function is introduced 3 years ago with a FIXME.
Is the function still needed? |
I don't really contribute there. My only contributions are syncs between the rust and Clippy repo. Fastest way to get help here is to post on Zulip about this. |
Remove `is_normalizable` fixes #11915 fixes #9798 Fixes only the first ICE in #10508 `is_normalizable` is used in a few places to avoid an ICE due to a delayed bug in normalization which occurs when a projection type is used on a type which doesn't implement the correct trait. The only part of clippy that actually needed this check is `zero_sized_map_values` due to a quirk of how type aliases work (they don't a real `ParamEnv`). This fixes the need for the check there by manually walking the type to determine if it's zero sized, rather than attempting to compute the type's layout thereby avoid the normalization that triggers the delayed bug. For an example of the issue with type aliases: ```rust trait Foo { type Foo; } struct Bar<T: Foo>(T::Foo); // The `ParamEnv` here just has `T: Sized`, not `T: Sized + Foo`. type Baz<T> = &'static Bar<T>; ``` When trying to compute the layout of `&'static Bar<T>` we need to determine if what type `<Bar<T> as Pointee>::Metadata` is. Doing this requires knowing if `T::Foo: Sized`, but since `T` doesn't have an associated type `Foo` in the context of the type alias a delayed bug is issued. changelog: [`large_enum_variant`]: correctly get the size of `bytes::Bytes`.
+1 here. I start getting weird false-positive with this lint, when I replaced some Also interesting that clippy completely ignores middle-size variant and even biggest-size variant. It warns me about variant containing Simplified example of my code and the warning I get: enum MyEnum {
Smallest(...), // the second-largest variant contains at least 96 bytes
NotSoSmall(...),
JustOk(...),
ContainsBytes(..., Vec<bytes::Bytes>), // the largest variant contains at least 440 bytes
Biggest(...),
}
// ^ the entire enum is at least 0 bytes |
Summary
If we are using
Vec
, clippy generates warning for large size difference in enum variants as expected, but if we replaceVec
withbytes::Bytes
, clippy doesn't generate any warning! Even when the size difference of enum variants is much bigger in later case!Lint Name
large_enum_variant
Reproducer
I tried this code:
I expected to see this happen:
clippy should have generated
large_enum_variant
warning for both enumsNoWarnings
( usesBytes
) &MakesClippyAngry
( usesVec
).Instead, this happened:
Clippy generates warning only for
MakesClippyAngry
, but doesn't forNoWarnings
.Version
The text was updated successfully, but these errors were encountered: