Skip to content

Edition 2024 now reports: argument requires that '1 must outlive 'static #133529

Closed as not planned
@zh-jq-b

Description

@zh-jq-b

I'm trying to test edition 2024 here by using branch https://github.com/bytedance/g3/tree/edition-2024, now some of the code reports

argument requires that `'1` must outlive `'static`

The toolchain version is

cargo 1.85.0-nightly (4c39aaff6 2024-11-25)

Code

The code is here: https://github.com/bytedance/g3, branch edition-2024.

cargo +nightly build -p g3-ctl

will give error at line https://github.com/bytedance/g3/blob/40d1e2e5946e701deb0a26d2e8342120a2fb89f5/lib/g3-ctl/src/opts.rs#L92

   Compiling g3-ctl v0.1.0 (/code/rust/g3/lib/g3-ctl)
error[E0521]: borrowed data escapes outside of method
  --> lib/g3-ctl/src/opts.rs:92:22
   |
86 |         &self,
   |         -----
   |         |
   |         `self` is a reference that is only valid in the method body
   |         let's call the lifetime of this reference `'1`
87 |         daemon_name: &'static str,
   |         ----------- `daemon_name` declared here, outside of the method body
...
92 |         let stream = self.connect_to_daemon(daemon_name).await?;
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                      |
   |                      `self` escapes the method body here
   |                      argument requires that `'1` must outlive `'static`

For more information about this error, try `rustc --explain E0521`.
error: could not compile `g3-ctl` (lib) due to 1 previous error

And

cargo +nightly build -p g3-daemon

will give error at line https://github.com/bytedance/g3/blob/40d1e2e5946e701deb0a26d2e8342120a2fb89f5/lib/g3-daemon/src/control/local/mod.rs#L174

   Compiling g3-daemon v0.2.0 (/code/rust/g3/lib/g3-daemon)
error[E0521]: borrowed data escapes outside of associated function
   --> lib/g3-daemon/src/control/local/mod.rs:174:26
    |
168 |         daemon_name: &str,
    |         -----------  - let's call the lifetime of this reference `'1`
    |         |
    |         `daemon_name` is a reference that is only valid in the associated function body
...
174 |         let mut stream = LocalControllerImpl::connect_to_daemon(daemon_name, daemon_group).await?;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                          |
    |                          `daemon_name` escapes the associated function body here
    |                          argument requires that `'1` must outlive `'static`

error[E0521]: borrowed data escapes outside of associated function
   --> lib/g3-daemon/src/control/local/mod.rs:174:26
    |
169 |         daemon_group: &str,
    |         ------------  - let's call the lifetime of this reference `'2`
    |         |
    |         `daemon_group` is a reference that is only valid in the associated function body
...
174 |         let mut stream = LocalControllerImpl::connect_to_daemon(daemon_name, daemon_group).await?;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                          |
    |                          `daemon_group` escapes the associated function body here
    |                          argument requires that `'2` must outlive `'static`

For more information about this error, try `rustc --explain E0521`.
error: could not compile `g3-daemon` (lib) due to 2 previous errors

Version it worked on

Edition 2021

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-edition-2024Area: The 2024 editionA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions