From 8f3753703c9e4e587fcb9790a07aa18b310b8431 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 7 Jun 2019 00:58:32 +0200 Subject: [PATCH] Fix slice const generic length display --- src/librustdoc/clean/mod.rs | 5 ++++- .../rustdoc/const-generics/const-generic-slice.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/const-generics/const-generic-slice.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 03d16feb483a9..a717ef20a8444 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2768,7 +2768,10 @@ impl Clean 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) }, diff --git a/src/test/rustdoc/const-generics/const-generic-slice.rs b/src/test/rustdoc/const-generics/const-generic-slice.rs new file mode 100644 index 0000000000000..60d96770f7eae --- /dev/null +++ b/src/test/rustdoc/const-generics/const-generic-slice.rs @@ -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 Array for [T; N]' +impl Array for [T; N] { + type Item = T; +}