Skip to content

Commit 85c8e81

Browse files
committed
reduce diff to tuple.rs
1 parent 4684773 commit 85c8e81

File tree

1 file changed

+17
-23
lines changed
  • crates/ty_python_semantic/src/types

1 file changed

+17
-23
lines changed

crates/ty_python_semantic/src/types/tuple.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ impl<T> Tuple<T> {
938938
pub(crate) fn from_elements(elements: impl IntoIterator<Item = T>) -> Tuple<T> {
939939
FixedLengthTuple::from_elements(elements).into()
940940
}
941+
941942
pub(crate) fn with_capacity(capacity: usize) -> Self {
942943
Tuple::Fixed(FixedLengthTuple::with_capacity(capacity))
943944
}
@@ -1097,42 +1098,40 @@ impl<'db> Tuple<Type<'db>> {
10971098

10981099
// If any of the required elements are pairwise disjoint, the tuples are disjoint as well.
10991100
#[allow(clippy::items_after_statements)]
1100-
fn any_disjoint<'db>(
1101+
fn any_disjoint<'s, 'db>(
11011102
db: &'db dyn Db,
1102-
a: impl IntoIterator<Item = Type<'db>>,
1103-
b: impl IntoIterator<Item = Type<'db>>,
1103+
a: impl IntoIterator<Item = &'s Type<'db>>,
1104+
b: impl IntoIterator<Item = &'s Type<'db>>,
11041105
visitor: &mut PairVisitor<'db>,
1105-
) -> bool {
1106+
) -> bool
1107+
where
1108+
'db: 's,
1109+
{
11061110
a.into_iter().zip(b).any(|(self_element, other_element)| {
1107-
self_element.is_disjoint_from_impl(db, other_element, visitor)
1111+
self_element.is_disjoint_from_impl(db, *other_element, visitor)
11081112
})
11091113
}
11101114

11111115
match (self, other) {
11121116
(Tuple::Fixed(self_tuple), Tuple::Fixed(other_tuple)) => {
1113-
if any_disjoint(
1114-
db,
1115-
self_tuple.elements().copied(),
1116-
other_tuple.elements().copied(),
1117-
visitor,
1118-
) {
1117+
if any_disjoint(db, self_tuple.elements(), other_tuple.elements(), visitor) {
11191118
return true;
11201119
}
11211120
}
11221121

11231122
(Tuple::Variable(self_tuple), Tuple::Variable(other_tuple)) => {
11241123
if any_disjoint(
11251124
db,
1126-
self_tuple.prefix_elements().copied(),
1127-
other_tuple.prefix_elements().copied(),
1125+
self_tuple.prefix_elements(),
1126+
other_tuple.prefix_elements(),
11281127
visitor,
11291128
) {
11301129
return true;
11311130
}
11321131
if any_disjoint(
11331132
db,
1134-
self_tuple.suffix_elements().rev().copied(),
1135-
other_tuple.suffix_elements().rev().copied(),
1133+
self_tuple.suffix_elements().rev(),
1134+
other_tuple.suffix_elements().rev(),
11361135
visitor,
11371136
) {
11381137
return true;
@@ -1141,18 +1140,13 @@ impl<'db> Tuple<Type<'db>> {
11411140

11421141
(Tuple::Fixed(fixed), Tuple::Variable(variable))
11431142
| (Tuple::Variable(variable), Tuple::Fixed(fixed)) => {
1144-
if any_disjoint(
1145-
db,
1146-
fixed.elements().copied(),
1147-
variable.prefix_elements().copied(),
1148-
visitor,
1149-
) {
1143+
if any_disjoint(db, fixed.elements(), variable.prefix_elements(), visitor) {
11501144
return true;
11511145
}
11521146
if any_disjoint(
11531147
db,
1154-
fixed.elements().rev().copied(),
1155-
variable.suffix_elements().rev().copied(),
1148+
fixed.elements().rev(),
1149+
variable.suffix_elements().rev(),
11561150
visitor,
11571151
) {
11581152
return true;

0 commit comments

Comments
 (0)