diff options
Diffstat (limited to 'src/tools/clippy/tests/ui/uninit_vec.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/uninit_vec.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/uninit_vec.rs b/src/tools/clippy/tests/ui/uninit_vec.rs index 194e4fc15..79effc82f 100644 --- a/src/tools/clippy/tests/ui/uninit_vec.rs +++ b/src/tools/clippy/tests/ui/uninit_vec.rs @@ -7,6 +7,11 @@ struct MyVec { vec: Vec<u8>, } +union MyOwnMaybeUninit { + value: u8, + uninit: (), +} + fn main() { // with_capacity() -> set_len() should be detected let mut vec: Vec<u8> = Vec::with_capacity(1000); @@ -97,4 +102,34 @@ fn main() { unsafe { vec.set_len(0); } + + // ZSTs should not be detected + let mut vec: Vec<()> = Vec::with_capacity(1000); + unsafe { + vec.set_len(10); + } + + // unions should not be detected + let mut vec: Vec<MyOwnMaybeUninit> = Vec::with_capacity(1000); + unsafe { + vec.set_len(10); + } + + polymorphic::<()>(); + + fn polymorphic<T>() { + // We are conservative around polymorphic types. + let mut vec: Vec<T> = Vec::with_capacity(1000); + unsafe { + vec.set_len(10); + } + } + + fn poly_maybe_uninit<T>() { + // We are conservative around polymorphic types. + let mut vec: Vec<MaybeUninit<T>> = Vec::with_capacity(1000); + unsafe { + vec.set_len(10); + } + } } |