@@ -35,6 +35,24 @@ fn coerce_pointee_new_type_param(trait_id: TraitId) -> TypeParamId {
3535 } )
3636}
3737
38+ fn trait_args ( trait_ : BuiltinDeriveImplTrait , self_ty : Ty < ' _ > ) -> GenericArgs < ' _ > {
39+ match trait_ {
40+ BuiltinDeriveImplTrait :: Copy
41+ | BuiltinDeriveImplTrait :: Clone
42+ | BuiltinDeriveImplTrait :: Default
43+ | BuiltinDeriveImplTrait :: Debug
44+ | BuiltinDeriveImplTrait :: Hash
45+ | BuiltinDeriveImplTrait :: Eq
46+ | BuiltinDeriveImplTrait :: Ord => GenericArgs :: new_from_slice ( & [ self_ty. into ( ) ] ) ,
47+ BuiltinDeriveImplTrait :: PartialOrd | BuiltinDeriveImplTrait :: PartialEq => {
48+ GenericArgs :: new_from_slice ( & [ self_ty. into ( ) , self_ty. into ( ) ] )
49+ }
50+ BuiltinDeriveImplTrait :: CoerceUnsized | BuiltinDeriveImplTrait :: DispatchFromDyn => {
51+ panic ! ( "`CoerceUnsized` and `DispatchFromDyn` have special generics" )
52+ }
53+ }
54+ }
55+
3856pub ( crate ) fn generics_of < ' db > ( interner : DbInterner < ' db > , id : BuiltinDeriveImplId ) -> Generics {
3957 let db = interner. db ;
4058 let loc = id. loc ( db) ;
@@ -95,21 +113,19 @@ pub fn impl_trait<'db>(
95113 | BuiltinDeriveImplTrait :: Debug
96114 | BuiltinDeriveImplTrait :: Hash
97115 | BuiltinDeriveImplTrait :: Ord
98- | BuiltinDeriveImplTrait :: Eq => {
116+ | BuiltinDeriveImplTrait :: Eq
117+ | BuiltinDeriveImplTrait :: PartialOrd
118+ | BuiltinDeriveImplTrait :: PartialEq => {
99119 let self_ty = Ty :: new_adt (
100120 interner,
101121 loc. adt ,
102122 GenericArgs :: identity_for_item ( interner, loc. adt . into ( ) ) ,
103123 ) ;
104- EarlyBinder :: bind ( TraitRef :: new ( interner, trait_id. into ( ) , [ self_ty] ) )
105- }
106- BuiltinDeriveImplTrait :: PartialOrd | BuiltinDeriveImplTrait :: PartialEq => {
107- let self_ty = Ty :: new_adt (
124+ EarlyBinder :: bind ( TraitRef :: new_from_args (
108125 interner,
109- loc. adt ,
110- GenericArgs :: identity_for_item ( interner, loc. adt . into ( ) ) ,
111- ) ;
112- EarlyBinder :: bind ( TraitRef :: new ( interner, trait_id. into ( ) , [ self_ty, self_ty] ) )
126+ trait_id. into ( ) ,
127+ trait_args ( loc. trait_ , self_ty) ,
128+ ) )
113129 }
114130 BuiltinDeriveImplTrait :: CoerceUnsized | BuiltinDeriveImplTrait :: DispatchFromDyn => {
115131 let generic_params = GenericParams :: new ( db, loc. adt . into ( ) ) ;
@@ -260,21 +276,7 @@ fn simple_trait_predicates<'db>(
260276 let param_idx =
261277 param_idx. into_raw ( ) . into_u32 ( ) + ( generic_params. len_lifetimes ( ) as u32 ) ;
262278 let param_ty = Ty :: new_param ( interner, param_id, param_idx) ;
263- let trait_args = match loc. trait_ {
264- BuiltinDeriveImplTrait :: Copy
265- | BuiltinDeriveImplTrait :: Clone
266- | BuiltinDeriveImplTrait :: Default
267- | BuiltinDeriveImplTrait :: Debug
268- | BuiltinDeriveImplTrait :: Hash
269- | BuiltinDeriveImplTrait :: Ord
270- | BuiltinDeriveImplTrait :: Eq => GenericArgs :: new_from_slice ( & [ param_ty. into ( ) ] ) ,
271- BuiltinDeriveImplTrait :: PartialOrd | BuiltinDeriveImplTrait :: PartialEq => {
272- GenericArgs :: new_from_slice ( & [ param_ty. into ( ) , param_ty. into ( ) ] )
273- }
274- BuiltinDeriveImplTrait :: CoerceUnsized | BuiltinDeriveImplTrait :: DispatchFromDyn => {
275- unreachable ! ( )
276- }
277- } ;
279+ let trait_args = trait_args ( loc. trait_ , param_ty) ;
278280 let trait_ref = TraitRef :: new_from_args ( interner, trait_id. into ( ) , trait_args) ;
279281 trait_ref. upcast ( interner)
280282 } ) ;
@@ -285,12 +287,14 @@ fn simple_trait_predicates<'db>(
285287 & mut assoc_type_bounds,
286288 interner. db . field_types ( id. into ( ) ) ,
287289 trait_id,
290+ loc. trait_ ,
288291 ) ,
289292 AdtId :: UnionId ( id) => extend_assoc_type_bounds (
290293 interner,
291294 & mut assoc_type_bounds,
292295 interner. db . field_types ( id. into ( ) ) ,
293296 trait_id,
297+ loc. trait_ ,
294298 ) ,
295299 AdtId :: EnumId ( id) => {
296300 for & ( variant_id, _, _) in & id. enum_variants ( interner. db ) . variants {
@@ -299,6 +303,7 @@ fn simple_trait_predicates<'db>(
299303 & mut assoc_type_bounds,
300304 interner. db . field_types ( variant_id. into ( ) ) ,
301305 trait_id,
306+ loc. trait_ ,
302307 )
303308 }
304309 }
@@ -320,12 +325,14 @@ fn extend_assoc_type_bounds<'db>(
320325 interner : DbInterner < ' db > ,
321326 assoc_type_bounds : & mut Vec < Clause < ' db > > ,
322327 fields : & ArenaMap < LocalFieldId , StoredEarlyBinder < StoredTy > > ,
323- trait_ : TraitId ,
328+ trait_id : TraitId ,
329+ trait_ : BuiltinDeriveImplTrait ,
324330) {
325331 struct ProjectionFinder < ' a , ' db > {
326332 interner : DbInterner < ' db > ,
327333 assoc_type_bounds : & ' a mut Vec < Clause < ' db > > ,
328- trait_ : TraitId ,
334+ trait_id : TraitId ,
335+ trait_ : BuiltinDeriveImplTrait ,
329336 }
330337
331338 impl < ' db > TypeVisitor < DbInterner < ' db > > for ProjectionFinder < ' _ , ' db > {
@@ -334,15 +341,20 @@ fn extend_assoc_type_bounds<'db>(
334341 fn visit_ty ( & mut self , t : Ty < ' db > ) -> Self :: Result {
335342 if let TyKind :: Alias ( AliasTyKind :: Projection , _) = t. kind ( ) {
336343 self . assoc_type_bounds . push (
337- TraitRef :: new ( self . interner , self . trait_ . into ( ) , [ t] ) . upcast ( self . interner ) ,
344+ TraitRef :: new_from_args (
345+ self . interner ,
346+ self . trait_id . into ( ) ,
347+ trait_args ( self . trait_ , t) ,
348+ )
349+ . upcast ( self . interner ) ,
338350 ) ;
339351 }
340352
341353 t. super_visit_with ( self )
342354 }
343355 }
344356
345- let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_ } ;
357+ let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_id , trait_ } ;
346358 for ( _, field) in fields. iter ( ) {
347359 field. get ( ) . instantiate_identity ( ) . visit_with ( & mut visitor) ;
348360 }
@@ -503,10 +515,12 @@ struct MultiGenericParams<'a, T, #[pointee] U: ?Sized, const N: usize>(*const U)
503515#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
504516struct Simple;
505517
506- trait Trait {}
518+ trait Trait {
519+ type Assoc;
520+ }
507521
508522#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
509- struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N]);
523+ struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N], T::Assoc );
510524 "# ,
511525 expect ! [ [ r#"
512526
@@ -529,41 +543,49 @@ struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N]);
529543 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
530544 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
531545 Clause(Binder { value: TraitPredicate(#1: Debug, polarity:Positive), bound_vars: [] })
546+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Debug, polarity:Positive), bound_vars: [] })
532547
533548 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
534549 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
535550 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
536551 Clause(Binder { value: TraitPredicate(#1: Clone, polarity:Positive), bound_vars: [] })
552+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Clone, polarity:Positive), bound_vars: [] })
537553
538554 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
539555 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
540556 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
541557 Clause(Binder { value: TraitPredicate(#1: Copy, polarity:Positive), bound_vars: [] })
558+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Copy, polarity:Positive), bound_vars: [] })
542559
543560 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
544561 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
545562 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
546563 Clause(Binder { value: TraitPredicate(#1: PartialEq<[#1]>, polarity:Positive), bound_vars: [] })
564+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): PartialEq<[Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. })]>, polarity:Positive), bound_vars: [] })
547565
548566 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
549567 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
550568 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
551569 Clause(Binder { value: TraitPredicate(#1: Eq, polarity:Positive), bound_vars: [] })
570+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Eq, polarity:Positive), bound_vars: [] })
552571
553572 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
554573 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
555574 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
556575 Clause(Binder { value: TraitPredicate(#1: PartialOrd<[#1]>, polarity:Positive), bound_vars: [] })
576+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): PartialOrd<[Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. })]>, polarity:Positive), bound_vars: [] })
557577
558578 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
559579 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
560580 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
561581 Clause(Binder { value: TraitPredicate(#1: Ord, polarity:Positive), bound_vars: [] })
582+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Ord, polarity:Positive), bound_vars: [] })
562583
563584 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
564585 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
565586 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
566587 Clause(Binder { value: TraitPredicate(#1: Hash, polarity:Positive), bound_vars: [] })
588+ Clause(Binder { value: TraitPredicate(Alias(Projection, AliasTy { args: [#1], def_id: TypeAliasId("Assoc"), .. }): Hash, polarity:Positive), bound_vars: [] })
567589
568590 "# ] ] ,
569591 ) ;
0 commit comments