mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
chore: fix version detection for addr_of! (#4863)
This commit is contained in:
+29
-2
@@ -10,8 +10,16 @@ const CONST_THREAD_LOCAL_PROBE: &str = r#"
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
const ADDR_OF_PROBE: &str = r#"
|
||||||
|
{
|
||||||
|
let my_var = 10;
|
||||||
|
::std::ptr::addr_of!(my_var)
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut enable_const_thread_local = false;
|
let mut enable_const_thread_local = false;
|
||||||
|
let mut enable_addr_of = false;
|
||||||
|
|
||||||
match AutoCfg::new() {
|
match AutoCfg::new() {
|
||||||
Ok(ac) => {
|
Ok(ac) => {
|
||||||
@@ -35,8 +43,19 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ac.probe_rustc_version(1, 51) {
|
// The `addr_of` and `addr_of_mut` macros were stabilized in 1.51.
|
||||||
autocfg::emit("tokio_no_addr_of")
|
if ac.probe_rustc_version(1, 52) {
|
||||||
|
enable_addr_of = true;
|
||||||
|
} else if ac.probe_rustc_version(1, 51) {
|
||||||
|
// This compiler claims to be 1.51, but there are some nightly
|
||||||
|
// compilers that claim to be 1.51 without supporting the
|
||||||
|
// feature. Explicitly probe to check if code using them
|
||||||
|
// compiles.
|
||||||
|
//
|
||||||
|
// The oldest nightly that supports the feature is 2021-01-31.
|
||||||
|
if ac.probe_expression(ADDR_OF_PROBE) {
|
||||||
|
enable_addr_of = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,4 +77,12 @@ fn main() {
|
|||||||
// RUSTFLAGS="--cfg tokio_no_const_thread_local"
|
// RUSTFLAGS="--cfg tokio_no_const_thread_local"
|
||||||
autocfg::emit("tokio_no_const_thread_local")
|
autocfg::emit("tokio_no_const_thread_local")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !enable_addr_of {
|
||||||
|
// To disable this feature on compilers that support it, you can
|
||||||
|
// explicitly pass this flag with the following environment variable:
|
||||||
|
//
|
||||||
|
// RUSTFLAGS="--cfg tokio_no_addr_of"
|
||||||
|
autocfg::emit("tokio_no_addr_of")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user