Skip to content

Commit b127b9f

Browse files
committed
[rustdoc] Don't try to print the value of a non-primitive const
1 parent 5497a36 commit b127b9f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/librustdoc/clean/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ pub(crate) fn print_evaluated_const(
371371
) -> Option<String> {
372372
tcx.const_eval_poly(def_id).ok().and_then(|val| {
373373
let ty = tcx.type_of(def_id).instantiate_identity();
374+
if !ty.is_primitive() {
375+
return None;
376+
}
374377
match (val, ty.kind()) {
375378
(_, &ty::Ref(..)) => None,
376379
(mir::ConstValue::Scalar(_), &ty::Adt(_, _)) => None,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![crate_name = "foo"]
2+
3+
pub trait Foo {
4+
type AssocType;
5+
6+
const THE_CONST: Self::AssocType;
7+
}
8+
9+
pub struct Bar;
10+
11+
impl Foo for Bar {
12+
type AssocType = (u32,);
13+
14+
//@ has foo/struct.Bar.html
15+
//@ matches - '//section[@id="associatedconstant.THE_CONST"]/h4[@class="code-header"]' '^const THE_CONST: Self::AssocType'
16+
//@ !matches - '//section[@id="associatedconstant.THE_CONST"]//*[last()]' '{transmute'
17+
const THE_CONST: Self::AssocType = (1u32,);
18+
}

0 commit comments

Comments
 (0)