未验证 提交 68698637 编写于 作者: K kennytm 提交者: GitHub

Rollup merge of #47862 - GuillaumeGomez:const-evaluation-ice, r=eddyb

Fix const evaluation ICE in rustdoc

Fixes #47860.

r? @EddyB
......@@ -2447,7 +2447,12 @@ fn clean(&self, cx: &DocContext) -> Type {
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 @@ fn clean(&self, cx: &DocContext) -> Type {
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()
......
// 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];
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册