@@ -7,6 +7,12 @@ use crate::{
7
7
} ;
8
8
9
9
judgment_fn ! {
10
+ /// Check whether the where-clause `via` (which is one of the `assumptions` that are in in scope)
11
+ /// can be used to prove `goal` (the thing we are trying to prove).
12
+ ///
13
+ /// This is equivalent to the "elaboration" of the environment that takes place in rustc,
14
+ /// but done lazilly. For example, if you have `where T: Eq` then you can clearly prove `T: Eq`
15
+ /// but you can also prove `T: PartialEq` because `trait Eq: PartialEq`.
10
16
pub fn prove_via(
11
17
_decls: Decls ,
12
18
env: Env ,
@@ -17,7 +23,9 @@ judgment_fn! {
17
23
debug( goal, via, assumptions, env)
18
24
19
25
(
26
+ // `c` = "clause", the name for something that we are assuming is true.
20
27
( let ( skel_c, parameters_c) = pred_1. debone( ) )
28
+ // `g` = "goal, the name for something that we are trying to prove.
21
29
( let ( skel_g, parameters_g) = pred_2. debone( ) )
22
30
( if skel_c == skel_g) !
23
31
( prove( decls, env, assumptions, Wcs :: all_eq( parameters_c, parameters_g) ) => c)
@@ -34,16 +42,21 @@ judgment_fn! {
34
42
( prove_via( _decls, env, _assumptions, WcData :: Relation ( rel_1) , WcData :: Relation ( rel_2) ) => Constraints :: none( env) )
35
43
)
36
44
45
+ // If you have `where for<'a> T: Trait<'a>` then you can prove `T: Trait<'b>` for any `'b`.
37
46
(
38
47
( let ( env, subst) = env. existential_substitution( & binder) )
39
48
( let via1 = binder. instantiate_with( & subst) . unwrap( ) )
49
+ // Try to prove `T: Trait<?a> == goal`.
40
50
( prove_via( decls, env, assumptions, via1, goal) => c)
41
51
----------------------------- ( "forall" )
42
52
( prove_via( decls, env, assumptions, WcData :: ForAll ( binder) , goal) => c. pop_subst( & subst) )
43
53
)
44
54
55
+ // If you have `where if (T: Debug) T: Foo` (not in Rust but it should be...)...
45
56
(
57
+ // if the goal is `T: Foo`...
46
58
( prove_via( & decls, env, & assumptions, wc_consequence, goal) => c)
59
+ // ...and we can prove `T: Debug`... then it holds.
47
60
( prove_after( & decls, c, & assumptions, & wc_condition) => c)
48
61
----------------------------- ( "implies" )
49
62
( prove_via( decls, env, assumptions, WcData :: Implies ( wc_condition, wc_consequence) , goal) => c)
0 commit comments