]> git.lizzy.rs Git - rust.git/commitdiff
generalize: no need to cache errors
authorlcnr <rust@lcnr.de>
Mon, 4 Jul 2022 13:35:21 +0000 (15:35 +0200)
committerlcnr <rust@lcnr.de>
Thu, 8 Sep 2022 09:14:33 +0000 (11:14 +0200)
compiler/rustc_infer/src/infer/combine.rs

index d4350aa5734dee4aefe5583a5f1e6233d0cf2303..644c92ed0e54876da09c29957cc07c93aed1967e 100644 (file)
@@ -486,7 +486,7 @@ struct Generalizer<'cx, 'tcx> {
 
     param_env: ty::ParamEnv<'tcx>,
 
-    cache: SsoHashMap<Ty<'tcx>, RelateResult<'tcx, Ty<'tcx>>>,
+    cache: SsoHashMap<Ty<'tcx>, Ty<'tcx>>,
 }
 
 /// Result from a generalization operation. This includes
@@ -593,8 +593,8 @@ fn relate_with_variance<T: Relate<'tcx>>(
     fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
         assert_eq!(t, t2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
 
-        if let Some(result) = self.cache.get(&t) {
-            return result.clone();
+        if let Some(&result) = self.cache.get(&t) {
+            return Ok(result);
         }
         debug!("generalize: t={:?}", t);
 
@@ -664,10 +664,10 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
                 Ok(t)
             }
             _ => relate::super_relate_tys(self, t, t),
-        };
+        }?;
 
-        self.cache.insert(t, result.clone());
-        return result;
+        self.cache.insert(t, result);
+        Ok(result)
     }
 
     fn regions(