@@ -12,6 +12,8 @@ use formality_types::{
12
12
#[ term]
13
13
pub struct Decls {
14
14
pub max_size : usize ,
15
+
16
+ /// Each trait in the program
15
17
pub trait_decls : Vec < TraitDecl > ,
16
18
pub impl_decls : Vec < ImplDecl > ,
17
19
pub neg_impl_decls : Vec < NegImplDecl > ,
@@ -95,31 +97,49 @@ impl Decls {
95
97
}
96
98
}
97
99
100
+ /// An "impl decl" indicates that a trait is implemented for a given set of types.
101
+ /// One "impl decl" is created for each impl in the Rust source.
98
102
#[ term( impl $binder) ]
99
103
pub struct ImplDecl {
104
+ /// The binder covers the generic variables from the impl
100
105
pub binder : Binder < ImplDeclBoundData > ,
101
106
}
102
107
108
+ /// Data bound under the generics from [`ImplDecl`][]
103
109
#[ term( $trait_ref where $where_clause) ]
104
110
pub struct ImplDeclBoundData {
111
+ /// The trait ref that is implemented
105
112
pub trait_ref : TraitRef ,
113
+
114
+ ///
106
115
pub where_clause : Wcs ,
107
116
}
108
117
118
+ /// A declaration that some trait will *not* be implemented for a type; derived from negative impls
119
+ /// like `impl !Foo for Bar`.
109
120
#[ term( impl $binder) ]
110
121
pub struct NegImplDecl {
122
+ /// Binder comes the generics on the impl
111
123
pub binder : Binder < NegImplDeclBoundData > ,
112
124
}
113
125
126
+ /// Data bound under the impl generics for a negative impl
114
127
#[ term( !$trait_ref where $where_clause) ]
115
128
pub struct NegImplDeclBoundData {
116
129
pub trait_ref : TraitRef ,
117
130
pub where_clause : Wcs ,
118
131
}
119
132
133
+ /// A "trait declaration" declares a trait that exists, its generics, and its where-clauses.
134
+ /// It doesn't capture the trait items, which will be transformed into other sorts of rules.
135
+ ///
136
+ /// In Rust syntax, it covers the `trait Foo: Bar` part of the declaration, but not what appears in the `{...}`.
120
137
#[ term( trait $id $binder) ]
121
138
pub struct TraitDecl {
139
+ /// The name of the trait
122
140
pub id : TraitId ,
141
+
142
+ /// The binder here captures the generics of the trait; it always begins with a `Self` type.
123
143
pub binder : Binder < TraitDeclBoundData > ,
124
144
}
125
145
@@ -163,24 +183,39 @@ impl TraitDecl {
163
183
}
164
184
}
165
185
186
+ /// A trait *invariant* is a rule like `<T> Implemented(T: Ord) => Implemented(T: PartialOrd)`.
187
+ /// It indices that, if we know that `T: Ord` from the environment,
188
+ /// we also know that `T: PartialOrd`.
189
+ /// Invariants are produced from trait declarations during lowering; they derive from the
190
+ /// where-clauses on the trait.
166
191
#[ term]
167
192
pub struct TraitInvariant {
168
193
pub binder : Binder < TraitInvariantBoundData > ,
169
194
}
170
195
196
+ /// The "bound data" for a [`TraitInvariant`][] -- i.e., what is covered by the forall.
171
197
#[ term( $trait_ref => $where_clause) ]
172
198
pub struct TraitInvariantBoundData {
199
+ /// Knowing that this trait-ref is implemented...
173
200
pub trait_ref : TraitRef ,
201
+
202
+ /// ...implies that these where-clauses hold.
174
203
pub where_clause : Wc ,
175
204
}
176
205
206
+ /// The "bound data" for a [`TraitDecl`][] -- i.e., what is covered by the forall.
177
207
#[ term( where $where_clause) ]
178
208
pub struct TraitDeclBoundData {
209
+ /// The where-clauses declared on the trait
179
210
pub where_clause : Wcs ,
180
211
}
181
212
213
+ /// An "alias equal declaration" declares when an alias type can be normalized
214
+ /// to something else. They are derived from `type Foo = Bar` declarations in
215
+ /// impls, which would generate an alias eq decl saying that `<T as SomeTrait>::Foo = Bar`.
182
216
#[ term( alias $binder) ]
183
217
pub struct AliasEqDecl {
218
+ /// The binder includes the generics from the impl and also any generics on the GAT.
184
219
pub binder : Binder < AliasEqDeclBoundData > ,
185
220
}
186
221
@@ -190,13 +225,23 @@ impl AliasEqDecl {
190
225
}
191
226
}
192
227
228
+ /// Data bound under the impl generics for a [`AliasEqDecl`][]
193
229
#[ term( $alias = $ty where $where_clause) ]
194
230
pub struct AliasEqDeclBoundData {
231
+ /// The alias that is equal
195
232
pub alias : AliasTy ,
233
+
234
+ /// The type the alias is equal to
196
235
pub ty : Ty ,
236
+
237
+ /// The where-clauses that must hold for this rule to be applicable; derived from the impl and the GAT
197
238
pub where_clause : Wcs ,
198
239
}
199
240
241
+ /// Alias bounds indicate things that are always known to be true of an alias type,
242
+ /// even when its precise value is not known.
243
+ /// For example given a trait `trait Foo { type Bar: Baz; }`
244
+ /// we know that `<T as Foo>::Bar: Baz` must hold.
200
245
#[ term( alias $binder) ]
201
246
pub struct AliasBoundDecl {
202
247
pub binder : Binder < AliasBoundDeclBoundData > ,
0 commit comments