@@ -132,8 +132,6 @@ to be **well-formed**:
132
132
133
133
``` text
134
134
// Rule WellFormed-TraitRef
135
- //
136
- // For each where clause WC:
137
135
forall<Self, P1..Pn> {
138
136
WellFormed(Self: Trait<P1..Pn>) :- Implemented(Self: Trait<P1..Pn>) && WellFormed(WC)
139
137
}
@@ -198,38 +196,72 @@ in detail in the [section on associated types](./traits-associated-types.html),
198
196
but reproduced here for reference:
199
197
200
198
``` text
201
- // Rule ProjectionEq-Normalize
202
- //
203
- // ProjectionEq can succeed by normalizing:
204
- forall<Self, P1..Pn, Pn+1..Pm, U> {
205
- ProjectionEq(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> = U) :-
206
- Normalize(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> -> U)
207
- }
199
+ // Rule ProjectionEq-Normalize
200
+ //
201
+ // ProjectionEq can succeed by normalizing:
202
+ forall<Self, P1..Pn, Pn+1..Pm, U> {
203
+ ProjectionEq(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> = U) :-
204
+ Normalize(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> -> U)
205
+ }
206
+ ```
208
207
209
- // Rule ProjectionEq-Skolemize
210
- //
211
- // ProjectionEq can succeed by skolemizing, see "associated type"
212
- // chapter for more:
213
- forall<Self, P1..Pn, Pn+1..Pm> {
214
- ProjectionEq(
215
- <Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> =
216
- (Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>
217
- ) :-
218
- // But only if the trait is implemented, and the conditions from
219
- // the associated type are met as well:
220
- Implemented(Self: Trait<P1..Pn>)
221
- && WC1
222
- }
208
+ ``` text
209
+ // Rule ProjectionEq-Skolemize
210
+ //
211
+ // ProjectionEq can succeed by skolemizing, see "associated type"
212
+ // chapter for more:
213
+ forall<Self, P1..Pn, Pn+1..Pm> {
214
+ ProjectionEq(
215
+ <Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm> =
216
+ (Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>
217
+ )
218
+ }
223
219
```
224
220
225
221
The next rule covers implied bounds for the projection. In particular,
226
- the ` Bounds ` declared on the associated type must be proven to hold to
227
- show that the impl is well-formed, and hence we can rely on them
222
+ the ` Bounds ` declared on the associated type must have been proven to hold
223
+ to show that the impl is well-formed, and hence we can rely on them
228
224
elsewhere.
229
225
230
226
``` text
231
- // XXX how exactly should we set this up? Have to be careful;
232
- // presumably this has to be a kind of `FromEnv` setup.
227
+ // Rule Implied-Bound-From-AssocTy
228
+ //
229
+ // For each `Bound` in `Bounds`:
230
+ forall<Self, P1..Pn, Pn+1..Pm> {
231
+ FromEnv(<Self as Trait<P1..Pn>>::AssocType<Pn+1..Pm>>: Bound) :-
232
+ FromEnv(Self: Trait<P1..Pn>)
233
+ }
234
+ ```
235
+
236
+ Next, we define the requirements for an instantiation of our associated
237
+ type to be well-formed...
238
+
239
+ ``` text
240
+ // Rule WellFormed-AssocTy
241
+ forall<Self, P1..Pn, Pn+1..Pm> {
242
+ WellFormed((Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>) :-
243
+ WC1, Implemented(Self: Trait<P1..Pn>)
244
+ }
245
+ ```
246
+
247
+ ...along with the reverse implications, when we can assume that it is
248
+ well-formed.
249
+
250
+ ``` text
251
+ // Rule Implied-WC-From-AssocTy
252
+ //
253
+ // For each where clause WC1:
254
+ forall<Self, P1..Pn, Pn+1..Pm> {
255
+ FromEnv(WC1) :- FromEnv((Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>)
256
+ }
257
+ ```
258
+
259
+ ``` text
260
+ // Rule Implied-Trait-From-AssocTy
261
+ forall<Self, P1..Pn, Pn+1..Pm> {
262
+ FromEnv(Self: Trait<P1..Pn>) :-
263
+ FromEnv((Trait::AssocType)<Self, P1..Pn, Pn+1..Pm>)
264
+ }
233
265
```
234
266
235
267
### Lowering function and constant declarations
@@ -269,26 +301,27 @@ In addition, we will lower all of the *impl items*.
269
301
Given an impl that contains:
270
302
271
303
``` rust,ignore
272
- impl<P0..Pn> Trait<A1..An > for A0
273
- where WC
304
+ impl<P0..Pn> Trait<P1..Pn > for P0
305
+ where WC_impl
274
306
{
275
- type AssocType<Pn+1..Pm> where WC1 = T;
307
+ type AssocType<Pn+1..Pm> = T;
276
308
}
277
309
```
278
310
279
- We produce the following rule:
311
+ and our where clause ` WC1 ` on the trait associated type from above, we
312
+ produce the following rule:
280
313
281
314
``` text
282
315
// Rule Normalize-From-Impl
283
316
forall<P0..Pm> {
284
317
forall<Pn+1..Pm> {
285
- Normalize(<A0 as Trait<A1..An >>::AssocType<Pn+1..Pm> -> T) :-
286
- WC && WC1
318
+ Normalize(<P0 as Trait<P1..Pn >>::AssocType<Pn+1..Pm> -> T) :-
319
+ Implemented(P0 as Trait) && WC1
287
320
}
288
321
}
289
322
```
290
323
291
- Note that ` WC ` and ` WC1 ` both encode where-clauses that the impl can
324
+ Note that ` WC_impl ` and ` WC1 ` both encode where-clauses that the impl can
292
325
rely on.
293
326
294
327
<a name =" constant-vals " ></a >
@@ -300,5 +333,3 @@ like to treat them exactly like normalization. This presumably
300
333
involves adding a new kind of parameter (constant), and then having a
301
334
` NormalizeValue ` domain goal. This is * to be written* because the
302
335
details are a bit up in the air.
303
-
304
-
0 commit comments