]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/astconv/mod.rs
fix most compiler/ doctests
[rust.git] / compiler / rustc_typeck / src / astconv / mod.rs
index 3e36ffa7fe0d2f4291dfae5a032f7cb9752ca61f..2303e64e1007456e76f2343d6215cf3fe4caf676 100644 (file)
@@ -294,9 +294,9 @@ pub fn ast_path_substs_for_ty(
     ///
     /// Example:
     ///
-    /// ```
-    /// T: std::ops::Index<usize, Output = u32>
-    /// ^1 ^^^^^^^^^^^^^^2 ^^^^3  ^^^^^^^^^^^4
+    /// ```ignore (illustrative)
+    ///    T: std::ops::Index<usize, Output = u32>
+    /// // ^1 ^^^^^^^^^^^^^^2 ^^^^3  ^^^^^^^^^^^4
     /// ```
     ///
     /// 1. The `self_ty` here would refer to the type `T`.
@@ -310,7 +310,7 @@ pub fn ast_path_substs_for_ty(
     ///
     /// For (generic) associated types
     ///
-    /// ```
+    /// ```ignore (illustrative)
     /// <Vec<u8> as Iterable<u8>>::Iter::<'a>
     /// ```
     ///
@@ -756,7 +756,7 @@ fn instantiate_poly_trait_ref_inner(
     ///
     /// Example:
     ///
-    /// ```
+    /// ```ignore (illustrative)
     /// poly_trait_ref = Iterator<Item = u32>
     /// self_ty = Foo
     /// ```
@@ -924,14 +924,9 @@ pub(crate) fn add_implicitly_sized<'hir>(
             let self_ty_def_id = tcx.hir().local_def_id(self_ty).to_def_id();
             for clause in where_clause {
                 if let hir::WherePredicate::BoundPredicate(pred) = clause {
-                    match pred.bounded_ty.kind {
-                        hir::TyKind::Path(hir::QPath::Resolved(_, path)) => match path.res {
-                            Res::Def(DefKind::TyParam, def_id) if def_id == self_ty_def_id => {}
-                            _ => continue,
-                        },
-                        _ => continue,
+                    if pred.is_param_bound(self_ty_def_id) {
+                        search_bounds(pred.bounds);
                     }
-                    search_bounds(pred.bounds);
                 }
             }
         }
@@ -1026,10 +1021,10 @@ pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'hir>>
     ///
     /// Example:
     ///
-    /// ```
+    /// ```ignore (illustrative)
     /// fn foo<T: Bar + Baz>() { }
-    ///        ^  ^^^^^^^^^ ast_bounds
-    ///        param_ty
+    /// //     ^  ^^^^^^^^^ ast_bounds
+    /// //     param_ty
     /// ```
     ///
     /// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be
@@ -2389,7 +2384,6 @@ fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool
                     bf.unsafety,
                     bf.abi,
                     bf.decl,
-                    &hir::Generics::empty(),
                     None,
                     Some(ast_ty),
                 ))
@@ -2551,8 +2545,7 @@ pub fn ty_of_fn(
         unsafety: hir::Unsafety,
         abi: abi::Abi,
         decl: &hir::FnDecl<'_>,
-        generics: &hir::Generics<'_>,
-        ident_span: Option<Span>,
+        generics: Option<&hir::Generics<'_>>,
         hir_ty: Option<&hir::Ty<'_>>,
     ) -> ty::PolyFnSig<'tcx> {
         debug!("ty_of_fn");
@@ -2565,7 +2558,9 @@ pub fn ty_of_fn(
         let mut visitor = HirPlaceholderCollector::default();
         let mut infer_replacements = vec![];
 
-        walk_generics(&mut visitor, generics);
+        if let Some(generics) = generics {
+            walk_generics(&mut visitor, generics);
+        }
 
         let input_tys: Vec<_> = decl
             .inputs
@@ -2617,8 +2612,7 @@ pub fn ty_of_fn(
 
             let mut diag = crate::collect::placeholder_type_error_diag(
                 tcx,
-                ident_span.map(|sp| sp.shrink_to_hi()),
-                generics.params,
+                generics,
                 visitor.0,
                 infer_replacements.iter().map(|(s, _)| *s).collect(),
                 true,