Skip to content

Commit a8525b6

Browse files
committed
Use IndexSet in lowering.rs
1 parent b964a3a commit a8525b6

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

chalk-integration/src/lowering.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,24 @@ impl Lower for VariableKind {
136136
}
137137

138138
impl LowerWithEnv for [QuantifiedWhereClause] {
139-
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
139+
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
140140

141141
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
142142
self.iter()
143143
.flat_map(|wc| match wc.lower(env) {
144144
Ok(v) => v.into_iter().map(Ok).collect(),
145-
Err(e) => vec![Err(e)],
145+
Err(e) => {
146+
let mut set = IndexSet::new();
147+
set.insert([Err(e)]);
148+
set
149+
}
146150
})
147-
.collect()
151+
.collect::<IndexSet<_>>()
148152
}
149153
}
150154

151155
impl LowerWithEnv for WhereClause {
152-
type Lowered = Vec<chalk_ir::WhereClause<ChalkIr>>;
156+
type Lowered = IndexSet<chalk_ir::WhereClause<ChalkIr>>;
153157

154158
/// Lower from an AST `where` clause to an internal IR.
155159
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -158,37 +162,47 @@ impl LowerWithEnv for WhereClause {
158162
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
159163
Ok(match self {
160164
WhereClause::Implemented { trait_ref } => {
161-
vec![chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?)]
165+
let mut set = IndexSet::new();
166+
set.insert(chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?));
167+
set
168+
}
169+
WhereClause::ProjectionEq { projection, ty } => {
170+
let mut set = IndexSet::new();
171+
set.insert(
172+
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
173+
alias: chalk_ir::AliasTy::Projection(projection.lower(env)?),
174+
ty: ty.lower(env)?,
175+
}),
176+
chalk_ir::WhereClause::Implemented(projection.trait_ref.lower(env)?),
177+
);
178+
set
162179
}
163-
WhereClause::ProjectionEq { projection, ty } => vec![
164-
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
165-
alias: chalk_ir::AliasTy::Projection(projection.lower(env)?),
166-
ty: ty.lower(env)?,
167-
}),
168-
chalk_ir::WhereClause::Implemented(projection.trait_ref.lower(env)?),
169-
],
170180
WhereClause::LifetimeOutlives { a, b } => {
171-
vec![chalk_ir::WhereClause::LifetimeOutlives(
181+
let mut set = IndexSet::new();
182+
set.insert(chalk_ir::WhereClause::LifetimeOutlives(
172183
chalk_ir::LifetimeOutlives {
173184
a: a.lower(env)?,
174185
b: b.lower(env)?,
175186
},
176-
)]
187+
));
188+
set
177189
}
178190
WhereClause::TypeOutlives { ty, lifetime } => {
179-
vec![chalk_ir::WhereClause::TypeOutlives(
191+
let mut set = IndexSet::new();
192+
set.insert(chalk_ir::WhereClause::TypeOutlives(
180193
chalk_ir::TypeOutlives {
181194
ty: ty.lower(env)?,
182195
lifetime: lifetime.lower(env)?,
183196
},
184-
)]
197+
));
198+
set
185199
}
186200
})
187201
}
188202
}
189203

190204
impl LowerWithEnv for QuantifiedWhereClause {
191-
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
205+
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
192206

193207
/// Lower from an AST `where` clause to an internal IR.
194208
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -197,7 +211,7 @@ impl LowerWithEnv for QuantifiedWhereClause {
197211
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
198212
let variable_kinds = self.variable_kinds.iter().map(|k| k.lower());
199213
let binders = env.in_binders(variable_kinds, |env| Ok(self.where_clause.lower(env)?))?;
200-
Ok(binders.into_iter().collect())
214+
Ok(binders.into_iter().collect::<IndexSet<_>>())
201215
}
202216
}
203217

@@ -573,7 +587,7 @@ impl LowerWithEnv for [QuantifiedInlineBound] {
573587
.iter()
574588
.chain(auto_traits.iter())
575589
.map(|(b, _)| b.lower(env))
576-
.collect()
590+
.collect::<IndexSet<_>>()
577591
}
578592
}
579593

0 commit comments

Comments
 (0)