Skip to content

Borrow checker error on nightly even when the type is 'static #106332

Description

@NobodyXu

Compiling the binstalk from cargo-bins/cargo-binstall#646 failed on nightly due to lifetime error while it works on stable.

The code in question looks like this and is in taken from crates/binstalk/src/fetchers/gh_crate_meta.rs

pub struct GhCrateMeta {
    client: Client,
    data: Arc<Data>,
    target_data: Arc<TargetData>,
    resolution: OnceCell<(Url, PkgFmt)>,
}

type FindTaskRes = Result<Option<(Url, PkgFmt)>, BinstallError>;

impl GhCrateMeta {
    fn launch_baseline_find_tasks<'a>(
        &'a self,
        pkg_fmt: PkgFmt,
        pkg_url: &'a str,
        repo: Option<&'a str>,
    ) -> impl Iterator<Item = impl Future<Output = FindTaskRes> + 'static> + 'a {
        todo!()
    }

    fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>> {
        AutoAbortJoinHandle::spawn(async move {
            // ...
            let mut handles = FuturesUnordered::new();

            // Iterate over pkg_urls to avoid String::clone.
            for pkg_url in pkg_urls {
                //             Clone iter pkg_fmts to ensure all pkg_fmts is
                //             iterated over for each pkg_url, which is
                //             basically cartesian product.
                //             |
                for pkg_fmt in pkg_fmts.clone() {
                    handles.extend(this.launch_baseline_find_tasks(pkg_fmt, &pkg_url, repo));
                }
            }

            todo!()
        })
    }

On nightly, this failed with:

error[E0597]: `pkg_url` does not live long enough
   --> crates/binstalk/src/fetchers/gh_crate_meta.rs:147:77
    |
147 |                     handles.extend(this.launch_baseline_find_tasks(pkg_fmt, &pkg_url, repo));
    |                                                                             ^^^^^^^^ borrowed value 
does not live long enough
148 |                 }
149 |             }
    |             - `pkg_url` dropped here while still borrowed
...
160 |         })
    |         - borrow might be used here, when `handles` is dropped and runs the `Drop` code for type `Fu
turesUnordered`
    |
    = note: values in a scope are dropped in the opposite order they are defined

For more information about this error, try `rustc --explain E0597`.
error: could not compile `binstalk` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `binstalk` due to previous error

Meta

rustc +nightly --version --verbose:

rustc 1.68.0-nightly (ce85c9857 2022-12-30)
binary: rustc
commit-hash: ce85c98575e3016cf2007d90a85be321e592aa96
commit-date: 2022-12-30
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6

Activity

  1. clubby789 commented on Dec 31, 2022

    @clubby789
    Contributor

    @rustbot modify labels: +regression-from-stable-to-beta

  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 31, 2022
  3. albertlarsan68 commented on Dec 31, 2022

    @albertlarsan68
    Member

    @rustbot labels +E-needs-bisection

  4. added
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Dec 31, 2022
  5. clubby789 commented on Dec 31, 2022

    @clubby789
  6. lukas-code commented on Dec 31, 2022

    @lukas-code
    Contributor

    searched nightlies: from nightly-2022-12-09 to nightly-2022-12-27
    regressed nightly: nightly-2022-12-10
    searched commit range: 7632db0...dfe3fe7
    regressed commit: 7701a7e (#105456)

    bisected with cargo-bisect-rustc v0.6.4

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --regress=error -- check 

    Maybe its #105317?

  7. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Dec 31, 2022
  8. clubby789 commented on Dec 31, 2022

    @clubby789
  9. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Dec 31, 2022
  10. lqd commented on Dec 31, 2022

    @lqd
    Member

    You can manually bisect the PRs in that rollup, #105456 (comment) contains the list of each of their artifacts.

    I'd start by looking at #105255 though.

  11. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Dec 31, 2022
  12. lukas-code commented on Dec 31, 2022

    @lukas-code
    Contributor
  13. self-assigned this
    on Dec 31, 2022
  14. added this to the 1.67.0 milestone on Jan 1, 2023
  15. NobodyXu commented on Jan 5, 2023

    @NobodyXu
    ContributorAuthor

    Any update on this?

    I've tested the code on:

    rustc 1.68.0-nightly (659e169d3 2023-01-04)
    binary: rustc
    commit-hash: 659e169d37990b9c730a59a96081f2ef7afbe8f1
    commit-date: 2023-01-04
    host: aarch64-apple-darwin
    release: 1.68.0-nightly
    LLVM version: 15.0.6
    

    and it still failed.

  16. apiraino commented on Jan 6, 2023

    @apiraino
    Contributor

    @NobodyXu AFAICS your bug report has been acknowledged and has an assignee, looks like it's a regression in the beta channel (comment). The new stable will be out in a few weeks, might be fixed by then.

  17. NobodyXu commented on Jan 6, 2023

    @NobodyXu
    ContributorAuthor

    @NobodyXu AFAICS your bug report has been acknowledged and has an assignee, looks like it's a regression in the beta channel (comment). The new stable will be out in a few weeks, might be fixed by then.

    Thanks, so looks like it's going to take quite some time.
    I might go ahead and release cargo-binstall without waiting for this one.

  18. apiraino commented on Jan 10, 2023

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-high +T-compiler

  19. added
    P-highHigh priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 10, 2023
  20. added a commit that references this issue on Jan 12, 2023
    bbb2a22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions