@@ -163,6 +163,55 @@ pub fn push_auto_trait_impls_opaque<I: Interner>(
163163 } ) ;
164164}
165165
166+ #[ instrument( level = "debug" , skip( builder) ) ]
167+ pub fn push_auto_trait_impls_generator < I : Interner > (
168+ builder : & mut ClauseBuilder < ' _ , I > ,
169+ auto_trait_id : TraitId < I > ,
170+ generator_id : GeneratorId < I > ,
171+ ) {
172+ let generator_datum = builder. db . generator_datum ( generator_id) ;
173+ let interner = builder. interner ( ) ;
174+
175+ // Must be an auto trait.
176+ assert ! ( builder. db. trait_datum( auto_trait_id) . is_auto_trait( ) ) ;
177+
178+ // Auto traits never have generic parameters of their own (apart from `Self`).
179+ assert_eq ! (
180+ builder. db. trait_datum( auto_trait_id) . binders. len( interner) ,
181+ 1
182+ ) ;
183+
184+ builder. push_binders ( & generator_datum. input_output , |builder, input_output| {
185+ let self_ty: Ty < _ > = ApplicationTy {
186+ name : generator_id. cast ( interner) ,
187+ substitution : builder. substitution_in_scope ( ) ,
188+ }
189+ . intern ( interner) ;
190+
191+ // trait_ref = `Generator<...>: MyAutoTrait`
192+ let auto_trait_ref = TraitRef {
193+ trait_id : auto_trait_id,
194+ substitution : Substitution :: from1 ( interner, self_ty) ,
195+ } ;
196+
197+ debug ! ( "input output: {:?}" , generator_datum. input_output) ;
198+
199+ // forall<P0..Pn> { // generic parameters from struct
200+ // MyStruct<...>: MyAutoTrait :-
201+ // Field0: MyAutoTrait,
202+ // ...
203+ // FieldN: MyAutoTrait
204+ // }
205+ builder. push_clause (
206+ auto_trait_ref,
207+ input_output. upvars . iter ( ) . map ( |upvar_ty| TraitRef {
208+ trait_id : auto_trait_id,
209+ substitution : Substitution :: from1 ( interner, upvar_ty. clone ( ) ) ,
210+ } ) ,
211+ ) ;
212+ } ) ;
213+ }
214+
166215/// Given some goal `goal` that must be proven, along with
167216/// its `environment`, figures out the program clauses that apply
168217/// to this goal from the Rust program. So for example if the goal
@@ -249,6 +298,9 @@ fn program_clauses_that_could_match<I: Interner>(
249298 TypeName :: Adt ( adt_id) => {
250299 push_auto_trait_impls ( builder, trait_id, * adt_id) ;
251300 }
301+ TypeName :: Generator ( generator_id) => {
302+ push_auto_trait_impls_generator ( builder, trait_id, * generator_id) ;
303+ }
252304 _ => { }
253305 } ,
254306 TyData :: InferenceVar ( _, _) | TyData :: BoundVar ( _) => {
0 commit comments