Skip to content

Commit 27c7947

Browse files
committed
support upcasting from any U: Upcast<T>
1 parent ae194f9 commit 27c7947

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/formality-core/src/collections.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ tuple_upcast!(Vec: A, B, C, D);
159159
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
160160
pub struct Cons<T, C>(pub T, pub C);
161161

162-
impl<T> UpcastFrom<Cons<T, Set<T>>> for Set<T>
162+
impl<T, U> UpcastFrom<Cons<U, Set<T>>> for Set<T>
163163
where
164164
T: Ord + Clone,
165+
U: Upcast<T>,
165166
{
166-
fn upcast_from(term: Cons<T, Set<T>>) -> Self {
167+
fn upcast_from(term: Cons<U, Set<T>>) -> Self {
167168
let Cons(elem, mut set) = term;
168-
set.insert(elem);
169+
set.insert(elem.upcast());
169170
set
170171
}
171172
}
@@ -185,13 +186,14 @@ where
185186
}
186187
}
187188

188-
impl<T> UpcastFrom<Cons<T, Vec<T>>> for Vec<T>
189+
impl<T, U> UpcastFrom<Cons<U, Vec<T>>> for Vec<T>
189190
where
190191
T: Ord + Clone,
192+
U: Upcast<T>,
191193
{
192-
fn upcast_from(term: Cons<T, Vec<T>>) -> Self {
194+
fn upcast_from(term: Cons<U, Vec<T>>) -> Self {
193195
let Cons(elem, mut vec) = term;
194-
vec.insert(0, elem);
196+
vec.insert(0, elem.upcast());
195197
vec
196198
}
197199
}

0 commit comments

Comments
 (0)