Skip to content

Commit d201e83

Browse files
committed
renumber regions in the generator interior
Fixes #47189.
1 parent bf02c57 commit d201e83

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/librustc_mir/borrow_check/nll/renumber.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use rustc::ty::subst::Substs;
12-
use rustc::ty::{self, ClosureSubsts, Ty, TypeFoldable};
12+
use rustc::ty::{self, ClosureSubsts, GeneratorInterior, Ty, TypeFoldable};
1313
use rustc::mir::{BasicBlock, Location, Mir, Statement, StatementKind};
1414
use rustc::mir::visit::{MutVisitor, TyContext};
1515
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
@@ -90,6 +90,21 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> {
9090
*constant = self.renumber_regions(ty_context, &*constant);
9191
}
9292

93+
fn visit_generator_interior(&mut self,
94+
interior: &mut GeneratorInterior<'tcx>,
95+
location: Location) {
96+
debug!(
97+
"visit_generator_interior(interior={:?}, location={:?})",
98+
interior,
99+
location,
100+
);
101+
102+
let ty_context = TyContext::Location(location);
103+
*interior = self.renumber_regions(ty_context, interior);
104+
105+
debug!("visit_generator_interior: interior={:?}", interior);
106+
}
107+
93108
fn visit_closure_substs(&mut self, substs: &mut ClosureSubsts<'tcx>, location: Location) {
94109
debug!(
95110
"visit_closure_substs(substs={:?}, location={:?})",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2017 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+
#![feature(generators, nll)]
12+
13+
// Test for issue #47189. Here, both `s` and `t` are live for the
14+
// generator's lifetime, but within the generator they have distinct
15+
// lifetimes.
16+
//
17+
// Currently, we accept this code (with NLL enabled) since `x` is only
18+
// borrowed once at a time -- though whether we should is not entirely
19+
// obvious to me (the borrows are live over a yield, but then they are
20+
// re-borrowing borrowed content, etc). Maybe I just haven't had
21+
// enough coffee today, but I'm not entirely sure at this moment what
22+
// effect a `suspend` should have on existing borrows. -nmatsakis
23+
24+
fn foo(x: &mut u32) {
25+
move || {
26+
let s = &mut *x;
27+
yield;
28+
*s += 1;
29+
30+
let t = &mut *x;
31+
yield;
32+
*t += 1;
33+
};
34+
}
35+
36+
fn main() {
37+
foo(&mut 0);
38+
}

0 commit comments

Comments
 (0)