File tree Expand file tree Collapse file tree 7 files changed +74
-13
lines changed Expand file tree Collapse file tree 7 files changed +74
-13
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ matrix:
14
14
- rust : stable
15
15
env :
16
16
- FEATURES='array-sizes-33-128 array-sizes-129-255'
17
+ - ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
17
18
- rust : beta
18
19
- rust : nightly
19
20
env :
@@ -29,6 +30,7 @@ matrix:
29
30
- rust : nightly
30
31
env :
31
32
- FEATURES='array-sizes-33-128 array-sizes-129-255'
33
+ - ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
32
34
branches :
33
35
only :
34
36
- master
Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " arrayvec"
3
- version = " 0.4.10 "
3
+ version = " 0.4.11 "
4
4
authors = [" bluss" ]
5
5
license = " MIT/Apache-2.0"
6
6
Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ __ https://docs.rs/arrayvec
22
22
Recent Changes (arrayvec)
23
23
-------------------------
24
24
25
+ - 0.4.11
26
+
27
+ - In Rust 1.36 or later, use newly stable MaybeUninit. This extends the
28
+ soundness work introduced in 0.4.9, we are finally able to use this in
29
+ stable. We use feature detection (build script) to enable this at build
30
+ time.
31
+
25
32
- 0.4.10
26
33
27
34
- Use ``repr(C) `` in the ``union `` version that was introduced in 0.4.9, to
Original file line number Diff line number Diff line change @@ -11,17 +11,28 @@ fn main() {
11
11
}
12
12
13
13
fn detect_maybe_uninit ( ) {
14
+ let has_stable_maybe_uninit = probe ( & stable_maybe_uninit ( ) ) ;
15
+ if has_stable_maybe_uninit {
16
+ println ! ( "cargo:rustc-cfg=has_stable_maybe_uninit" ) ;
17
+ return ;
18
+ }
14
19
let has_unstable_union_with_md = probe ( & maybe_uninit_code ( true ) ) ;
15
20
if has_unstable_union_with_md {
16
21
println ! ( "cargo:rustc-cfg=has_manually_drop_in_union" ) ;
17
22
println ! ( "cargo:rustc-cfg=has_union_feature" ) ;
18
- return ;
19
23
}
24
+ }
20
25
21
- let has_stable_union_with_md = probe ( & maybe_uninit_code ( false ) ) ;
22
- if has_stable_union_with_md {
23
- println ! ( "cargo:rustc-cfg=has_manually_drop_in_union" ) ;
24
- }
26
+ // To guard against changes in this currently unstable feature, use
27
+ // a detection tests instead of a Rustc version and/or date test.
28
+ fn stable_maybe_uninit ( ) -> String {
29
+ let code = "
30
+ #![allow(warnings)]
31
+ use std::mem::MaybeUninit;
32
+
33
+ fn main() { }
34
+ " ;
35
+ code. to_string ( )
25
36
}
26
37
27
38
// To guard against changes in this currently unstable feature, use
Original file line number Diff line number Diff line change @@ -50,9 +50,12 @@ use std::fmt;
50
50
use std:: io;
51
51
52
52
53
- #[ cfg( has_manually_drop_in_union) ]
53
+ #[ cfg( has_stable_maybe_uninit) ]
54
+ #[ path="maybe_uninit_stable.rs" ]
54
55
mod maybe_uninit;
55
- #[ cfg( not( has_manually_drop_in_union) ) ]
56
+ #[ cfg( all( not( has_stable_maybe_uninit) , has_manually_drop_in_union) ) ]
57
+ mod maybe_uninit;
58
+ #[ cfg( all( not( has_stable_maybe_uninit) , not( has_manually_drop_in_union) ) ) ]
56
59
#[ path="maybe_uninit_nodrop.rs" ]
57
60
mod maybe_uninit;
58
61
Original file line number Diff line number Diff line change
1
+
2
+
3
+ use array:: Array ;
4
+ use std:: mem:: MaybeUninit as StdMaybeUninit ;
5
+
6
+ pub struct MaybeUninit < T > {
7
+ inner : StdMaybeUninit < T > ,
8
+ }
9
+
10
+ impl < T > MaybeUninit < T > {
11
+ /// Create a new MaybeUninit with uninitialized interior
12
+ pub unsafe fn uninitialized ( ) -> Self {
13
+ MaybeUninit { inner : StdMaybeUninit :: uninit ( ) }
14
+ }
15
+
16
+ /// Create a new MaybeUninit from the value `v`.
17
+ pub fn from ( v : T ) -> Self {
18
+ MaybeUninit { inner : StdMaybeUninit :: new ( v) }
19
+ }
20
+
21
+ // Raw pointer casts written so that we don't reference or access the
22
+ // uninitialized interior value
23
+
24
+ /// Return a raw pointer to the start of the interior array
25
+ pub fn ptr ( & self ) -> * const T :: Item
26
+ where T : Array
27
+ {
28
+ // std MaybeUninit creates a &self.value reference here which is
29
+ // not guaranteed to be sound in our case - we will partially
30
+ // initialize the value, not always wholly.
31
+ self . inner . as_ptr ( ) as * const T :: Item
32
+ }
33
+
34
+ /// Return a mut raw pointer to the start of the interior array
35
+ pub fn ptr_mut ( & mut self ) -> * mut T :: Item
36
+ where T : Array
37
+ {
38
+ self . inner . as_mut_ptr ( ) as * mut T :: Item
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -635,10 +635,8 @@ fn test_sizes_129_255() {
635
635
636
636
637
637
#[ test]
638
- fn test_nightly_uses_maybe_uninit ( ) {
639
- if option_env ! ( "ARRAYVECTEST_ENSURE_UNION" ) . map ( |s| !s. is_empty ( ) ) . unwrap_or ( false ) {
640
- assert ! ( cfg!( has_manually_drop_in_union) ) ;
641
- type ByteArray = ArrayVec < [ u8 ; 4 ] > ;
642
- assert ! ( mem:: size_of:: <ByteArray >( ) == 5 ) ;
638
+ fn test_newish_stable_uses_maybe_uninit ( ) {
639
+ if option_env ! ( "ARRAYVECTEST_ENSURE_MAYBEUNINIT" ) . map ( |s| !s. is_empty ( ) ) . unwrap_or ( false ) {
640
+ assert ! ( cfg!( has_stable_maybe_uninit) ) ;
643
641
}
644
642
}
You can’t perform that action at this time.
0 commit comments