@@ -9,6 +9,7 @@ use chalk_ir::{
99use chalk_parse:: ast:: * ;
1010use chalk_solve:: rust_ir:: { self , IntoWhereClauses } ;
1111use indexmap:: IndexMap ;
12+ use indexmap:: IndexSet ;
1213use program_lowerer:: ProgramLowerer ;
1314use string_cache:: DefaultAtom as Atom ;
1415use tracing:: debug;
@@ -53,7 +54,7 @@ impl Lower for Program {
5354trait LowerParameterMap {
5455 fn synthetic_parameters ( & self ) -> Option < chalk_ir:: WithKind < ChalkIr , Ident > > ;
5556 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 > > {
5758 self . synthetic_parameters ( )
5859 . into_iter ( )
5960 . chain ( self . declared_parameters ( ) . iter ( ) . map ( |id| id. lower ( ) ) )
@@ -136,7 +137,7 @@ impl Lower for VariableKind {
136137}
137138
138139impl LowerWithEnv for [ QuantifiedWhereClause ] {
139- type Lowered = Vec < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
140+ type Lowered = IndexSet < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
140141
141142 fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
142143 self . iter ( )
@@ -149,7 +150,7 @@ impl LowerWithEnv for [QuantifiedWhereClause] {
149150}
150151
151152impl LowerWithEnv for WhereClause {
152- type Lowered = Vec < chalk_ir:: WhereClause < ChalkIr > > ;
153+ type Lowered = IndexSet < chalk_ir:: WhereClause < ChalkIr > > ;
153154
154155 /// Lower from an AST `where` clause to an internal IR.
155156 /// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -158,37 +159,47 @@ impl LowerWithEnv for WhereClause {
158159 fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
159160 Ok ( match self {
160161 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
162165 }
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 {
165169 alias : chalk_ir:: AliasTy :: Projection ( projection. lower ( env) ?) ,
166170 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+ }
170177 WhereClause :: LifetimeOutlives { a, b } => {
171- vec ! [ chalk_ir:: WhereClause :: LifetimeOutlives (
178+ let mut set = IndexSet :: new ( ) ;
179+ set. insert ( chalk_ir:: WhereClause :: LifetimeOutlives (
172180 chalk_ir:: LifetimeOutlives {
173181 a : a. lower ( env) ?,
174182 b : b. lower ( env) ?,
175183 } ,
176- ) ]
184+ ) ) ;
185+ set
177186 }
178187 WhereClause :: TypeOutlives { ty, lifetime } => {
179- vec ! [ chalk_ir:: WhereClause :: TypeOutlives (
188+ let mut set = IndexSet :: new ( ) ;
189+ set. insert ( chalk_ir:: WhereClause :: TypeOutlives (
180190 chalk_ir:: TypeOutlives {
181191 ty : ty. lower ( env) ?,
182192 lifetime : lifetime. lower ( env) ?,
183193 } ,
184- ) ]
194+ ) ) ;
195+ set
185196 }
186197 } )
187198 }
188199}
189200
190201impl LowerWithEnv for QuantifiedWhereClause {
191- type Lowered = Vec < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
202+ type Lowered = IndexSet < chalk_ir:: QuantifiedWhereClause < ChalkIr > > ;
192203
193204 /// Lower from an AST `where` clause to an internal IR.
194205 /// 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>) {
298309 Ok ( rust_ir:: AdtVariantDatum { fields : fields? } )
299310 } )
300311 . 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 < _ > > ( ) ,
302317 } )
303318 } ) ?;
304319
@@ -340,7 +355,11 @@ impl LowerWithEnv for (&FnDefn, chalk_ir::FnDefId<ChalkIr>) {
340355 let ( fn_defn, fn_def_id) = self ;
341356
342357 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 < _ > > ( ) ;
344363
345364 let inputs_and_output = env. in_binders ( vec ! [ ] , |env| {
346365 let args: LowerResult < _ > = fn_defn
@@ -542,7 +561,7 @@ impl LowerWithEnv for QuantifiedInlineBound {
542561}
543562
544563impl LowerWithEnv for [ QuantifiedInlineBound ] {
545- type Lowered = Vec < rust_ir:: QuantifiedInlineBound < ChalkIr > > ;
564+ type Lowered = IndexSet < rust_ir:: QuantifiedInlineBound < ChalkIr > > ;
546565
547566 fn lower ( & self , env : & Env ) -> LowerResult < Self :: Lowered > {
548567 fn trait_identifier ( bound : & InlineBound ) -> & Identifier {
@@ -899,7 +918,11 @@ impl LowerWithEnv for (&Impl, ImplId<ChalkIr>, &AssociatedTyValueIds) {
899918 ) ) ?;
900919 }
901920
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 < _ > > ( ) ;
903926 debug ! ( where_clauses = ?trait_ref) ;
904927 Ok ( rust_ir:: ImplDatumBound {
905928 trait_ref,
@@ -986,7 +1009,11 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {
9861009 }
9871010
9881011 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 < _ > > ( ) ,
9901017 } )
9911018 } ) ?;
9921019
0 commit comments