Skip to content

Commit 7e24b98

Browse files
committed
upvar: Make sure that typeck succeeded before analyzing a closure
If a type that cannot be called as a function is called, and the result is assigned to a variable, the "unexpected callee type" ICE occurs. Fixes rust-lang#20714. Fixes rust-lang#20842. Fixes rust-lang#20862.
1 parent ffd8cb7 commit 7e24b98

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/librustc_typeck/check/upvar.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ pub fn closure_analyze_fn(fcx: &FnCtxt,
6161
let mut seed = SeedBorrowKind::new(fcx);
6262
seed.visit_block(body);
6363

64-
let mut adjust = AdjustBorrowKind::new(fcx);
65-
adjust.analyze_fn(decl, body);
64+
if fcx.err_count_since_creation() == 0 {
65+
let mut adjust = AdjustBorrowKind::new(fcx);
66+
adjust.analyze_fn(decl, body);
67+
}
6668
}
6769

6870
///////////////////////////////////////////////////////////////////////////
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
// Related issues: #20714, #20842, #20862
12+
13+
fn main() {
14+
let homura = ""(); //~ ERROR expected function, found
15+
}

0 commit comments

Comments
 (0)