Rollup merge of #53541 - GuillaumeGomez:fix-impl-trait-ret-type, r=oli-obk
Fix missing impl trait display as ret type
I need to convert a `TraitPredicate` into a `TraitBound` to get the returned impl trait. So far, didn't find how or even if it was the good way to do it.
cc @eddyb @oli-obk (since you're the one behind the change apparently 😉)
This commit is contained in:
commit
3d8e760bf8
@ -2378,6 +2378,7 @@ impl From<ast::FloatTy> for PrimitiveType {
|
|||||||
impl Clean<Type> for hir::Ty {
|
impl Clean<Type> for hir::Ty {
|
||||||
fn clean(&self, cx: &DocContext) -> Type {
|
fn clean(&self, cx: &DocContext) -> Type {
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
|
|
||||||
match self.node {
|
match self.node {
|
||||||
TyKind::Never => Never,
|
TyKind::Never => Never,
|
||||||
TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
|
TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
|
||||||
@ -2415,6 +2416,14 @@ impl Clean<Type> for hir::Ty {
|
|||||||
if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&did) {
|
if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&did) {
|
||||||
return ImplTrait(bounds);
|
return ImplTrait(bounds);
|
||||||
}
|
}
|
||||||
|
} else if let Def::Existential(did) = path.def {
|
||||||
|
// This block is for returned impl trait only.
|
||||||
|
if let Some(node_id) = cx.tcx.hir.as_local_node_id(did) {
|
||||||
|
let item = cx.tcx.hir.expect_item(node_id);
|
||||||
|
if let hir::ItemKind::Existential(ref ty) = item.node {
|
||||||
|
return ImplTrait(ty.bounds.clean(cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut alias = None;
|
let mut alias = None;
|
||||||
|
40
src/test/rustdoc/impl-everywhere.rs
Normal file
40
src/test/rustdoc/impl-everywhere.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2018 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.
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
pub trait Foo {}
|
||||||
|
pub trait Foo2 {}
|
||||||
|
|
||||||
|
pub struct Bar;
|
||||||
|
|
||||||
|
impl Foo for Bar {}
|
||||||
|
impl Foo2 for Bar {}
|
||||||
|
|
||||||
|
// @!has foo/fn.foo.html '//section[@id="main"]//pre' "x: &\'x impl Foo"
|
||||||
|
// @!has foo/fn.foo.html '//section[@id="main"]//pre' "-> &\'x impl Foo {"
|
||||||
|
pub fn foo<'x>(x: &'x impl Foo) -> &'x impl Foo {
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' "x: &\'x impl Foo"
|
||||||
|
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' '-> impl Foo2 {'
|
||||||
|
pub fn foo2<'x>(_x: &'x impl Foo) -> impl Foo2 {
|
||||||
|
Bar
|
||||||
|
}
|
||||||
|
|
||||||
|
// @!has foo/fn.foo_foo.html '//section[@id="main"]//pre' '-> impl Foo + Foo2 {'
|
||||||
|
pub fn foo_foo() -> impl Foo + Foo2 {
|
||||||
|
Bar
|
||||||
|
}
|
||||||
|
|
||||||
|
// @!has foo/fn.foo2.html '//section[@id="main"]//pre' "x: &'x (impl Foo + Foo2)"
|
||||||
|
pub fn foo_foo_foo<'x>(_x: &'x (impl Foo + Foo2)) {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user