Skip to content

Commit ea44ce0

Browse files
committed
Make Canonical trait impls more robust
1 parent 0689a4f commit ea44ce0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

compiler/rustc_type_ir/src/canonical.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,30 @@ impl<I: Interner, V: Eq> Eq for Canonical<I, V> {}
6363

6464
impl<I: Interner, V: PartialEq> PartialEq for Canonical<I, V> {
6565
fn eq(&self, other: &Self) -> bool {
66-
self.value == other.value
67-
&& self.max_universe == other.max_universe
68-
&& self.variables == other.variables
66+
let Self { value, max_universe, variables } = self;
67+
*value == other.value
68+
&& *max_universe == other.max_universe
69+
&& *variables == other.variables
6970
}
7071
}
7172

7273
impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
7374
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75+
let Self { value, max_universe, variables } = self;
7476
write!(
7577
f,
76-
"Canonical {{ value: {}, max_universe: {:?}, variables: {:?} }}",
77-
self.value, self.max_universe, self.variables
78+
"Canonical {{ value: {value}, max_universe: {max_universe:?}, variables: {variables:?} }}",
7879
)
7980
}
8081
}
8182

8283
impl<I: Interner, V: fmt::Debug> fmt::Debug for Canonical<I, V> {
8384
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85+
let Self { value, max_universe, variables } = self;
8486
f.debug_struct("Canonical")
85-
.field("value", &self.value)
86-
.field("max_universe", &self.max_universe)
87-
.field("variables", &self.variables)
87+
.field("value", &value)
88+
.field("max_universe", &max_universe)
89+
.field("variables", &variables)
8890
.finish()
8991
}
9092
}
@@ -109,9 +111,10 @@ where
109111
I::CanonicalVars: TypeVisitable<I>,
110112
{
111113
fn visit_with<F: TypeVisitor<I>>(&self, folder: &mut F) -> F::Result {
112-
try_visit!(self.value.visit_with(folder));
113-
try_visit!(self.max_universe.visit_with(folder));
114-
self.variables.visit_with(folder)
114+
let Self { value, max_universe, variables } = self;
115+
try_visit!(value.visit_with(folder));
116+
try_visit!(max_universe.visit_with(folder));
117+
variables.visit_with(folder)
115118
}
116119
}
117120

0 commit comments

Comments
 (0)