sfackler / rust-native-tls

Apache License 2.0
468 stars 197 forks source link

Fails to compile on MacOS #296

Closed Altanis closed 2 months ago

Altanis commented 2 months ago

When using libraries such as reqwest which rely on this πackage (as well as simply installing only native-tls), I get compile time errors as such:

error[E0195]: lifetime parameters or bounds on type `Target` do not match the trait declaration
  --> /Users/altanis/.cargo/registry/src/index.crates.io-6f17d22bba15001f/native-tls-0.2.11/src/imp/security_framework.rs:41:1
   |
41 | / lazy_static! {
42 | |     static ref TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, TempDir)>> = Mutex::new(None);
43 | | }
   | |_^ lifetimes do not match type in trait
   |
   = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `lock` found for struct `TEMP_KEYCHAIN` in the current scope
   --> /Users/altanis/.cargo/registry/src/index.crates.io-6f17d22bba15001f/native-tls-0.2.11/src/imp/security_framework.rs:162:45
    |
41  | / lazy_static! {
42  | |     static ref TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, TempDir)>> = Mutex::new(None);
43  | | }
    | |_- method `lock` not found for this struct
...
162 |           let keychain = match *TEMP_KEYCHAIN.lock().unwrap() {
    |                                               ^^^^ method not found in `TEMP_KEYCHAIN`

error[E0282]: type annotations needed
   --> /Users/altanis/.cargo/registry/src/index.crates.io-6f17d22bba15001f/native-tls-0.2.11/src/imp/security_framework.rs:163:49
    |
163 |             Some((ref keychain, _)) => keychain.clone(),
    |                                                 ^^^^^ cannot infer type

error[E0599]: no method named `lock` found for struct `TEMP_KEYCHAIN` in the current scope
   --> /Users/altanis/.cargo/registry/src/index.crates.io-6f17d22bba15001f/native-tls-0.2.11/src/imp/security_framework.rs:155:32
    |
41  | / lazy_static! {
42  | |     static ref TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, TempDir)>> = Mutex::new(None);
43  | | }
    | |_- method `lock` not found for this struct
...
155 |                   *TEMP_KEYCHAIN.lock().unwrap() = None;
    |                                  ^^^^ method not found in `TEMP_KEYCHAIN`

Some errors have detailed explanations: E0195, E0282, E0599.
For more information about an error, try `rustc --explain E0195`.
error: could not compile `native-tls` (lib) due to 4 previous errors

If it helps, I'm using MacOS Ventura 13.2.1 (on an M2 chip). My compiler is up to date.

sfackler commented 2 months ago

That seems like a problem in the lazy_static crate.

Altanis commented 2 months ago

I reinstalled Rust and this got fixed, so it's fine.