-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Borrowck allows two mutable borrows when using match ergonomics #51117
Comments
NLL fixes this. Adding
|
|
Now that 1.26.1 has been released, can someone confirm that this will be fixed in 1.26.2, or at least disable match ergonomics entirely? It isn't feasible to expect users to download a nightly and enable |
I for one would love the option to disable match ergonomics for crates. It's been nothing but distracting so far. |
|
I doubt that we will be disabling match ergonomics at this point due to their likely wide use and stabilization. It's possible we'd make another patch release but rather unlikely; we'll see what the results of compiler discussion are (I believe their meeting is Thursday). I do believe we'll backport the fix to beta so that it makes it for 1.27 if we have it by then. |
I figured compiling code to access garbage memory silently would be more serious than that. I guess users should stay with 1.25 then. |
@novacrazy This issue isn't the place to argue about the feature itself (which has already gone through several open comment periods prior to stabilization). I'd encourage you to instead open a thread on https://internals.rust-lang.org/ to talk about your experiences in detail, if you think there's something actionable for the lang team. |
This problem is in no way specific to match-default-bindings, apparently. The following program is also accepted (!): fn main() {
let mut foo = Some("foo".to_string());
let bar = &mut foo;
match bar {
Some(ref mut baz) => {
bar.take();
drop(baz);
},
None => unreachable!(),
}
} |
@nikomatsakis prepending |
@nikomatsakis |
I see, I see. Yes, of course. That helps! thanks. |
Found the bug. "Implicit" derefs were accidentally being considered distinct from "explicit" derefs, leading borrowck to conclude that there are two distinct paths involved. Fix coming shortly. |
…ef, r=eddyb remove notion of Implicit derefs from mem-cat `PointerKind` is included in `LoanPath` and hence forms part of the equality check; this led to having two unequal paths that both represent `*x`, depending on whether the `*` was inserted automatically or explicitly. Bad mojo. Fixes #51117 r? @eddyb
Core team just discussed this and we've decided to backport the fix and release 1.26.2. |
1.26.2 release This includes a backport of #51235 which fixes #51117 on stable. It has not been tested. r? @nikomatsakis since the backport was not clean. cc @rust-lang/core @rust-lang/release
Can this be closed? |
Yes, I think so. |
The fix for rust-lang/rust#51117 exposed some other double mutable borrows, which are difficult to work around without enabling NLL.
Since this was fixed on AST-borrowck by #51235, removing NLL-fixed-by-NLL. |
... which can be used to trigger a UAF in safe code.
Original repro:
Inserting explicit annotations to disable match ergonomics leads to borrowck correctly complaining about two mutable borrows, which leads me to believe this is only because of match ergonomics.
The text was updated successfully, but these errors were encountered: