diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index be1582066e3..a81c3a177f8 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -654,11 +654,12 @@ impl<'a, 'tcx> ty::TyS<'tcx> { } tcx.layout_depth.set(depth+1); - let layout = Layout::compute_uncached(self, infcx)?; + let layout = Layout::compute_uncached(self, infcx); + tcx.layout_depth.set(depth); + let layout = layout?; if can_cache { tcx.layout_cache.borrow_mut().insert(self, layout); } - tcx.layout_depth.set(depth); Ok(layout) }