about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2019-03-07 23:32:42 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2019-03-23 14:43:27 +0100
commitdc628b4f6728a858b9a2715e2d2046b4758bb6e4 (patch)
treed4e5d837803f3d534134d9f8de4283915a24f2ba
parent6bce61cd4b20ae0661a1a7bd656cebc999b5a2ee (diff)
downloadrust-dc628b4f6728a858b9a2715e2d2046b4758bb6e4.tar.gz
rust-dc628b4f6728a858b9a2715e2d2046b4758bb6e4.zip
cleanup
-rw-r--r--src/librustc_typeck/collect.rs8
-rw-r--r--src/librustdoc/clean/mod.rs28
-rw-r--r--src/librustdoc/html/render.rs1
3 files changed, 24 insertions, 13 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index e723ee1d10a..095c92ff10d 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1133,6 +1133,10 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
     checked_type_of(tcx, def_id, true).unwrap()
 }
 
+/// Same as [`type_of`] but returns [`Option`] instead of failing.
+///
+/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
+/// you'd better just call [`type_of`] directly.
 pub fn checked_type_of<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     def_id: DefId,
@@ -1382,14 +1386,14 @@ pub fn checked_type_of<'a, 'tcx>(
                                     for param in &generics.params {
                                         if let ty::GenericParamDefKind::Const = param.kind {
                                             if param_index == arg_index {
-                                                return tcx.type_of(param.def_id);
+                                                return Some(tcx.type_of(param.def_id));
                                             }
                                             param_index += 1;
                                         }
                                     }
                                     // This is no generic parameter associated with the arg. This is
                                     // probably from an extra arg where one is not needed.
-                                    return tcx.types.err;
+                                    return Some(tcx.types.err);
                                 }
                                 Def::Err => tcx.types.err,
                                 x => {
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index c41d02fbfbb..e7277308cd9 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1474,7 +1474,7 @@ impl GenericParamDefKind {
         }
     }
 
-    pub fn get_type(&self, cx: &DocContext<'_, '_, '_>) -> Option<Type> {
+    pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
         match *self {
             GenericParamDefKind::Type { did, .. } => {
                 rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
@@ -1505,7 +1505,7 @@ impl GenericParamDef {
         self.kind.is_type()
     }
 
-    pub fn get_type(&self, cx: &DocContext<'_, '_, '_>) -> Option<Type> {
+    pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
         self.kind.get_type(cx)
     }
 
@@ -1750,12 +1750,16 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
     }
 }
 
-// The point is to replace bounds with types.
+/// The point of this function is to replace bounds with types.
+///
+/// i.e. `[T, U]` when you have the following bounds: `T: Display, U: Option<T>` will return
+/// `[Display, Option]` (we just returns the list of the types, we don't care about the
+/// wrapped types in here).
 fn get_real_types(
     generics: &Generics,
     arg: &Type,
-    cx: &DocContext<'_, '_, '_>,
-) -> Vec<Type> {
+    cx: &DocContext<'_>,
+) -> FxHashSet<Type> {
     let arg_s = arg.to_string();
     let mut res = Vec::new();
     if arg.is_full_generic() {
@@ -1776,7 +1780,7 @@ fn get_real_types(
                             if let Some(ty) = x.get_type(cx) {
                                 let mut adds = get_real_types(generics, &ty, cx);
                                 if !adds.is_empty() {
-                                    res.append(&mut adds);
+                                    res.extend(adds);
                                 } else if !ty.is_full_generic() {
                                     res.push(ty);
                                 }
@@ -1794,7 +1798,7 @@ fn get_real_types(
                 if let Some(ty) = bound.get_trait_type() {
                     let mut adds = get_real_types(generics, &ty, cx);
                     if !adds.is_empty() {
-                        res.append(&mut adds);
+                        res.extend(adds);
                     } else if !ty.is_full_generic() {
                         res.push(ty.clone());
                     }
@@ -1808,7 +1812,7 @@ fn get_real_types(
                 if gen.is_full_generic() {
                     let mut adds = get_real_types(generics, gen, cx);
                     if !adds.is_empty() {
-                        res.append(&mut adds);
+                        res.extend(adds);
                     }
                 } else {
                     res.push(gen.clone());
@@ -1819,10 +1823,14 @@ fn get_real_types(
     res
 }
 
+/// Return the full list of types when bounds have been resolved.
+///
+/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
+/// `[u32, Display, Option]`.
 pub fn get_all_types(
     generics: &Generics,
     decl: &FnDecl,
-    cx: &DocContext<'_, '_, '_>,
+    cx: &DocContext<'_>,
 ) -> (Vec<Type>, Vec<Type>) {
     let mut all_types = Vec::new();
     for arg in decl.inputs.values.iter() {
@@ -1831,7 +1839,7 @@ pub fn get_all_types(
         }
         let mut args = get_real_types(generics, &arg.type_, cx);
         if !args.is_empty() {
-            all_types.append(&mut args);
+            all_types.extend(args);
         } else {
             all_types.push(arg.type_.clone());
         }
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 930f3fd3c5c..b0f0a26bd27 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -5052,7 +5052,6 @@ fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
         Some(output)
     };
 
-    println!("===> {:?}", output);
     Some(IndexItemFunctionType { inputs, output })
 }