Rollup merge of #61605 - GuillaumeGomez:const-generic-display, r=varkor

Fix slice const generic length display

Fixes #61487.

r? @varkor
This commit is contained in:
Mazdak Farrokhzad 2019-06-07 16:48:09 +02:00 committed by GitHub
commit 9bbdc40334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -2768,7 +2768,10 @@ impl Clean<Type> for hir::Ty {
};
let length = match cx.tcx.const_eval(param_env.and(cid)) {
Ok(length) => print_const(cx, length),
Err(_) => "_".to_string(),
Err(_) => cx.sess()
.source_map()
.span_to_snippet(cx.tcx.def_span(def_id))
.unwrap_or_else(|_| "_".to_string()),
};
Array(box ty.clean(cx), length)
},

View File

@ -0,0 +1,12 @@
#![crate_name = "foo"]
#![feature(const_generics)]
pub trait Array {
type Item;
}
// @has foo/trait.Array.html
// @has - '//h3[@class="impl"]' 'impl<T, const N: usize> Array for [T; N]'
impl <T, const N: usize> Array for [T; N] {
type Item = T;
}