File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ fn main() {
23
23
let nightly_feature_enabled = is_var_set ( "CARGO_FEATURE_NIGHTLY" ) ;
24
24
let spin_feature_enabled = is_var_set ( "CARGO_FEATURE_SPIN_NO_STD" ) ;
25
25
26
- let version_geq_127 = version ( ) . unwrap ( ) >= Version :: new ( 1 , 27 , 0 ) ;
27
- let unreachable_hint_supported = version_geq_127 || nightly_feature_enabled;
26
+ let version_geq_122 = version ( ) . unwrap ( ) >= Version :: new ( 1 , 22 , 0 ) ;
27
+ let drop_in_static_supported = version_geq_122 || nightly_feature_enabled;
28
28
29
29
// precedence:
30
30
// 1. explicit requests via cfg or spin_no_std feature
@@ -36,11 +36,17 @@ fn main() {
36
36
"inline"
37
37
} else if force_spin_cfg || spin_feature_enabled {
38
38
"spin"
39
- } else if unreachable_hint_supported {
39
+ } else if drop_in_static_supported {
40
40
"inline"
41
41
} else {
42
42
"heap"
43
43
} ;
44
44
45
45
println ! ( "cargo:rustc-cfg=lazy_static_{}_impl" , impl_name) ;
46
+
47
+ let version_geq_127 = version ( ) . unwrap ( ) >= Version :: new ( 1 , 27 , 0 ) ;
48
+ let core_unreachable_unchecked_supported = version_geq_127 || nightly_feature_enabled;
49
+ if core_unreachable_unchecked_supported {
50
+ println ! ( "cargo:rustc-cfg=lazy_static_core_unreachable_unchecked" ) ;
51
+ }
46
52
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ impl<T: Sync> Lazy<T> {
31
31
unsafe {
32
32
match self . 0 {
33
33
Some ( ref x) => x,
34
- None => core :: hint :: unreachable_unchecked ( ) ,
34
+ None => unreachable_unchecked ( ) ,
35
35
}
36
36
}
37
37
}
@@ -46,3 +46,15 @@ macro_rules! __lazy_static_create {
46
46
static mut $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: INIT ;
47
47
} ;
48
48
}
49
+
50
+ #[ cfg( lazy_static_core_unreachable_unchecked) ]
51
+ use core:: hint:: unreachable_unchecked;
52
+
53
+ #[ cfg( not( lazy_static_core_unreachable_unchecked) ) ]
54
+ /// Polyfill for core::hint::unreachable_unchecked. Included to support Rust prior to 1.27. See
55
+ /// [issue #102](https://github.com/rust-lang-nursery/lazy-static.rs/issues/102#issuecomment-400959779)
56
+ /// for details.
57
+ unsafe fn unreachable_unchecked ( ) -> ! {
58
+ enum Void { }
59
+ match std:: mem:: uninitialized :: < Void > ( ) { }
60
+ }
You can’t perform that action at this time.
0 commit comments