Skip to content

Borrow checker on beta rejects code accepted on stable. #60927

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

Closed
khuey opened this issue May 17, 2019 · 14 comments
Closed

Borrow checker on beta rejects code accepted on stable. #60927

khuey opened this issue May 17, 2019 · 14 comments
Assignees
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@khuey
Copy link
Contributor

khuey commented May 17, 2019

See the repo at https://github.com/khuey/rust-nightly-borrow-checker-failure

This repository builds on 1.34.2. It fails on 1.35.0-beta.8 with

error[E0597]: `global_lock` does not live long enough
  --> src/lib.rs:24:26
   |
24 |             let locked = global_lock.as_ref().lock().unwrap();
   |                          ^^^^^^^^^^^ borrowed value does not live long enough
25 |             ptr::write(&mut self.global_lock, Some(locked));
   |                        --------------------- cast requires that `global_lock` is borrowed for `'static`
26 |         }
27 |     }
   |     - `global_lock` dropped here while still borrowed

error: aborting due to previous error
@Manishearth Manishearth added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label May 17, 2019
@Manishearth
Copy link
Member

cc @nikomatsakis

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-borrow-checker Area: The borrow checker labels May 17, 2019
@Manishearth
Copy link
Member

We're cutting off a new stable next week, we should prioritize investigating and fixing this.

@Centril
Copy link
Contributor

Centril commented May 17, 2019

Maximally reduced (playpen):

pub fn bar<'a>(this: &'a mut ((), &'static ())) {
    let beta = from(&this.0);
    let locked = as_ref(&beta);
    write(&mut this.1, locked);
}

fn write<T>(_: *mut T, _: T) {}
fn from<'a>(_: &'a ()) -> &'static () { panic!() }
fn as_ref<'a>(_: &'a &'static ()) -> &'a () { panic!() }

@matthewjasper
Copy link
Contributor

Probably #58673, which fixed pointer casts being able to launder lifetimes with NLL.

@Manishearth
Copy link
Member

@matthewjasper any idea on how we'd be able to fix this in time for the release? Either by backporting or by fixing the actual bug?

@matthewjasper
Copy link
Contributor

The example provided should be using let locked = (*global_lock.as_ptr()).lock().unwrap();.

@khuey
Copy link
Contributor Author

khuey commented May 18, 2019

Yeah that works.

@pnkfelix
Copy link
Member

pnkfelix commented May 20, 2019

Hmm. Was I wrong about PR #58673 only affecting code opting in via #![feature(nll)]? I had thought when I reviewed that PR that it did not affect NLL migrate mode, and therefore could not be breaking stable/beta ...

Update: Ah! I figured out why NLL migrate mode does not "save" us here: The NLL error being signaled would only be downgraded to a warning if the AST-borrowck accepted the code. But the AST-borrowck rejects this code (or at least, it rejects the minimized example provided by @Centril , as you can see on this playpen). And therefore, we have a case where NLL previously accepted some code (but AST-borrowck rejected it), and now with PR #58673 in place, NLL rejects it with a hard error (because the migrate mode, upon inspecting the behavior of AST-borrowck, does not do the downgrade-to-warning).

@pietroalbini
Copy link
Member

pietroalbini commented May 20, 2019

Me and @pnkfelix discussed this on Discord. The beta to stable promotion is happening today so there is no time for the compiler team to decide what's the best fix for this issue, and we don't want to rush things.

I'm going to back out PR #58673 from the 1.35.0 release, but it will still be present on beta 1.36.0 and nightly, giving the teams more breathing room to reach a decision.

@pietroalbini
Copy link
Member

An update: backing out the change doesn't seem to be trivial so I'm going to do the initial stable PR without it (aka with the regression).

When I tried doing the revert I got a bunch of ICEs both in the test suite and while compiling stage1 rustc, so the backout seems risky enough not to do it right before 1.35.0 goes out.

cc @rust-lang/release

@Manishearth
Copy link
Member

Can we mention this in the release blog post so people are warned?

@Centril
Copy link
Contributor

Centril commented May 20, 2019

Assigning myself as a reminder re. blog post (but not for anything else).

@Centril Centril self-assigned this May 20, 2019
@pnkfelix
Copy link
Member

triage: I don't think we're going to try to "fix" the regression here. From the investigation documented above, it seems like acceptable fallout from a soundness fix; a warning-cycle would have been nice, but its not a necessity, and its not going to block the release.

Removing I-nominated tag, and not going to add a priority label. Leaving assigned to @Centril regarding messaging.

@Centril
Copy link
Contributor

Centril commented May 23, 2019

Decided not to include in blogpost or relnotes. Closing therefore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

7 participants