Rollup merge of #156851 - reddevilmidzy:mgca-doc, r=GuillaumeGomez

rustdoc: avoid ICE when rendering body-less type consts

close: https://github.com/rust-lang/rust/issues/149287
This commit is contained in:
Jonathan Brouwer
2026-05-27 08:14:27 +02:00
committed by GitHub
2 changed files with 20 additions and 2 deletions
+4 -2
View File
@@ -351,8 +351,10 @@ fn print_pat(pat: &Pat<'_>, wild: bool) -> impl Display {
pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String {
match n.kind() {
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => {
if let Some(def) = def.as_local() {
rendered_const(tcx, tcx.hir_body_owned_by(def), def)
if let Some(def) = def.as_local()
&& let Some(body_id) = tcx.hir_maybe_body_owned_by(def)
{
rendered_const(tcx, body_id, def)
} else {
inline::print_inlined_const(tcx, def)
}
@@ -0,0 +1,16 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/149287>
//! Ensure that rustdoc does not ICE when a body-less type const is used
//! as an associated const.
//@ check-pass
#![feature(min_generic_const_args)]
pub trait Tr {
type const SIZE: usize;
}
fn mk_array<T: Tr>() -> [(); <T as Tr>::SIZE] {
[(); T::SIZE]
}
fn main() {}