]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/ty/util.rs
fix most compiler/ doctests
[rust.git] / compiler / rustc_middle / src / ty / util.rs
index 39038e85b11a086a52733ca6a542deea4018237a..40e449cf10efc675ee1116b76057e6977c7360ee 100644 (file)
@@ -187,7 +187,7 @@ pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
     /// if input `ty` is not a structure at all.
     pub fn struct_tail_without_normalization(self, ty: Ty<'tcx>) -> Ty<'tcx> {
         let tcx = self;
-        tcx.struct_tail_with_normalize(ty, |ty| ty)
+        tcx.struct_tail_with_normalize(ty, |ty| ty, || {})
     }
 
     /// Returns the deeply last field of nested structures, or the same type if
@@ -203,7 +203,7 @@ pub fn struct_tail_erasing_lifetimes(
         param_env: ty::ParamEnv<'tcx>,
     ) -> Ty<'tcx> {
         let tcx = self;
-        tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty))
+        tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty), || {})
     }
 
     /// Returns the deeply last field of nested structures, or the same type if
@@ -220,6 +220,10 @@ pub fn struct_tail_with_normalize(
         self,
         mut ty: Ty<'tcx>,
         mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
+        // This is currently used to allow us to walk a ValTree
+        // in lockstep with the type in order to get the ValTree branch that
+        // corresponds to an unsized field.
+        mut f: impl FnMut() -> (),
     ) -> Ty<'tcx> {
         let recursion_limit = self.recursion_limit();
         for iteration in 0.. {
@@ -235,12 +239,16 @@ pub fn struct_tail_with_normalize(
                         break;
                     }
                     match def.non_enum_variant().fields.last() {
-                        Some(f) => ty = f.ty(self, substs),
+                        Some(field) => {
+                            f();
+                            ty = field.ty(self, substs);
+                        }
                         None => break,
                     }
                 }
 
                 ty::Tuple(tys) if let Some((&last_ty, _)) = tys.split_last() => {
+                    f();
                     ty = last_ty;
                 }
 
@@ -967,7 +975,7 @@ impl<'tcx> ExplicitSelf<'tcx> {
     ///
     /// Examples:
     ///
-    /// ```
+    /// ```ignore (illustrative)
     /// impl<'a> Foo for &'a T {
     ///     // Legal declarations:
     ///     fn method1(self: &&'a T); // ExplicitSelf::ByReference