Skip to content

Commit 5db71db

Browse files
committed
Auto merge of #53133 - Zoxc:gen-int, r=eddyb
Record adjustments and original type for expressions in the generator interior Fixes #50878 and #52398. r? @eddyb
2 parents 18a4c38 + 401af79 commit 5db71db

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/librustc_typeck/check/generator_interior.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'gcx, 'tcx> {
167167

168168
let scope = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
169169

170-
let ty = self.fcx.tables.borrow().expr_ty_adjusted(expr);
170+
// Record the unadjusted type
171+
let ty = self.fcx.tables.borrow().expr_ty(expr);
171172
self.record(ty, scope, Some(expr), expr.span);
173+
174+
// Also include the adjusted types, since these can result in MIR locals
175+
for adjustment in self.fcx.tables.borrow().expr_adjustments(expr) {
176+
self.record(adjustment.target, scope, Some(expr), expr.span);
177+
}
172178
}
173179
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
#![feature(generators)]
12+
13+
use std::cell::RefCell;
14+
15+
struct A;
16+
17+
impl A {
18+
fn test(&self, a: ()) {}
19+
}
20+
21+
fn main() {
22+
// Test that the MIR local with type &A created for the auto-borrow adjustment
23+
// is caught by typeck
24+
move || {
25+
A.test(yield);
26+
};
27+
28+
// Test that the std::cell::Ref temporary returned from the `borrow` call
29+
// is caught by typeck
30+
let y = RefCell::new(true);
31+
static move || {
32+
yield *y.borrow();
33+
return "Done";
34+
};
35+
}

0 commit comments

Comments
 (0)