Repository: tokio-rs/tokio
File: tokio/build.rs (Rust)

Code before:
"#;

const ADDR_OF_PROBE: &str = r#"
{
    let my_var = 10;
    ::std::ptr::addr_of!(my_var)
}
"#;

const CONST_MUTEX_NEW_PROBE: &str = r#"
{
    static MY_MUTEX: ::std::sync::Mutex<i32> = ::std::sync::Mutex::new(1);
    *MY_MUTEX.lock().unwrap()
}
"#;

const TARGET_HAS_ATOMIC_PROBE: &str = r#"
{
    #[cfg(target_has_atomic = "ptr")]
    let _ = (); 
}
"#;

const TARGET_ATOMIC_U64_PROBE: &str = r#"
{
    use core::sync::atomic::AtomicU64 as _;
}
"#;

fn main() {
    let mut enable_const_thread_local = false;
    let mut enable_addr_of = false;
    let mut enable_target_has_atomic = false;
    let mut enable_const_mutex_new = false;
    let mut target_has_atomic_u64 = true;

    match AutoCfg::new() {
        Ok(ac) => {
            // These checks prefer to call only `probe_rustc_version` if that is
            // enough to determine whether the feature is supported. This is
            // because the `probe_expression` call involves a call to rustc,
            // which the `probe_rustc_version` call avoids.

            // Const-initialized thread locals were stabilized in 1.59.
            if ac.probe_rustc_version(1, 60) {
                enable_const_thread_local = true;
            } else if ac.probe_rustc_version(1, 59) {
                // This compiler claims to be 1.59, but there are some nightly
                // compilers that claim to be 1.59 without supporting the
                // feature. Explicitly probe to check if code using them
                // compiles.

Review comment (bug):
autocfg's probe [compiles code with 2015 edition](https://github.com/cuviper/autocfg/blob/e75324cfa5fa0bec4f06f9609ab169bb7747f984/src/lib.rs#L205-L237), so there are places where `core::` works and places where it does not.

And probably this `core::` is not working: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=03a97e54f0ff94e4814206a4c3e62f86

Code after:
"#;

const ADDR_OF_PROBE: &str = r#"
{
    let my_var = 10;
    ::std::ptr::addr_of!(my_var)
}
"#;

const CONST_MUTEX_NEW_PROBE: &str = r#"
{
    static MY_MUTEX: ::std::sync::Mutex<i32> = ::std::sync::Mutex::new(1);
    *MY_MUTEX.lock().unwrap()
}
"#;

const TARGET_HAS_ATOMIC_PROBE: &str = r#"
{
    #[cfg(target_has_atomic = "ptr")]
    let _ = (); 
}
"#;

const TARGET_ATOMIC_U64_PROBE: &str = r#"
{
    use std::sync::atomic::AtomicU64 as _;
}
"#;

fn main() {
    let mut enable_const_thread_local = false;
    let mut enable_addr_of = false;
    let mut enable_target_has_atomic = false;
    let mut enable_const_mutex_new = false;
    let mut target_needs_atomic_u64_fallback = false;

    match AutoCfg::new() {
        Ok(ac) => {
            // These checks prefer to call only `probe_rustc_version` if that is
            // enough to determine whether the feature is supported. This is
            // because the `probe_expression` call involves a call to rustc,
            // which the `probe_rustc_version` call avoids.

            // Const-initialized thread locals were stabilized in 1.59.
            if ac.probe_rustc_version(1, 60) {
                enable_const_thread_local = true;
            } else if ac.probe_rustc_version(1, 59) {
                // This compiler claims to be 1.59, but there are some nightly
                // compilers that claim to be 1.59 without supporting the
                // feature. Explicitly probe to check if code using them
                // compiles.