@@ -164,8 +164,7 @@ where
164164 let interner = gb. interner ( ) ;
165165
166166 // struct is well-formed in terms of Sized
167- let sized_constraint_goal =
168- WellKnownConstraints :: struct_sized_constraint ( gb. db ( ) , fields) ;
167+ let sized_constraint_goal = WfWellKnownGoals :: struct_sized_constraint ( gb. db ( ) , fields) ;
169168
170169 // (FromEnv(T: Eq) => ...)
171170 gb. implies (
@@ -256,7 +255,7 @@ fn impl_header_wf_goal<I: Interner>(
256255 let well_formed_goal = gb. forall ( & impl_fields, ( ) , |gb, _, ( trait_ref, where_clauses) , ( ) | {
257256 let interner = gb. interner ( ) ;
258257
259- let trait_constraint_goal = WellKnownConstraints :: inside_impl ( gb. db ( ) , & trait_ref) ;
258+ let trait_constraint_goal = WfWellKnownGoals :: inside_impl ( gb. db ( ) , & trait_ref) ;
260259
261260 // if (WC && input types are well formed) { ... }
262261 gb. implies (
@@ -289,7 +288,7 @@ fn impl_header_wf_goal<I: Interner>(
289288 Some (
290289 gb. all (
291290 iter:: once ( well_formed_goal)
292- . chain ( WellKnownConstraints :: outside_impl ( db, & impl_datum) . into_iter ( ) ) ,
291+ . chain ( WfWellKnownGoals :: outside_impl ( db, & impl_datum) . into_iter ( ) ) ,
293292 ) ,
294293 )
295294}
@@ -453,9 +452,13 @@ fn compute_assoc_ty_goal<I: Interner>(
453452 ) )
454453}
455454
456- struct WellKnownConstraints { }
455+ /// Defines methods to compute well-formedness goals for well-known
456+ /// traits (e.g. a goal for all fields of struct in a Copy impl to be Copy)
457+ struct WfWellKnownGoals { }
457458
458- impl WellKnownConstraints {
459+ impl WfWellKnownGoals {
460+ /// A convenience method to compute the goal assuming `trait_ref`
461+ /// well-formedness requirements are in the environment.
459462 pub fn inside_impl < I : Interner > (
460463 db : & dyn RustIrDatabase < I > ,
461464 trait_ref : & TraitRef < I > ,
@@ -468,6 +471,9 @@ impl WellKnownConstraints {
468471 }
469472 }
470473
474+ /// Computes well-formedness goals without any assumptions about the environment.
475+ /// Note that `outside_impl` does not call `inside_impl`, one needs to call both
476+ /// in order to get the full set of goals to be proven.
471477 pub fn outside_impl < I : Interner > (
472478 db : & dyn RustIrDatabase < I > ,
473479 impl_datum : & ImplDatum < I > ,
@@ -534,6 +540,7 @@ impl WellKnownConstraints {
534540 _ => return None ,
535541 } ;
536542
543+ // not { Implemented(ImplSelfTy: Drop) }
537544 let neg_drop_goal =
538545 db. well_known_trait_id ( WellKnownTrait :: DropTrait )
539546 . map ( |drop_trait_id| {
@@ -553,6 +560,7 @@ impl WellKnownConstraints {
553560 . substitute ( interner, substitution)
554561 . into_iter ( )
555562 . map ( |f| {
563+ // Implemented(FieldTy: Copy)
556564 TraitRef {
557565 trait_id : trait_ref. trait_id ,
558566 substitution : Substitution :: from1 ( interner, f) ,
@@ -609,7 +617,7 @@ impl WellKnownConstraints {
609617 ..
610618 } ) = impl_datum
611619 . binders
612- . value
620+ . skip_binders ( )
613621 . trait_ref
614622 . self_type_parameter ( interner)
615623 . data ( interner)
@@ -629,16 +637,19 @@ impl WellKnownConstraints {
629637 . binders
630638 . map_ref ( |v| ( & v. trait_ref , & v. where_clauses ) ) ;
631639
640+ // forall<ImplP1...ImplPn> { .. }
632641 let implied_by_struct_def_goal =
633642 gb. forall ( & impl_fields, ( ) , |gb, _, ( trait_ref, where_clauses) , ( ) | {
634643 let interner = gb. interner ( ) ;
635644
645+ // FromEnv(ImplSelfType) => ...
636646 gb. implies (
637647 iter:: once (
638648 FromEnv :: Ty ( trait_ref. self_type_parameter ( interner) )
639649 . cast :: < DomainGoal < I > > ( interner) ,
640650 ) ,
641651 |gb| {
652+ // All(ImplWhereClauses)
642653 gb. all (
643654 where_clauses
644655 . iter ( )
@@ -652,6 +663,7 @@ impl WellKnownConstraints {
652663 . binders
653664 . map_ref ( |b| b. trait_ref . self_type_parameter ( interner) ) ;
654665
666+ // forall<StructP1..StructPN> {...}
655667 let eq_goal = gb. forall (
656668 & struct_datum. binders ,
657669 ( struct_name, impl_self_ty) ,
@@ -665,11 +677,14 @@ impl WellKnownConstraints {
665677 . cast ( interner)
666678 . intern ( interner) ;
667679
680+ // exists<ImplP1...ImplPn> { .. }
668681 gb. exists (
669682 & impl_self_ty,
670683 def_struct,
671684 |gb, _, impl_struct, def_struct| {
672685 let interner = gb. interner ( ) ;
686+
687+ // StructName<StructP1..StructPn> = ImplSelfType
673688 GoalData :: EqGoal ( EqGoal {
674689 a : ParameterData :: Ty ( def_struct) . intern ( interner) ,
675690 b : ParameterData :: Ty ( impl_struct. clone ( ) ) . intern ( interner) ,
0 commit comments