From d4077ad62152f1e1f1137afbdae76fcecee6fad0 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sat, 23 Dec 2017 22:45:39 -0500 Subject: [PATCH 1/2] Hard break for rust-lang/rust#46976 --- src/librustdoc/html/render.rs | 6 +++++- src/test/rustdoc/issue-46976.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/issue-46976.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3be44f3095858..d0329a04206c3 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -4130,7 +4130,11 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option match *clean_type { clean::ResolvedPath { ref path, .. } => { let segments = &path.segments; - Some(segments[segments.len() - 1].name.clone()) + let path_segment = segments.into_iter().last().unwrap_or_else(|| panic!( + "get_index_type_name(clean_type: {:?}, accept_generic: {:?}) had length zero path", + clean_type, accept_generic + )); + Some(path_segment.name.clone()) } clean::Generic(ref s) if accept_generic => Some(s.clone()), clean::Primitive(ref p) => Some(format!("{:?}", p)), diff --git a/src/test/rustdoc/issue-46976.rs b/src/test/rustdoc/issue-46976.rs new file mode 100644 index 0000000000000..0df80fe3bd77a --- /dev/null +++ b/src/test/rustdoc/issue-46976.rs @@ -0,0 +1,12 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(universal_impl_trait)] +pub fn ice(f: impl Fn()) {} From 077ba8a7991ed3706cb2ebe2982607402a86f618 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sat, 30 Dec 2017 22:18:39 -0500 Subject: [PATCH 2/2] Fix rust-lang/rust#46976 --- src/librustc/hir/lowering.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6fc35e5302dbb..4383e0c9432b5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -995,9 +995,10 @@ impl<'a> LoweringContext<'a> { ); let hir_bounds = self.lower_bounds(bounds, itctx); + // Set the name to `impl Bound1 + Bound2` + let name = Symbol::intern(&pprust::ty_to_string(t)); self.in_band_ty_params.push(hir::TyParam { - // Set the name to `impl Bound1 + Bound2` - name: Symbol::intern(&pprust::ty_to_string(t)), + name, id: def_node_id, bounds: hir_bounds, default: None, @@ -1009,7 +1010,7 @@ impl<'a> LoweringContext<'a> { hir::TyPath(hir::QPath::Resolved(None, P(hir::Path { span, def: Def::TyParam(DefId::local(def_index)), - segments: vec![].into(), + segments: hir_vec![hir::PathSegment::from_name(name)], }))) }, ImplTraitContext::Disallowed => {