Skip to content

compile error[E0310]: the parameter type S/K may not live long enough #200

@gigaimage

Description

@gigaimage

zeromq is one of the dependencies in cargo install deno
It fails with the following errors

 Compiling zeromq v0.4.0
error[E0310]: the parameter type `S` may not live long enough
   --> /Users/gigaimage/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zeromq-0.4.0/src/fair_queue.rs:120:29
    |
120 |             let waker_ref = waker_ref(&waker);
    |                             ^^^^^^^^^^^^^^^^^
    |                             |
    |                             the parameter type `S` must be valid for the static lifetime...
    |                             ...so that the type `S` will meet its required lifetime bounds
    |
help: consider adding an explicit lifetime bound
    |
89  |     S: Stream<Item = T> + Send + 'static,
    |                                +++++++++

error[E0310]: the parameter type `K` may not live long enough
   --> /Users/gigaimage/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zeromq-0.4.0/src/fair_queue.rs:120:29
    |
120 |             let waker_ref = waker_ref(&waker);
    |                             ^^^^^^^^^^^^^^^^^
    |                             |
    |                             the parameter type `K` must be valid for the static lifetime...
    |                             ...so that the type `K` will meet its required lifetime bounds
    |
help: consider adding an explicit lifetime bound
    |
90  |     K: Eq + Hash + Unpin + Clone + Send + Sync + 'static,
    |                                                +++++++++

For more information about this error, try `rustc --explain E0310`.
error: could not compile `zeromq` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile `deno v2.0.2`, intermediate artifacts can be found at `/var/folders/_t/c8dp0d8s3p1_pm_m6dj3pr3w0000gn/T/cargo-installa251ik`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
 λ rustc --explain E0310
  A parameter type is missing a lifetime constraint or has a lifetime that does not live long enough.

  Erroneous code example:

  // This won't compile because T is not constrained to the static lifetime
  // the reference needs
  struct Foo<T> {
      foo: &'static T
  }

  Type parameters in type definitions have lifetimes associated with them that represent how long the data stored within them is guaranteed
  to live. This lifetime must be as long as the data needs to be alive, and missing the constraint that denotes this will cause this error.

  This will compile, because it has the constraint on the type parameter:

  struct Foo<T: 'static> {
      foo: &'static T
  }

Workaround as per deno gh: cargo install --locked deno

System config:
λ rustup show
Default host: x86_64-apple-darwin
rustup home: /Users/gigaimage/.rustup

nightly-x86_64-apple-darwin (default)
rustc 1.84.0-nightly (662180b34 2024-10-20)

λ cargo --version
cargo 1.84.0-nightly (cf53cc54b 2024-10-18)

MacOS : 12.7.6 Monterey

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions