Auto merge of #46894 - detrumi:fix-const-eval-trait, r=eddyb
Const-eval array lengths in rustdoc. Fixes #46727 r? @eddyb Big thanks to @eddyb for helping me figure this out.
This commit is contained in:
commit
304717bd86
3 changed files with 40 additions and 2 deletions
|
@ -33,7 +33,6 @@ use rustc::middle::resolve_lifetime as rl;
|
|||
use rustc::middle::lang_items;
|
||||
use rustc::hir::def::{Def, CtorKind};
|
||||
use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc::traits::Reveal;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, Ty, AdtKind};
|
||||
use rustc::middle::stability;
|
||||
|
@ -2062,7 +2061,7 @@ impl Clean<Type> for hir::Ty {
|
|||
TySlice(ref ty) => Slice(box ty.clean(cx)),
|
||||
TyArray(ref ty, n) => {
|
||||
let def_id = cx.tcx.hir.body_owner_def_id(n);
|
||||
let param_env = ty::ParamEnv::empty(Reveal::UserFacing);
|
||||
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 = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
|
||||
|
@ -2191,6 +2190,11 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
ty::TyStr => Primitive(PrimitiveType::Str),
|
||||
ty::TySlice(ty) => Slice(box ty.clean(cx)),
|
||||
ty::TyArray(ty, n) => {
|
||||
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()
|
||||
};
|
||||
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
|
||||
n.to_string()
|
||||
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
|
||||
|
|
17
src/test/rustdoc/auxiliary/issue-46727.rs
Normal file
17
src/test/rustdoc/auxiliary/issue-46727.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// compile-flags: -Cmetadata=aux
|
||||
|
||||
pub trait Foo {}
|
||||
|
||||
pub struct Bar<T> { x: T }
|
||||
|
||||
impl<T> Foo for Bar<[T; 1 + 1 + 1]> {}
|
17
src/test/rustdoc/issue-46727.rs
Normal file
17
src/test/rustdoc/issue-46727.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:issue-46727.rs
|
||||
|
||||
extern crate issue_46727;
|
||||
|
||||
// @has issue_46727/trait.Foo.html
|
||||
// @has - '//code' 'impl<T> Foo for Bar<[T; 3]>'
|
||||
pub use issue_46727::{Foo, Bar};
|
Loading…
Add table
Add a link
Reference in a new issue