diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index c6ecb08615fcf..aa47c6b70a21a 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -1019,7 +1019,11 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> { fn super_fold_with>(&self, folder: &mut F) -> Self { let ty = self.ty.fold_with(folder); let val = self.val.fold_with(folder); - folder.tcx().mk_const(ty::Const { ty, val }) + if ty != self.ty || val != self.val { + folder.tcx().mk_const(ty::Const { ty, val }) + } else { + *self + } } fn fold_with>(&self, folder: &mut F) -> Self {