Skip to content

Commit 09a7e64

Browse files
committed
When we turn on NLL migration in the 2018 edition, we need two-phase borrows too!
Fix rust-lang#52967.
1 parent 60c1ee7 commit 09a7e64

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/librustc/ty/context.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13951395
}
13961396

13971397
/// If true, we should enable two-phase borrows checks. This is
1398-
/// done with either `-Ztwo-phase-borrows` or with
1399-
/// `#![feature(nll)]`.
1398+
/// done with either: `-Ztwo-phase-borrows`, `#![feature(nll)]`,
1399+
/// or by opting into an edition after 2015.
14001400
pub fn two_phase_borrows(self) -> bool {
1401-
self.features().nll || self.sess.opts.debugging_opts.two_phase_borrows
1401+
if self.features().nll || self.sess.opts.debugging_opts.two_phase_borrows {
1402+
return true;
1403+
}
1404+
1405+
match self.sess.edition() {
1406+
Edition::Edition2015 => false,
1407+
Edition::Edition2018 => true,
1408+
_ => true,
1409+
}
14021410
}
14031411

14041412
/// What mode(s) of borrowck should we run? AST? MIR? both?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This is a regression test for #52967, where we discovered that in
12+
// the initial deployment of NLL for the 2018 edition, I forgot to
13+
// turn on two-phase-borrows in addition to `-Z borrowck=migrate`.
14+
15+
// revisions: ast zflags edition
16+
//[zflags]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
17+
//[edition]compile-flags: --edition 2018
18+
19+
// run-pass
20+
21+
fn the_bug() {
22+
let mut stuff = ("left", "right");
23+
match stuff {
24+
(ref mut left, _) if *left == "left" => { *left = "new left"; }
25+
_ => {}
26+
}
27+
assert_eq!(stuff, ("new left", "right"));
28+
}
29+
30+
fn main() {
31+
the_bug();
32+
}

0 commit comments

Comments
 (0)