From ea44ce059b9f10394a08e369cd856192984d0ca0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 22 Mar 2024 12:18:08 +0000 Subject: [PATCH] Make `Canonical` trait impls more robust --- compiler/rustc_type_ir/src/canonical.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index ad18ef249842..3da74f9fe6e7 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -63,28 +63,30 @@ impl Eq for Canonical {} impl PartialEq for Canonical { fn eq(&self, other: &Self) -> bool { - self.value == other.value - && self.max_universe == other.max_universe - && self.variables == other.variables + let Self { value, max_universe, variables } = self; + *value == other.value + && *max_universe == other.max_universe + && *variables == other.variables } } impl fmt::Display for Canonical { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Self { value, max_universe, variables } = self; write!( f, - "Canonical {{ value: {}, max_universe: {:?}, variables: {:?} }}", - self.value, self.max_universe, self.variables + "Canonical {{ value: {value}, max_universe: {max_universe:?}, variables: {variables:?} }}", ) } } impl fmt::Debug for Canonical { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Self { value, max_universe, variables } = self; f.debug_struct("Canonical") - .field("value", &self.value) - .field("max_universe", &self.max_universe) - .field("variables", &self.variables) + .field("value", &value) + .field("max_universe", &max_universe) + .field("variables", &variables) .finish() } } @@ -109,9 +111,10 @@ where I::CanonicalVars: TypeVisitable, { fn visit_with>(&self, folder: &mut F) -> F::Result { - try_visit!(self.value.visit_with(folder)); - try_visit!(self.max_universe.visit_with(folder)); - self.variables.visit_with(folder) + let Self { value, max_universe, variables } = self; + try_visit!(value.visit_with(folder)); + try_visit!(max_universe.visit_with(folder)); + variables.visit_with(folder) } }