The items imported in `cfg-if` in the standard cannot be traced its definition

For example:

cfg_if::cfg_if! {
    if #[cfg(test)] {
        // Avoid duplicating the global state associated with thread-locals between this crate and
        // realstd. Miri relies on this.
        pub use realstd::thread::{local_impl, AccessError, LocalKey};
    } else {
        #[stable(feature = "rust1", since = "1.0.0")]
        pub use self::local::{AccessError, LocalKey};

        // Implementation details used by the thread_local!{} macro.
        #[doc(hidden)]
        #[unstable(feature = "thread_local_internals", issue = "none")]
        pub mod local_impl {
            pub use crate::sys::thread_local::{thread_local_inner, Key, abort_on_dtor_unwind};
        }
    }
}

I cannot trace the definition of thread_local_inner, even though I has added cfg-if = "1.0.0" in the dependencies.

How must I trace the definition of the items introduced in cfg-if?

this is due to lack of the cargo lock file from the standard library. a possible workaround is use the rust-analyzer setting: rust-analyzer.cargo.sysrootQueryMetadata": true, but this requires the directory containing the source code of the standard library being writable, which shouldn't be a problem if you install rust toolchain using rustup (to the default location of $HOME/.rustup, that is)

see also:

So, this issue cannot be solved without giving root privilege as far as now?

sorry, my wording is not clear. it does NOT need write access to the operating system's root tree,but the path given by rustc --print sysroot. specfically, the directory to the source code of the standard library crates, as it needs to create cargo lock file so it can analyze the source code.

I used curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh on Getting started - Rust Programming Language to install the rust, everything is the default. Did you mean I need to do is set rust-analyzer.cargo.sysrootQueryMetadata": true?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.