Skip to content

Commit 4c6a3f4

Browse files
committed
pass the right ParamEnv to might_permit_raw_init_strict
1 parent 5ef38a3 commit 4c6a3f4

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

tests/ui/uninit_vec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![warn(clippy::uninit_vec)]
22

33
use std::mem::MaybeUninit;
4+
use std::cell::UnsafeCell;
45

56
#[derive(Default)]
67
struct MyVec {
@@ -12,6 +13,12 @@ union MyOwnMaybeUninit {
1213
uninit: (),
1314
}
1415

16+
// https://github.com/rust-lang/rust/issues/119620
17+
unsafe fn requires_paramenv<S>() {
18+
let mut vec = Vec::<UnsafeCell<*mut S>>::with_capacity(1);
19+
vec.set_len(1);
20+
}
21+
1522
fn main() {
1623
// with_capacity() -> set_len() should be detected
1724
let mut vec: Vec<u8> = Vec::with_capacity(1000);

tests/ui/uninit_vec.stderr

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
2-
--> tests/ui/uninit_vec.rs:17:5
2+
--> tests/ui/uninit_vec.rs:18:5
3+
|
4+
LL | let mut vec = Vec::<UnsafeCell<*mut S>>::with_capacity(1);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL | vec.set_len(1);
7+
| ^^^^^^^^^^^^^^
8+
|
9+
= help: initialize the buffer or wrap the content in `MaybeUninit`
10+
= note: `-D clippy::uninit-vec` implied by `-D warnings`
11+
= help: to override `-D warnings` add `#[allow(clippy::uninit_vec)]`
12+
13+
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
14+
--> tests/ui/uninit_vec.rs:24:5
315
|
416
LL | let mut vec: Vec<u8> = Vec::with_capacity(1000);
517
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,11 +20,9 @@ LL | vec.set_len(200);
820
| ^^^^^^^^^^^^^^^^
921
|
1022
= help: initialize the buffer or wrap the content in `MaybeUninit`
11-
= note: `-D clippy::uninit-vec` implied by `-D warnings`
12-
= help: to override `-D warnings` add `#[allow(clippy::uninit_vec)]`
1323

1424
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
15-
--> tests/ui/uninit_vec.rs:24:5
25+
--> tests/ui/uninit_vec.rs:31:5
1626
|
1727
LL | vec.reserve(1000);
1828
| ^^^^^^^^^^^^^^^^^^
@@ -23,7 +33,7 @@ LL | vec.set_len(200);
2333
= help: initialize the buffer or wrap the content in `MaybeUninit`
2434

2535
error: calling `set_len()` on empty `Vec` creates out-of-bound values
26-
--> tests/ui/uninit_vec.rs:31:5
36+
--> tests/ui/uninit_vec.rs:38:5
2737
|
2838
LL | let mut vec: Vec<u8> = Vec::new();
2939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +42,7 @@ LL | vec.set_len(200);
3242
| ^^^^^^^^^^^^^^^^
3343

3444
error: calling `set_len()` on empty `Vec` creates out-of-bound values
35-
--> tests/ui/uninit_vec.rs:38:5
45+
--> tests/ui/uninit_vec.rs:45:5
3646
|
3747
LL | let mut vec: Vec<u8> = Default::default();
3848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -41,7 +51,7 @@ LL | vec.set_len(200);
4151
| ^^^^^^^^^^^^^^^^
4252

4353
error: calling `set_len()` on empty `Vec` creates out-of-bound values
44-
--> tests/ui/uninit_vec.rs:44:5
54+
--> tests/ui/uninit_vec.rs:51:5
4555
|
4656
LL | let mut vec: Vec<u8> = Vec::default();
4757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,7 +60,7 @@ LL | vec.set_len(200);
5060
| ^^^^^^^^^^^^^^^^
5161

5262
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
53-
--> tests/ui/uninit_vec.rs:61:5
63+
--> tests/ui/uninit_vec.rs:68:5
5464
|
5565
LL | let mut vec: Vec<u8> = Vec::with_capacity(1000);
5666
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -61,7 +71,7 @@ LL | vec.set_len(200);
6171
= help: initialize the buffer or wrap the content in `MaybeUninit`
6272

6373
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
64-
--> tests/ui/uninit_vec.rs:71:5
74+
--> tests/ui/uninit_vec.rs:78:5
6575
|
6676
LL | my_vec.vec.reserve(1000);
6777
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +82,7 @@ LL | my_vec.vec.set_len(200);
7282
= help: initialize the buffer or wrap the content in `MaybeUninit`
7383

7484
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
75-
--> tests/ui/uninit_vec.rs:77:5
85+
--> tests/ui/uninit_vec.rs:84:5
7686
|
7787
LL | my_vec.vec = Vec::with_capacity(1000);
7888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -83,7 +93,7 @@ LL | my_vec.vec.set_len(200);
8393
= help: initialize the buffer or wrap the content in `MaybeUninit`
8494

8595
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
86-
--> tests/ui/uninit_vec.rs:52:9
96+
--> tests/ui/uninit_vec.rs:59:9
8797
|
8898
LL | let mut vec: Vec<u8> = Vec::with_capacity(1000);
8999
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -94,7 +104,7 @@ LL | vec.set_len(200);
94104
= help: initialize the buffer or wrap the content in `MaybeUninit`
95105

96106
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
97-
--> tests/ui/uninit_vec.rs:56:9
107+
--> tests/ui/uninit_vec.rs:63:9
98108
|
99109
LL | vec.reserve(1000);
100110
| ^^^^^^^^^^^^^^^^^^
@@ -105,7 +115,7 @@ LL | vec.set_len(200);
105115
= help: initialize the buffer or wrap the content in `MaybeUninit`
106116

107117
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
108-
--> tests/ui/uninit_vec.rs:132:9
118+
--> tests/ui/uninit_vec.rs:139:9
109119
|
110120
LL | let mut vec: Vec<T> = Vec::with_capacity(1000);
111121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -115,5 +125,5 @@ LL | vec.set_len(10);
115125
|
116126
= help: initialize the buffer or wrap the content in `MaybeUninit`
117127

118-
error: aborting due to 11 previous errors
128+
error: aborting due to 12 previous errors
119129

0 commit comments

Comments
 (0)