Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrow checker error does not figure out source of 'static requirement through closure capture #126342

Open
Noratrieb opened this issue Jun 12, 2024 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Noratrieb
Copy link
Member

Code

fn main() {
    let targets = String::new();
    let queue = targets.as_str();

    (move || require_static(queue))();
}

fn require_static(_: &'static str) {}

Current output

error[E0597]: `targets` does not live long enough
 --> src/main.rs:3:17
  |
2 |     let targets = String::new();
  |         ------- binding `targets` declared here
3 |     let queue = targets.as_str();
  |                 ^^^^^^^---------
  |                 |
  |                 borrowed value does not live long enough
  |                 argument requires that `targets` is borrowed for `'static`
...
6 | }
  | - `targets` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

error[E0597]: `targets` does not live long enough
 --> src/main.rs:3:17
  |
2 |     let targets = String::new();
  |         ------- binding `targets` declared here
3 |     let queue = targets.as_str();
  |                 ^^^^^^^ borrowed value does not live long enough
4 |
5 |     (move || require_static(queue))();
  |              --------------------- argument requires that `targets` is borrowed for `'static`
6 | }
  | - `targets` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Rationale and extra context

No response

Other cases

This works on stable, but regressed on nightly.

Rust Version

rustc 1.80.0-nightly (804421dff 2024-06-07)

Anything else?

No response

@Noratrieb Noratrieb added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-untriaged Untriaged performance or correctness regression. labels Jun 12, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 12, 2024
@Noratrieb
Copy link
Member Author

Regression in rust-lang-ci@4ffe0cc
The PR introducing the regression in this rollup is #122820: Stop using <DefId as Ord> in various diagnostic situations

searched nightlies: from nightly-2024-03-21 to nightly-2024-03-26
regressed nightly: nightly-2024-03-23
searched commit range: 0ad927c...85e449a
regressed commit: 1447f9d

bisected with cargo-bisect-rustc v0.6.8

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

cargo bisect-rustc --access github --start 2024-03-21 --end 2024-03-26 --prompt --preserve -- check 

@estebank @oli-obk I see the diagnostics changes caused test changes and you were aware of those, but it's really unfortunate :(.. i was really confused by this, would be great if it could be restored somehow

@Noratrieb Noratrieb added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Jun 12, 2024
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

Thanks for bisecting! cc @oli-obk for #122820

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 13, 2024
@lqd
Copy link
Member

lqd commented Jun 13, 2024

This will be stable later today.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 13, 2024

Yea, this is unfortunate, but previously was relying on essentially random information to emit the better diagnostic. We could try to get a similar enough mostly-random value for deciding the order of things and thus getting the diagnostic back, but I didn't do that in the hope of actually finding a reasonable heuristic

@Mark-Simulacrum Mark-Simulacrum added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants