diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0929b833c1965..7c9a49c82a939 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2447,7 +2447,12 @@ impl Clean for hir::Ty { let def_id = cx.tcx.hir.body_owner_def_id(n); let param_env = cx.tcx.param_env(def_id); let substs = Substs::identity_for_item(cx.tcx, def_id); - let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap(); + let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap_or_else(|_| { + cx.tcx.mk_const(ty::Const { + val: ConstVal::Unevaluated(def_id, substs), + ty: cx.tcx.types.usize + }) + }); let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val { n.to_string() } else if let ConstVal::Unevaluated(def_id, _) = n.val { @@ -2577,7 +2582,9 @@ impl<'tcx> Clean for Ty<'tcx> { let mut n = cx.tcx.lift(&n).unwrap(); if let ConstVal::Unevaluated(def_id, substs) = n.val { let param_env = cx.tcx.param_env(def_id); - n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap() + if let Ok(new_n) = cx.tcx.const_eval(param_env.and((def_id, substs))) { + n = new_n; + } }; let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val { n.to_string() diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc/const-evalutation-ice.rs new file mode 100644 index 0000000000000..9fed67ee583d2 --- /dev/null +++ b/src/test/rustdoc/const-evalutation-ice.rs @@ -0,0 +1,22 @@ +// Copyright 2018 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. + +// Just check if we don't get an ICE for the _S type. + +#![feature(const_size_of)] + +use std::cell::Cell; +use std::mem; + +pub struct S { + s: Cell +} + +pub type _S = [usize; 0 - (mem::size_of::() != 4) as usize];