Fix const evaluation ICE in rustdoc
This commit is contained in:
parent
56733bc9f8
commit
6b35d81382
@ -2447,7 +2447,12 @@ impl Clean<Type> 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<Type> 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()
|
||||
|
22
src/test/rustdoc/const-evalutation-ice.rs
Normal file
22
src/test/rustdoc/const-evalutation-ice.rs
Normal file
@ -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 <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.
|
||||
|
||||
// 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<usize>
|
||||
}
|
||||
|
||||
pub type _S = [usize; 0 - (mem::size_of::<S>() != 4) as usize];
|
Loading…
Reference in New Issue
Block a user