]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53541 - GuillaumeGomez:fix-impl-trait-ret-type, r=oli-obk
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 22 Aug 2018 15:45:36 +0000 (17:45 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Aug 2018 15:45:36 +0000 (17:45 +0200)
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 ðŸ˜‰)

1  2 
src/librustdoc/clean/mod.rs

index 6cb37c0e6de142a16c32d067990b714534fb013b,57ae2ac3a5b2af829ecc63ff490ae0a641ed0e98..a7fe15deb522bbde19acc9d172140bb7b47a0638
@@@ -2378,6 -2378,7 +2378,7 @@@ impl From<ast::FloatTy> for PrimitiveTy
  impl Clean<Type> for hir::Ty {
      fn clean(&self, cx: &DocContext) -> Type {
          use rustc::hir::*;
          match self.node {
              TyKind::Never => Never,
              TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
                      if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&did) {
                          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 ty_substs = FxHashMap();
                      let mut lt_substs = FxHashMap();
                      provided_params.with_generic_args(|generic_args| {
 -                        let mut indices = ty::GenericParamCount {
 -                            lifetimes: 0,
 -                            types: 0
 -                        };
 +                        let mut indices: GenericParamCount = Default::default();
                          for param in generics.params.iter() {
                              match param.kind {
                                  hir::GenericParamKind::Lifetime { .. } => {