From 7e24b982aea11f5f10656fe09e6df5b26a35d52b Mon Sep 17 00:00:00 2001 From: Barosl Lee Date: Sat, 10 Jan 2015 09:02:16 +0900 Subject: [PATCH] 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 #20714. Fixes #20842. Fixes #20862. --- src/librustc_typeck/check/upvar.rs | 6 ++++-- .../compile-fail/unexpected-callee-type-ice.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/unexpected-callee-type-ice.rs diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index ec44d765a8e68..bf63392c29f87 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -61,8 +61,10 @@ pub fn closure_analyze_fn(fcx: &FnCtxt, let mut seed = SeedBorrowKind::new(fcx); seed.visit_block(body); - let mut adjust = AdjustBorrowKind::new(fcx); - adjust.analyze_fn(decl, body); + if fcx.err_count_since_creation() == 0 { + let mut adjust = AdjustBorrowKind::new(fcx); + adjust.analyze_fn(decl, body); + } } /////////////////////////////////////////////////////////////////////////// diff --git a/src/test/compile-fail/unexpected-callee-type-ice.rs b/src/test/compile-fail/unexpected-callee-type-ice.rs new file mode 100644 index 0000000000000..a481852f2d092 --- /dev/null +++ b/src/test/compile-fail/unexpected-callee-type-ice.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Related issues: #20714, #20842, #20862 + +fn main() { + let homura = ""(); //~ ERROR expected function, found +}