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() {
2323 let nightly_feature_enabled = is_var_set ( "CARGO_FEATURE_NIGHTLY" ) ;
2424 let spin_feature_enabled = is_var_set ( "CARGO_FEATURE_SPIN_NO_STD" ) ;
2525
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;
2828
2929 // precedence:
3030 // 1. explicit requests via cfg or spin_no_std feature
@@ -36,11 +36,17 @@ fn main() {
3636 "inline"
3737 } else if force_spin_cfg || spin_feature_enabled {
3838 "spin"
39- } else if unreachable_hint_supported {
39+ } else if drop_in_static_supported {
4040 "inline"
4141 } else {
4242 "heap"
4343 } ;
4444
4545 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+ }
4652}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ impl<T: Sync> Lazy<T> {
3131 unsafe {
3232 match self . 0 {
3333 Some ( ref x) => x,
34- None => core :: hint :: unreachable_unchecked ( ) ,
34+ None => unreachable_unchecked ( ) ,
3535 }
3636 }
3737 }
@@ -46,3 +46,15 @@ macro_rules! __lazy_static_create {
4646 static mut $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: INIT ;
4747 } ;
4848}
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