Skip to content

Commit 14335ec

Browse files
committed
Remove broken const_type_id feature
The `const_type_id` feature was planned to stabilize in Rust 1.47, but this was reverted in: rust-lang/rust#77083 This causes errors when building `log` with the `kv_unstable` feature on Rust 1.47 or later. This patch removes the use of this no-longer-stable feature in those Rust versions.
1 parent 9a1902d commit 14335ec

File tree

2 files changed

+3
-119
lines changed

2 files changed

+3
-119
lines changed

build.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22
//! atomics and sets `cfg` flags accordingly.
33
44
use std::env;
5-
use std::process::Command;
6-
use std::str::{self, FromStr};
5+
use std::str;
76

87
#[cfg(feature = "kv_unstable")]
98
#[path = "src/kv/value/internal/cast/primitive.rs"]
109
mod primitive;
1110

1211
fn main() {
13-
let minor = match rustc_minor_version() {
14-
Some(minor) => minor,
15-
None => return,
16-
};
17-
1812
let target = match rustc_target() {
1913
Some(target) => target,
2014
None => return,
@@ -28,11 +22,6 @@ fn main() {
2822
println!("cargo:rustc-cfg=has_atomics");
2923
}
3024

31-
// If the Rust version is at least 1.46.0 then we can use type ids at compile time
32-
if minor >= 47 {
33-
println!("cargo:rustc-cfg=const_type_id");
34-
}
35-
3625
// Generate sorted type id lookup
3726
#[cfg(feature = "kv_unstable")]
3827
primitive::generate();
@@ -61,33 +50,3 @@ fn target_has_atomics(target: &str) -> bool {
6150
fn rustc_target() -> Option<String> {
6251
env::var("TARGET").ok()
6352
}
64-
65-
// From the `serde` build script
66-
fn rustc_minor_version() -> Option<u32> {
67-
let rustc = match env::var_os("RUSTC") {
68-
Some(rustc) => rustc,
69-
None => return None,
70-
};
71-
72-
let output = match Command::new(rustc).arg("--version").output() {
73-
Ok(output) => output,
74-
Err(_) => return None,
75-
};
76-
77-
let version = match str::from_utf8(&output.stdout) {
78-
Ok(version) => version,
79-
Err(_) => return None,
80-
};
81-
82-
let mut pieces = version.split('.');
83-
if pieces.next() != Some("rustc 1") {
84-
return None;
85-
}
86-
87-
let next = match pieces.next() {
88-
Some(next) => next,
89-
None => return None,
90-
};
91-
92-
u32::from_str(next).ok()
93-
}

src/kv/value/internal/cast/primitive.rs

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,83 +13,8 @@ In the future when `min_specialization` is stabilized we could use it instead an
1313
the `'static` bound altogether.
1414
*/
1515

16-
// Use consts to match a type with a conversion fn
17-
#[cfg(all(srcbuild, const_type_id))]
18-
pub(super) fn from_any<'v, T: ?Sized + 'static>(
19-
value: &'v T,
20-
) -> Option<crate::kv::value::internal::Primitive<'v>> {
21-
use std::any::TypeId;
22-
23-
use crate::kv::value::internal::Primitive;
24-
25-
macro_rules! to_primitive {
26-
($($ty:ty : ($const_ident:ident, $option_ident:ident),)*) => {
27-
trait ToPrimitive
28-
where
29-
Self: 'static,
30-
{
31-
const CALL: fn(&Self) -> Option<Primitive> = {
32-
$(
33-
const $const_ident: TypeId = TypeId::of::<$ty>();
34-
const $option_ident: TypeId = TypeId::of::<Option<$ty>>();
35-
);*
36-
37-
match TypeId::of::<Self>() {
38-
$(
39-
$const_ident => |v| Some(Primitive::from(unsafe { *(v as *const Self as *const $ty) })),
40-
$option_ident => |v| Some({
41-
let v = unsafe { *(v as *const Self as *const Option<$ty>) };
42-
match v {
43-
Some(v) => Primitive::from(v),
44-
None => Primitive::None,
45-
}
46-
}),
47-
)*
48-
49-
_ => |_| None,
50-
}
51-
};
52-
53-
fn to_primitive(&self) -> Option<Primitive> {
54-
(Self::CALL)(self)
55-
}
56-
}
57-
58-
impl<T: ?Sized + 'static> ToPrimitive for T {}
59-
}
60-
}
61-
62-
// NOTE: The types here *must* match the ones used below when `const_type_id` is not available
63-
to_primitive![
64-
usize: (USIZE, OPTION_USIZE),
65-
u8: (U8, OPTION_U8),
66-
u16: (U16, OPTION_U16),
67-
u32: (U32, OPTION_U32),
68-
u64: (U64, OPTION_U64),
69-
70-
isize: (ISIZE, OPTION_ISIZE),
71-
i8: (I8, OPTION_I8),
72-
i16: (I16, OPTION_I16),
73-
i32: (I32, OPTION_I32),
74-
i64: (I64, OPTION_I64),
75-
76-
f32: (F32, OPTION_F32),
77-
f64: (F64, OPTION_F64),
78-
79-
char: (CHAR, OPTION_CHAR),
80-
bool: (BOOL, OPTION_BOOL),
81-
&'static str: (STR, OPTION_STR),
82-
];
83-
84-
value.to_primitive()
85-
}
86-
87-
#[cfg(all(not(src_build), const_type_id))]
88-
#[allow(dead_code)]
89-
pub fn generate() {}
90-
9116
// Use a build-time generated set of type ids to match a type with a conversion fn
92-
#[cfg(all(srcbuild, not(const_type_id)))]
17+
#[cfg(srcbuild)]
9318
pub(super) fn from_any<'v>(
9419
value: &'v (dyn std::any::Any + 'static),
9520
) -> Option<crate::kv::value::internal::Primitive<'v>> {
@@ -107,7 +32,7 @@ pub(super) fn from_any<'v>(
10732
}
10833

10934
// When the `src_build` config is not set then we're in the build script
110-
#[cfg(all(not(srcbuild), not(const_type_id)))]
35+
#[cfg(not(srcbuild))]
11136
#[allow(dead_code)]
11237
pub fn generate() {
11338
use std::path::Path;

0 commit comments

Comments
 (0)