Skip to content

Commit 529f5f9

Browse files
nikomatsakisNiko Matsakis
authored andcommitted
generalize cons upcast even further
1 parent 6598f7a commit 529f5f9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/formality-core/src/collections.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ tuple_upcast!(Vec: A, B, C, D);
187187
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
188188
pub struct Cons<T, C>(pub T, pub C);
189189

190-
impl<T, U, V> UpcastFrom<Cons<U, Set<V>>> for Set<T>
190+
impl<T, U, V> UpcastFrom<Cons<U, V>> for Set<T>
191191
where
192192
T: Ord + Clone,
193193
U: Upcast<T>,
194-
V: Ord + Upcast<T>,
194+
V: Upcast<Set<T>>,
195195
{
196-
fn upcast_from(term: Cons<U, Set<V>>) -> Self {
196+
fn upcast_from(term: Cons<U, V>) -> Self {
197197
let Cons(elem, set) = term;
198198
let mut set: Set<T> = set.upcast();
199199
set.insert(elem.upcast());
@@ -216,16 +216,16 @@ where
216216
}
217217
}
218218

219-
impl<T, U, V> UpcastFrom<Cons<U, Vec<V>>> for Vec<T>
219+
impl<T, U, V> UpcastFrom<Cons<U, V>> for Vec<T>
220220
where
221221
U: Upcast<T>,
222-
V: Upcast<T>,
222+
V: Upcast<Vec<T>>,
223223
{
224-
fn upcast_from(term: Cons<U, Vec<V>>) -> Self {
224+
fn upcast_from(term: Cons<U, V>) -> Self {
225225
let Cons(elem, vec) = term;
226-
std::iter::once(elem.upcast())
227-
.chain(vec.into_iter().upcasted())
228-
.collect()
226+
let mut vec: Vec<T> = vec.upcast();
227+
vec.insert(0, elem.upcast());
228+
vec
229229
}
230230
}
231231

0 commit comments

Comments
 (0)