-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
regression 1.50: Borrow checker reports function param as not living long enough #80949
Comments
Let's try to reduce it @rustbot ping cleanup |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @JamesPatrickGill @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @shekohex @sinato @smmalis37 @steffahn @Stupremee @tamuhey @turboladen @woshilapin @yerke |
Still with dependency, but simplified code
let's see what I can get from there |
searched nightlies: from nightly-2020-12-01 to nightly-2021-01-06 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc 2021-01-06 --without-cargo --access github --regress error The code I tested:
|
Error: Label ICEBreaker-Cleanup-Crew can only be set by Rust team members Please let |
So #78373 resulted in MIR having one fewer block, which is making borrowck be less precise with how long the borrow lasts. There are a few possible fixes here for me to look at. |
Assigning |
@rylev how common was this bug in the crater report? just the one crate? |
Yes the linked crate was the only crate to show signs of this issue in the crater run. |
@nikomatsakis @pnkfelix @nagisa wanted a longer explanation of what's going on here. When we type check the MIR we find that:
So the lifetime of the borrow contains all points where In the new MIR the drop of |
While setting up my system for the revert, I narrowed the MCVE down a bit further. I don't think I illuminated much more in the process, though I do find it curious that I wasn't able to easily find a way to take the trait Trait { type Item; }
impl<'a, X> Trait for &'a Vec<X> {
type Item = &'a X;
}
impl<X> Trait for Box<dyn Trait<Item = X>> {
type Item = X;
}
fn make_dyn_trait(_: &()) -> Box<dyn Trait<Item = &()>> {
todo!()
}
fn diff<'a, M, N, S>(_: N, _: S)
where
M: 'a,
N: Trait<Item = &'a M>,
S: Trait<Item = &'a M>,
{
todo!()
}
fn may_panic<X>(_: X) { }
fn main() {
let dyn_trait = make_dyn_trait(&());
let storage = vec![()];
let _x = may_panic(());
let storage_ref = &storage;
diff(dyn_trait, storage_ref);
} |
(landing PR #81257 and backporting it to the beta channel would resolve this.) |
Here is a minified example of a regression I have run into, not sure if it's the same issue: use std::error::Error;
use std::iter;
fn walk_source_chain(error: &impl Error) {
for e in iter::successors(error.source(), |e| e.source()) {
println!("{}", e);
}
} Changing the closure parameter pattern to match |
Hmm, that example compiles on beta though. |
I believe that's an unrelated issue. Opened #81460 to track it. Thanks for reporting it! |
…ution-via-revert-of-pr-78373, r=matthewjasper Revert 78373 ("dont leak return value after panic in drop") Short term resolution for issue rust-lang#80949. Reopen rust-lang#47949 after this lands. (We plan to fine-tune PR rust-lang#78373 to not run into this problem.)
…ution-via-revert-of-pr-78373, r=matthewjasper Revert 78373 ("dont leak return value after panic in drop") Short term resolution for issue rust-lang#80949. Reopen rust-lang#47949 after this lands. (We plan to fine-tune PR rust-lang#78373 to not run into this problem.)
Fix backported to 1.50 and landed in 1.51, closing this. |
Only remove unreachable blocks after drop elaboration but avoid merging blocks, as that sometimes confuses borrowck precomputation of borrows_out_of_scope. See issue rust-lang#80949 for more details.
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
This might not actually be a regression an instead the code may have previously erroneously compiled. I cannot find an an open issue obviously related to this though.
As you can see here this code does not compile with a "borrowed value does not live long enough" where it did previously. This comes from a call to
diff::diff
which has this signature.The error message states that
n
may be dropped while the borrow in the next paramstate
is still active. This fails to compile on both 1.50 and 1.49 if the paramstate
is move to a local variable.@rustbot modify labels: +regression-from-stable-to-beta
The text was updated successfully, but these errors were encountered: