diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 88d9d42e840..0689b0ded6e 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -120,7 +120,16 @@ pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T // Is the type's representation size known at compile time? pub fn type_is_sized<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { let param_env = ty::empty_parameter_environment(tcx); - ty::type_is_sized(¶m_env, DUMMY_SP, ty) + // FIXME(#4287) This can cause errors due to polymorphic recursion, + // a better span should be provided, if available. + let err_count = tcx.sess.err_count(); + let is_sized = ty::type_is_sized(¶m_env, DUMMY_SP, ty); + // Those errors aren't fatal, but an incorrect result can later + // trip over asserts in both rustc's trans and LLVM. + if err_count < tcx.sess.err_count() { + tcx.sess.abort_if_errors(); + } + is_sized } pub fn type_is_fat_ptr<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool { diff --git a/src/test/compile-fail/infinite-instantiation.rs b/src/test/compile-fail/infinite-instantiation.rs index 2642ac6204c..d39efa3c2ab 100644 --- a/src/test/compile-fail/infinite-instantiation.rs +++ b/src/test/compile-fail/infinite-instantiation.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,28 +8,34 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: reached the recursion limit during monomorphization -// issue 2258 +//~^^^^^^^^^^ ERROR overflow +// +// We get an error message at the top of file (dummy span). +// This is not helpful, but also kind of annoying to prevent, +// so for now just live with it. +// This test case was originally for issue #2258. -trait to_opt { +trait ToOpt { fn to_option(&self) -> Option; } -impl to_opt for usize { +impl ToOpt for usize { fn to_option(&self) -> Option { Some(*self) } } -impl to_opt for Option { +impl ToOpt for Option { fn to_option(&self) -> Option> { Some((*self).clone()) } } -fn function(counter: usize, t: T) { +fn function(counter: usize, t: T) { if counter > 0_usize { function(counter - 1_usize, t.to_option()); + // FIXME(#4287) Error message should be here. It should be + // a type error to instantiate `test` at a type other than T. } } diff --git a/src/test/compile-fail/recursion.rs b/src/test/compile-fail/recursion.rs index ffc21a5ce61..55f3b995336 100644 --- a/src/test/compile-fail/recursion.rs +++ b/src/test/compile-fail/recursion.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,10 +10,9 @@ //~^^^^^^^^^^ ERROR overflow // -// We also get a second error message at the top of file (dummy -// span). This is not helpful, but also kind of annoying to prevent, -// so for now just live with it, since we also get a second message -// that is more helpful. +// We get an error message at the top of file (dummy span). +// This is not helpful, but also kind of annoying to prevent, +// so for now just live with it. enum Nil {NilValue} struct Cons {head:isize, tail:T} @@ -28,9 +27,8 @@ impl Dot for Cons { } fn test (n:isize, i:isize, first:T, second:T) ->isize { match n { 0 => {first.dot(second)} - //~^ ERROR: reached the recursion limit during monomorphization - // Error message should be here. It should be a type error - // to instantiate `test` at a type other than T. (See #4287) + // FIXME(#4287) Error message should be here. It should be + // a type error to instantiate `test` at a type other than T. _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} } }