Skip to content

Issue 46976 #47083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm intrigued about the implications elsewhere in the compiler of having a path with a single path segment of impl Bound1 + Bound2, including that it'd be different from impl Bound2 + Bound1 (but that is already an issue elsewhere, IIRC) and the high likelihood of code not expecting this.

That being said, the code looks otherwise correct. Deferring to @cramertj and @arielb1, @nikomatsakis as they have more context, but it LGTM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@estebank It's also interesting because there can be multiple different types with the same name (since fn foo(_: impl Into<u8>, _: impl Into<u8>) { ... } desugars to something like fn foo<"impl Into<u8>": Into<u8>, "impl Into<u8>": Into<u8>>(...) { ... }). I think it should be fine, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point as well. If there isn't already, I can add a compile-pass test for the fn f(impl Trait, impl Trait) with two distinct types to the two arguments. That'll make sure it works.

})))
},
ImplTraitContext::Disallowed => {
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
12 changes: 12 additions & 0 deletions src/test/rustdoc/issue-46976.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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()) {}