@@ -9,6 +9,7 @@ use chalk_ir::{
9
9
use chalk_parse:: ast:: * ;
10
10
use chalk_solve:: rust_ir:: { self , IntoWhereClauses } ;
11
11
use indexmap:: IndexMap ;
12
+ use indexmap:: IndexSet ;
12
13
use program_lowerer:: ProgramLowerer ;
13
14
use string_cache:: DefaultAtom as Atom ;
14
15
use tracing:: debug;
@@ -53,7 +54,7 @@ impl Lower for Program {
53
54
trait LowerParameterMap {
54
55
fn synthetic_parameters ( & self ) -> Option < chalk_ir:: WithKind < ChalkIr , Ident > > ;
55
56
fn declared_parameters ( & self ) -> & [ VariableKind ] ;
56
- fn all_parameters ( & self ) -> Vec < chalk_ir:: WithKind < ChalkIr , Ident > > {
57
+ fn all_parameters ( & self ) -> indexmap :: IndexSet < chalk_ir:: WithKind < ChalkIr , Ident > > {
57
58
self . synthetic_parameters ( )
58
59
. into_iter ( )
59
60
. chain ( self . declared_parameters ( ) . iter ( ) . map ( |id| id. lower ( ) ) )
@@ -136,7 +137,7 @@ impl Lower for VariableKind {
136
137
}
137
138
138
139
impl LowerWithEnv for [ QuantifiedWhereClause ] {
139
- type Lowered = Vec < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
140
+ type Lowered = IndexSet < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
140
141
141
142
fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
142
143
self . iter ( )
@@ -149,7 +150,7 @@ impl LowerWithEnv for [QuantifiedWhereClause] {
149
150
}
150
151
151
152
impl LowerWithEnv for WhereClause {
152
- type Lowered = Vec < chalk_ir:: WhereClause < ChalkIr > > ;
153
+ type Lowered = IndexSet < chalk_ir:: WhereClause < ChalkIr > > ;
153
154
154
155
/// Lower from an AST `where` clause to an internal IR.
155
156
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -158,37 +159,47 @@ impl LowerWithEnv for WhereClause {
158
159
fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
159
160
Ok ( match self {
160
161
WhereClause :: Implemented { trait_ref } => {
161
- vec ! [ chalk_ir:: WhereClause :: Implemented ( trait_ref. lower( env) ?) ]
162
+ let mut set = IndexSet :: new ( ) ;
163
+ set. insert ( chalk_ir:: WhereClause :: Implemented ( trait_ref. lower ( env) ?) ) ;
164
+ set
162
165
}
163
- WhereClause :: ProjectionEq { projection, ty } => vec ! [
164
- chalk_ir:: WhereClause :: AliasEq ( chalk_ir:: AliasEq {
166
+ WhereClause :: ProjectionEq { projection, ty } => {
167
+ let mut set = IndexSet :: new ( ) ;
168
+ set. insert ( chalk_ir:: WhereClause :: AliasEq ( chalk_ir:: AliasEq {
165
169
alias : chalk_ir:: AliasTy :: Projection ( projection. lower ( env) ?) ,
166
170
ty : ty. lower ( env) ?,
167
- } ) ,
168
- chalk_ir:: WhereClause :: Implemented ( projection. trait_ref. lower( env) ?) ,
169
- ] ,
171
+ } ) ) ;
172
+ set. insert ( chalk_ir:: WhereClause :: Implemented (
173
+ projection. trait_ref . lower ( env) ?,
174
+ ) ) ;
175
+ set
176
+ }
170
177
WhereClause :: LifetimeOutlives { a, b } => {
171
- vec ! [ chalk_ir:: WhereClause :: LifetimeOutlives (
178
+ let mut set = IndexSet :: new ( ) ;
179
+ set. insert ( chalk_ir:: WhereClause :: LifetimeOutlives (
172
180
chalk_ir:: LifetimeOutlives {
173
181
a : a. lower ( env) ?,
174
182
b : b. lower ( env) ?,
175
183
} ,
176
- ) ]
184
+ ) ) ;
185
+ set
177
186
}
178
187
WhereClause :: TypeOutlives { ty, lifetime } => {
179
- vec ! [ chalk_ir:: WhereClause :: TypeOutlives (
188
+ let mut set = IndexSet :: new ( ) ;
189
+ set. insert ( chalk_ir:: WhereClause :: TypeOutlives (
180
190
chalk_ir:: TypeOutlives {
181
191
ty : ty. lower ( env) ?,
182
192
lifetime : lifetime. lower ( env) ?,
183
193
} ,
184
- ) ]
194
+ ) ) ;
195
+ set
185
196
}
186
197
} )
187
198
}
188
199
}
189
200
190
201
impl LowerWithEnv for QuantifiedWhereClause {
191
- type Lowered = Vec < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
202
+ type Lowered = IndexSet < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
192
203
193
204
/// Lower from an AST `where` clause to an internal IR.
194
205
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -298,7 +309,11 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
298
309
Ok ( rust_ir:: AdtVariantDatum { fields : fields? } )
299
310
} )
300
311
. collect :: < LowerResult < _ > > ( ) ?,
301
- where_clauses : adt_defn. where_clauses . lower ( env) ?,
312
+ where_clauses : adt_defn
313
+ . where_clauses
314
+ . lower ( env) ?
315
+ . into_iter ( )
316
+ . collect :: < Vec < _ > > ( ) ,
302
317
} )
303
318
} ) ?;
304
319
@@ -340,7 +355,11 @@ impl LowerWithEnv for (&FnDefn, chalk_ir::FnDefId<ChalkIr>) {
340
355
let ( fn_defn, fn_def_id) = self ;
341
356
342
357
let binders = env. in_binders ( fn_defn. all_parameters ( ) , |env| {
343
- let where_clauses = fn_defn. where_clauses . lower ( env) ?;
358
+ let where_clauses = fn_defn
359
+ . where_clauses
360
+ . lower ( env) ?
361
+ . into_iter ( )
362
+ . collect :: < Vec < _ > > ( ) ;
344
363
345
364
let inputs_and_output = env. in_binders ( vec ! [ ] , |env| {
346
365
let args: LowerResult < _ > = fn_defn
@@ -542,7 +561,7 @@ impl LowerWithEnv for QuantifiedInlineBound {
542
561
}
543
562
544
563
impl LowerWithEnv for [ QuantifiedInlineBound ] {
545
- type Lowered = Vec < rust_ir:: QuantifiedInlineBound < ChalkIr > > ;
564
+ type Lowered = IndexSet < rust_ir:: QuantifiedInlineBound < ChalkIr > > ;
546
565
547
566
fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
548
567
fn trait_identifier ( bound : & InlineBound ) -> & Identifier {
@@ -899,7 +918,11 @@ impl LowerWithEnv for (&Impl, ImplId<ChalkIr>, &AssociatedTyValueIds) {
899
918
) ) ?;
900
919
}
901
920
902
- let where_clauses = impl_. where_clauses . lower ( & env) ?;
921
+ let where_clauses = impl_
922
+ . where_clauses
923
+ . lower ( & env) ?
924
+ . into_iter ( )
925
+ . collect :: < Vec < _ > > ( ) ;
903
926
debug ! ( where_clauses = ?trait_ref) ;
904
927
Ok ( rust_ir:: ImplDatumBound {
905
928
trait_ref,
@@ -986,7 +1009,11 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {
986
1009
}
987
1010
988
1011
Ok ( rust_ir:: TraitDatumBound {
989
- where_clauses : trait_defn. where_clauses . lower ( env) ?,
1012
+ where_clauses : trait_defn
1013
+ . where_clauses
1014
+ . lower ( env) ?
1015
+ . into_iter ( )
1016
+ . collect :: < Vec < _ > > ( ) ,
990
1017
} )
991
1018
} ) ?;
992
1019
0 commit comments