@@ -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,7 +276,8 @@ 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_ref = TraitRef :: new ( interner, trait_id. into ( ) , [ param_ty] ) ;
279+ let trait_args = trait_args ( loc. trait_ , param_ty) ;
280+ let trait_ref = TraitRef :: new_from_args ( interner, trait_id. into ( ) , trait_args) ;
264281 trait_ref. upcast ( interner)
265282 } ) ;
266283 let mut assoc_type_bounds = Vec :: new ( ) ;
@@ -270,12 +287,14 @@ fn simple_trait_predicates<'db>(
270287 & mut assoc_type_bounds,
271288 interner. db . field_types ( id. into ( ) ) ,
272289 trait_id,
290+ loc. trait_ ,
273291 ) ,
274292 AdtId :: UnionId ( id) => extend_assoc_type_bounds (
275293 interner,
276294 & mut assoc_type_bounds,
277295 interner. db . field_types ( id. into ( ) ) ,
278296 trait_id,
297+ loc. trait_ ,
279298 ) ,
280299 AdtId :: EnumId ( id) => {
281300 for & ( variant_id, _, _) in & id. enum_variants ( interner. db ) . variants {
@@ -284,6 +303,7 @@ fn simple_trait_predicates<'db>(
284303 & mut assoc_type_bounds,
285304 interner. db . field_types ( variant_id. into ( ) ) ,
286305 trait_id,
306+ loc. trait_ ,
287307 )
288308 }
289309 }
@@ -305,12 +325,14 @@ fn extend_assoc_type_bounds<'db>(
305325 interner : DbInterner < ' db > ,
306326 assoc_type_bounds : & mut Vec < Clause < ' db > > ,
307327 fields : & ArenaMap < LocalFieldId , StoredEarlyBinder < StoredTy > > ,
308- trait_ : TraitId ,
328+ trait_id : TraitId ,
329+ trait_ : BuiltinDeriveImplTrait ,
309330) {
310331 struct ProjectionFinder < ' a , ' db > {
311332 interner : DbInterner < ' db > ,
312333 assoc_type_bounds : & ' a mut Vec < Clause < ' db > > ,
313- trait_ : TraitId ,
334+ trait_id : TraitId ,
335+ trait_ : BuiltinDeriveImplTrait ,
314336 }
315337
316338 impl < ' db > TypeVisitor < DbInterner < ' db > > for ProjectionFinder < ' _ , ' db > {
@@ -319,15 +341,20 @@ fn extend_assoc_type_bounds<'db>(
319341 fn visit_ty ( & mut self , t : Ty < ' db > ) -> Self :: Result {
320342 if let TyKind :: Alias ( AliasTyKind :: Projection , _) = t. kind ( ) {
321343 self . assoc_type_bounds . push (
322- 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 ) ,
323350 ) ;
324351 }
325352
326353 t. super_visit_with ( self )
327354 }
328355 }
329356
330- let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_ } ;
357+ let mut visitor = ProjectionFinder { interner, assoc_type_bounds, trait_id , trait_ } ;
331358 for ( _, field) in fields. iter ( ) {
332359 field. get ( ) . instantiate_identity ( ) . visit_with ( & mut visitor) ;
333360 }
@@ -488,10 +515,12 @@ struct MultiGenericParams<'a, T, #[pointee] U: ?Sized, const N: usize>(*const U)
488515#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
489516struct Simple;
490517
491- trait Trait {}
518+ trait Trait {
519+ type Assoc;
520+ }
492521
493522#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
494- 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 );
495524 "# ,
496525 expect ! [ [ r#"
497526
@@ -514,41 +543,49 @@ struct WithGenerics<'a, T: Trait, const N: usize>(&'a [T; N]);
514543 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
515544 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
516545 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: [] })
517547
518548 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
519549 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
520550 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
521551 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: [] })
522553
523554 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
524555 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
525556 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
526557 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: [] })
527559
528560 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
529561 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
530562 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
531- Clause(Binder { value: TraitPredicate(#1: PartialEq, polarity:Positive), bound_vars: [] })
563+ 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: [] })
532565
533566 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
534567 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
535568 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
536569 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: [] })
537571
538572 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
539573 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
540574 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
541- Clause(Binder { value: TraitPredicate(#1: PartialOrd, polarity:Positive), bound_vars: [] })
575+ 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: [] })
542577
543578 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
544579 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
545580 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
546581 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: [] })
547583
548584 Clause(Binder { value: TraitPredicate(#1: Trait, polarity:Positive), bound_vars: [] })
549585 Clause(Binder { value: ConstArgHasType(#2, usize), bound_vars: [] })
550586 Clause(Binder { value: TraitPredicate(#1: Sized, polarity:Positive), bound_vars: [] })
551587 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: [] })
552589
553590 "# ] ] ,
554591 ) ;
0 commit comments