Skip to content

Commit 82c6679

Browse files
committed
Show use-site paths for unevaluated const array lengths
1 parent 4429659 commit 82c6679

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

src/librustdoc/clean/utils.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,28 +350,16 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
350350

351351
pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String {
352352
match n.kind() {
353-
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, .. }) => match kind {
354-
ty::UnevaluatedConstKind::Projection { def_id } => {
355-
if let Some(local_def_id) = def_id.as_local()
356-
&& let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id)
357-
{
358-
rendered_const(tcx, body_id, local_def_id)
359-
} else {
360-
n.to_string()
361-
}
362-
}
363-
ty::UnevaluatedConstKind::Inherent { def_id }
364-
| ty::UnevaluatedConstKind::Free { def_id }
365-
| ty::UnevaluatedConstKind::Anon { def_id } => {
366-
if let Some(local_def_id) = def_id.as_local()
367-
&& let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id)
368-
{
369-
rendered_const(tcx, body_id, local_def_id)
370-
} else {
371-
inline::print_inlined_const(tcx, def_id)
372-
}
353+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, .. }) => {
354+
let def_id = kind.opt_def_id().unwrap();
355+
if let Some(local_def_id) = def_id.as_local()
356+
&& let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id)
357+
{
358+
rendered_const(tcx, body_id, local_def_id)
359+
} else {
360+
n.to_string()
373361
}
374-
},
362+
}
375363
// array lengths are obviously usize
376364
ty::ConstKind::Value(cv) if *cv.ty.kind() == ty::Uint(ty::UintTy::Usize) => {
377365
cv.to_leaf().to_string()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name = "foo"]
2+
#![feature(min_generic_const_args)]
3+
#![expect(incomplete_features)]
4+
5+
type const N: usize = 2;
6+
7+
//@ has 'foo/trait.CollectArray.html'
8+
//@ has - '//pre[@class="rust item-decl"]/code' '[A; N]'
9+
pub trait CollectArray<A> {
10+
fn inner_array(&mut self) -> [A; N];
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_name = "foo"]
2+
#![feature(min_generic_const_args, inherent_associated_types)]
3+
#![expect(incomplete_features)]
4+
5+
pub struct Foo;
6+
7+
impl Foo {
8+
type const LEN: usize = 4;
9+
}
10+
11+
//@ has 'foo/fn.mk_array.html'
12+
//@ has - '//pre[@class="rust item-decl"]/code' '[u8; Foo::LEN]'
13+
pub fn mk_array() -> [u8; Foo::LEN] {
14+
[0u8; Foo::LEN]
15+
}

0 commit comments

Comments
 (0)