summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/uninit_vec.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /src/tools/clippy/tests/ui/uninit_vec.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/uninit_vec.rs')
-rw-r--r--src/tools/clippy/tests/ui/uninit_vec.rs35
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);
+ }
+ }
}