Rollup merge of #76297 - lcnr:const-ty-alias, r=varkor
rustdoc: fix min_const_generics with ty::Param fixes #75913 r? @varkor cc @jyn514
This commit is contained in:
commit
5d90d6ee90
2 changed files with 16 additions and 10 deletions
|
@ -1364,16 +1364,16 @@ impl Clean<Type> for hir::Ty<'_> {
|
||||||
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
|
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
|
||||||
TyKind::Array(ref ty, ref length) => {
|
TyKind::Array(ref ty, ref length) => {
|
||||||
let def_id = cx.tcx.hir().local_def_id(length.hir_id);
|
let def_id = cx.tcx.hir().local_def_id(length.hir_id);
|
||||||
let length = match cx.tcx.const_eval_poly(def_id.to_def_id()) {
|
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
||||||
Ok(length) => {
|
// as we currently do not supply the parent generics to anonymous constants
|
||||||
print_const(cx, ty::Const::from_value(cx.tcx, length, cx.tcx.types.usize))
|
// but do allow `ConstKind::Param`.
|
||||||
}
|
//
|
||||||
Err(_) => cx
|
// `const_eval_poly` tries to to first substitute generic parameters which
|
||||||
.sess()
|
// results in an ICE while manually constructing the constant and using `eval`
|
||||||
.source_map()
|
// does nothing for `ConstKind::Param`.
|
||||||
.span_to_snippet(cx.tcx.def_span(def_id))
|
let ct = ty::Const::from_anon_const(cx.tcx, def_id);
|
||||||
.unwrap_or_else(|_| "_".to_string()),
|
let param_env = cx.tcx.param_env(def_id);
|
||||||
};
|
let length = print_const(cx, ct.eval(cx.tcx, param_env));
|
||||||
Array(box ty.clean(cx), length)
|
Array(box ty.clean(cx), length)
|
||||||
}
|
}
|
||||||
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
|
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
|
||||||
|
|
6
src/test/rustdoc/const-generics/type-alias.rs
Normal file
6
src/test/rustdoc/const-generics/type-alias.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// ignore-tidy-linelength
|
||||||
|
#![feature(min_const_generics)]
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/type.CellIndex.html '//pre[@class="rust typedef"]' 'type CellIndex<const D: usize> = [i64; D];'
|
||||||
|
pub type CellIndex<const D: usize> = [i64; D];
|
Loading…
Add table
Add a link
Reference in a new issue