Skip to content

Commit

Permalink
Auto merge of #24367 - ebfull:fix_ice_cat_expr, r=pnkfelix
Browse files Browse the repository at this point in the history
An actual typeck error is the cause of many failed compilations but an
unrelated bug is being reported instead. It is triggered because a typeck
error is presumably not yet identified during compiler execution, which
would normally bypass an invariant in the presence of other errors. In
this particular situation, we delay the reporting of the bug until
abort_if_errors().

Closes #23827, closes #24356, closes #23041, closes #22897, closes #23966,
closes #24013, and closes #23729

**There is at least one situation where this bug may still be genuinely
triggered (#23437).**
  • Loading branch information
bors committed Apr 26, 2015
2 parents 61a5e46 + be11171 commit b0043db
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 11 deletions.
18 changes: 17 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct Session {
pub crate_metadata: RefCell<Vec<String>>,
pub features: RefCell<feature_gate::Features>,

pub delayed_span_bug: RefCell<Option<(codemap::Span, String)>>,

/// The maximum recursion limit for potentially infinitely recursive
/// operations such as auto-dereference and monomorphization.
pub recursion_limit: Cell<usize>,
Expand Down Expand Up @@ -114,7 +116,15 @@ impl Session {
self.diagnostic().handler().has_errors()
}
pub fn abort_if_errors(&self) {
self.diagnostic().handler().abort_if_errors()
self.diagnostic().handler().abort_if_errors();

let delayed_bug = self.delayed_span_bug.borrow();
match *delayed_bug {
Some((span, ref errmsg)) => {
self.diagnostic().span_bug(span, errmsg);
},
_ => {}
}
}
pub fn span_warn(&self, sp: Span, msg: &str) {
if self.can_print_warnings {
Expand Down Expand Up @@ -171,6 +181,11 @@ impl Session {
None => self.bug(msg),
}
}
/// Delay a span_bug() call until abort_if_errors()
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
let mut delayed = self.delayed_span_bug.borrow_mut();
*delayed = Some((sp, msg.to_string()));
}
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
self.diagnostic().span_bug(sp, msg)
}
Expand Down Expand Up @@ -402,6 +417,7 @@ pub fn build_session_(sopts: config::Options,
plugin_llvm_passes: RefCell::new(Vec::new()),
crate_types: RefCell::new(Vec::new()),
crate_metadata: RefCell::new(Vec::new()),
delayed_span_bug: RefCell::new(None),
features: RefCell::new(feature_gate::Features::new()),
recursion_limit: Cell::new(64),
can_print_warnings: can_print_warnings
Expand Down
12 changes: 2 additions & 10 deletions src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
}
Err(..) => {
let tcx = rcx.fcx.tcx();
if tcx.sess.has_errors() {
// cannot run dropck; okay b/c in error state anyway.
} else {
tcx.sess.span_bug(expr.span, "cat_expr_unadjusted Errd");
}
tcx.sess.delay_span_bug(expr.span, "cat_expr_unadjusted Errd");
}
}
}
Expand All @@ -583,11 +579,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
}
Err(..) => {
let tcx = rcx.fcx.tcx();
if tcx.sess.has_errors() {
// cannot run dropck; okay b/c in error state anyway.
} else {
tcx.sess.span_bug(expr.span, "cat_expr Errd");
}
tcx.sess.delay_span_bug(expr.span, "cat_expr Errd");
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/issue-22897.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() { }

// Before these errors would ICE as "cat_expr Errd" because the errors
// were unknown when the bug was triggered.

fn unconstrained_type() {
[];
//~^ ERROR cannot determine a type for this expression: unconstrained type
}
18 changes: 18 additions & 0 deletions src/test/compile-fail/issue-23041.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::any::Any;
fn main()
{
fn bar(x:i32) ->i32 { 3*x };
let b:Box<Any> = Box::new(bar as fn(_)->_);
b.downcast_ref::<fn(_)->_>();
//~^ ERROR cannot determine a type for this expression: unconstrained type
}
14 changes: 14 additions & 0 deletions src/test/compile-fail/issue-23966.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
"".chars().fold(|_, _| (), ());
//~^ ERROR cannot determine a type for this expression: unconstrained type
}
17 changes: 17 additions & 0 deletions src/test/compile-fail/issue-24013.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
use std::mem::{transmute, swap};
let a = 1;
let b = 2;
unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
//~^ ERROR cannot determine a type for this expression: unconstrained type
}

0 comments on commit b0043db

Please sign in to comment.