// 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 {
-// 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.
//
// 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<Self>;
}
-impl to_opt for usize {
+impl ToOpt for usize {
fn to_option(&self) -> Option<usize> {
Some(*self)
}
}
-impl<T:Clone> to_opt for Option<T> {
+impl<T:Clone> ToOpt for Option<T> {
fn to_option(&self) -> Option<Option<T>> {
Some((*self).clone())
}
}
-fn function<T:to_opt + Clone>(counter: usize, t: T) {
+fn function<T:ToOpt + Clone>(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.
}
}
-// 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.
//
//~^^^^^^^^^^ 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<T> {head:isize, tail:T}
}
fn test<T:Dot> (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})}
}
}