@@ -164,8 +164,7 @@ where
164
164
let interner = gb. interner ( ) ;
165
165
166
166
// 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) ;
169
168
170
169
// (FromEnv(T: Eq) => ...)
171
170
gb. implies (
@@ -256,7 +255,7 @@ fn impl_header_wf_goal<I: Interner>(
256
255
let well_formed_goal = gb. forall ( & impl_fields, ( ) , |gb, _, ( trait_ref, where_clauses) , ( ) | {
257
256
let interner = gb. interner ( ) ;
258
257
259
- let trait_constraint_goal = WellKnownConstraints :: inside_impl ( gb. db ( ) , & trait_ref) ;
258
+ let trait_constraint_goal = WfWellKnownGoals :: inside_impl ( gb. db ( ) , & trait_ref) ;
260
259
261
260
// if (WC && input types are well formed) { ... }
262
261
gb. implies (
@@ -289,7 +288,7 @@ fn impl_header_wf_goal<I: Interner>(
289
288
Some (
290
289
gb. all (
291
290
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 ( ) ) ,
293
292
) ,
294
293
)
295
294
}
@@ -453,9 +452,13 @@ fn compute_assoc_ty_goal<I: Interner>(
453
452
) )
454
453
}
455
454
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 { }
457
458
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.
459
462
pub fn inside_impl < I : Interner > (
460
463
db : & dyn RustIrDatabase < I > ,
461
464
trait_ref : & TraitRef < I > ,
@@ -468,6 +471,9 @@ impl WellKnownConstraints {
468
471
}
469
472
}
470
473
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.
471
477
pub fn outside_impl < I : Interner > (
472
478
db : & dyn RustIrDatabase < I > ,
473
479
impl_datum : & ImplDatum < I > ,
@@ -534,6 +540,7 @@ impl WellKnownConstraints {
534
540
_ => return None ,
535
541
} ;
536
542
543
+ // not { Implemented(ImplSelfTy: Drop) }
537
544
let neg_drop_goal =
538
545
db. well_known_trait_id ( WellKnownTrait :: DropTrait )
539
546
. map ( |drop_trait_id| {
@@ -553,6 +560,7 @@ impl WellKnownConstraints {
553
560
. substitute ( interner, substitution)
554
561
. into_iter ( )
555
562
. map ( |f| {
563
+ // Implemented(FieldTy: Copy)
556
564
TraitRef {
557
565
trait_id : trait_ref. trait_id ,
558
566
substitution : Substitution :: from1 ( interner, f) ,
@@ -609,7 +617,7 @@ impl WellKnownConstraints {
609
617
..
610
618
} ) = impl_datum
611
619
. binders
612
- . value
620
+ . skip_binders ( )
613
621
. trait_ref
614
622
. self_type_parameter ( interner)
615
623
. data ( interner)
@@ -629,16 +637,19 @@ impl WellKnownConstraints {
629
637
. binders
630
638
. map_ref ( |v| ( & v. trait_ref , & v. where_clauses ) ) ;
631
639
640
+ // forall<ImplP1...ImplPn> { .. }
632
641
let implied_by_struct_def_goal =
633
642
gb. forall ( & impl_fields, ( ) , |gb, _, ( trait_ref, where_clauses) , ( ) | {
634
643
let interner = gb. interner ( ) ;
635
644
645
+ // FromEnv(ImplSelfType) => ...
636
646
gb. implies (
637
647
iter:: once (
638
648
FromEnv :: Ty ( trait_ref. self_type_parameter ( interner) )
639
649
. cast :: < DomainGoal < I > > ( interner) ,
640
650
) ,
641
651
|gb| {
652
+ // All(ImplWhereClauses)
642
653
gb. all (
643
654
where_clauses
644
655
. iter ( )
@@ -652,6 +663,7 @@ impl WellKnownConstraints {
652
663
. binders
653
664
. map_ref ( |b| b. trait_ref . self_type_parameter ( interner) ) ;
654
665
666
+ // forall<StructP1..StructPN> {...}
655
667
let eq_goal = gb. forall (
656
668
& struct_datum. binders ,
657
669
( struct_name, impl_self_ty) ,
@@ -665,11 +677,14 @@ impl WellKnownConstraints {
665
677
. cast ( interner)
666
678
. intern ( interner) ;
667
679
680
+ // exists<ImplP1...ImplPn> { .. }
668
681
gb. exists (
669
682
& impl_self_ty,
670
683
def_struct,
671
684
|gb, _, impl_struct, def_struct| {
672
685
let interner = gb. interner ( ) ;
686
+
687
+ // StructName<StructP1..StructPn> = ImplSelfType
673
688
GoalData :: EqGoal ( EqGoal {
674
689
a : ParameterData :: Ty ( def_struct) . intern ( interner) ,
675
690
b : ParameterData :: Ty ( impl_struct. clone ( ) ) . intern ( interner) ,
0 commit comments