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

Borrowed value does not live long enough beta regression #101822

Closed
marmeladema opened this issue Sep 14, 2022 · 4 comments
Closed

Borrowed value does not live long enough beta regression #101822

marmeladema opened this issue Sep 14, 2022 · 4 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.

Comments

@marmeladema
Copy link
Contributor

Code

I tried this code:

use std::collections::BTreeMap;

struct Context<'e> {
    _data: &'e [u8],
}

pub struct Rule<'s> {
    _rule: Box<dyn for<'e> Fn(&'e Context<'e>) -> bool + Sync + Send + 's>,
}

pub struct Scheme {}

pub struct Parser<'s> {
    _scheme: &'s Scheme,
}

impl<'s> Parser<'s> {
    pub fn new(_scheme: &'s Scheme) -> Self {
        Self { _scheme }
    }
}

#[derive(Default)]
pub struct Config<'s> {
    _data: BTreeMap<String, Rule<'s>>,
}

impl<'s> Config<'s> {
    pub fn update(&mut self, _: Parser<'s>) {}
}

pub fn main() {
    let mut configuration = Config::default();
    let scheme = Scheme {};
    let parser = Parser::new(&scheme);

    configuration.update(parser);
}

I expected to see this happen: it compiles successfully

Instead, this happened:

error[[E0597]](https://doc.rust-lang.org/beta/error-index.html#E0597): `scheme` does not live long enough
  --> src/main.rs:35:30
   |
35 |     let parser = Parser::new(&scheme);
   |                              ^^^^^^^ borrowed value does not live long enough
...
38 | }
   | -
   | |
   | `scheme` dropped here while still borrowed
   | borrow might be used here, when `configuration` is dropped and runs the destructor for type `Config<'_>`
   |
   = note: values in a scope are dropped in the opposite order they are defined

For more information about this error, try `rustc --explain E0597`.

Beta: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=3f293aff3e5dc16ad303940d4613514a
Stable: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3f293aff3e5dc16ad303940d4613514a

Version it worked on

It most recently worked on: 1.63.0 (but probably before too)

$ rustc --version --verbose
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.5

Version with regression

rustc --version --verbose:

$ rustc +beta --version --verbose
rustc 1.64.0-beta.6 (25912c097 2022-09-09)
binary: rustc
commit-hash: 25912c09710a2de2a97b4904e9b528b73439927d
commit-date: 2022-09-09
host: x86_64-unknown-linux-gnu
release: 1.64.0-beta.6
LLVM version: 14.0.6

This might be an acceptable breakage but we faced this regression in production code so I figured it might be worthwhile creating a bug report for this in case it was an unnoticed regression.

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

@marmeladema marmeladema added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 14, 2022
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Sep 14, 2022
@marmeladema
Copy link
Contributor Author

Creating scheme before configuration solves the issue but it is still a regression between stable and beta (and nightly)

@lukas-code
Copy link
Member

This was caused by #99413.
See also #100544.

@marmeladema
Copy link
Contributor Author

Thank you for your fast reply @lukas-code!
Its unfortunate that a fix like this lead to a backward incompatible change.
Error reporting is already awesome but a note in the error message saying this was previously accepted but isn't anymore would have been awesome 👍

@jackh726
Copy link
Member

Closing as duplicate of #100544

@jackh726 jackh726 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2022
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

5 participants