Skip to content

Commit 2f8d9a8

Browse files
committed
Resolve type vars when inferring borrow kinds for upvars
As part of #20432, upvar checking is now moved out of regionck to its own pass and before regionck. But regionck has some type resolution of it own. Without them, now separated upvar checking may be tripped over by residue `ty_infer`. Closes #21306
1 parent aedcbb9 commit 2f8d9a8

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,14 +1635,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16351635
{
16361636
let raw_ty = self.expr_ty(expr);
16371637
let raw_ty = self.infcx().shallow_resolve(raw_ty);
1638+
let resolve_ty = |&: ty: Ty<'tcx>| self.infcx().resolve_type_vars_if_possible(&ty);
16381639
ty::adjust_ty(self.tcx(),
16391640
expr.span,
16401641
expr.id,
16411642
raw_ty,
16421643
adjustment,
16431644
|method_call| self.inh.method_map.borrow()
16441645
.get(&method_call)
1645-
.map(|method| method.ty))
1646+
.map(|method| resolve_ty(method.ty)))
16461647
}
16471648

16481649
pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> {

src/librustc_typeck/check/upvar.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,8 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx> {
121121
capture_clause: ast::CaptureClause,
122122
_body: &ast::Block)
123123
{
124-
let is_old_skool_closure = match self.fcx.expr_ty(expr).sty {
125-
_ => false,
126-
};
127-
128124
match capture_clause {
129-
ast::CaptureByValue if !is_old_skool_closure => {
130-
}
125+
ast::CaptureByValue => {}
131126
_ => {
132127
ty::with_freevars(self.tcx(), expr.id, |freevars| {
133128
for freevar in freevars.iter() {

src/test/run-pass/issue-21306.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 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+
use std::sync::Arc;
12+
13+
fn main() {
14+
let x = 5us;
15+
let command = Arc::new(Box::new(|&:| { x*2 }));
16+
assert_eq!(command(), 10);
17+
}

0 commit comments

Comments
 (0)