Skip to content

Commit 380d331

Browse files
Don't fold ExternalConstraintsData when it's empty
1 parent fd50e10 commit 380d331

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/rustc_middle/src/traits/solve.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
4949
self,
5050
folder: &mut F,
5151
) -> Result<Self, F::Error> {
52+
if self.is_empty() {
53+
return Ok(self);
54+
}
55+
5256
Ok(FallibleTypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData {
5357
region_constraints: self.region_constraints.clone().try_fold_with(folder)?,
5458
opaque_types: self
@@ -64,6 +68,10 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
6468
}
6569

6670
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
71+
if self.is_empty() {
72+
return self;
73+
}
74+
6775
TypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData {
6876
region_constraints: self.region_constraints.clone().fold_with(folder),
6977
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ pub struct ExternalConstraintsData<I: Interner> {
236236
pub normalization_nested_goals: NestedNormalizationGoals<I>,
237237
}
238238

239+
impl<I: Interner> ExternalConstraintsData<I> {
240+
pub fn is_empty(&self) -> bool {
241+
self.region_constraints.is_empty()
242+
&& self.opaque_types.is_empty()
243+
&& self.normalization_nested_goals.is_empty()
244+
}
245+
}
246+
239247
#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)]
240248
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
241249
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]

0 commit comments

Comments
 (0)