@@ -224,20 +224,6 @@ should work and will probably try at some point.
224
224
# Reference-level explanation
225
225
[ reference-level-explanation ] : #reference-level-explanation
226
226
227
- With this RFC implemented,
228
- rust allows usage of ` Self(v0, v1, ..) ` inside inherent and
229
- trait ` impl ` s of tuple structs, either when mentioning the tuple struct
230
- directly in the ` impl ` header, or via a type alias.
231
- This usage is permitted both in expression and pattern contexts.
232
-
233
- Furthermore, ` Self ` , when referring to a tuple struct, can be legally coerced
234
- into an ` fn ` pointer which accepts and returns expressions of the same type as
235
- the function pointer ` Self ` is referring to accepts.
236
-
237
- A unit struct defined as ` struct $ident; ` can similarly be referred
238
- to as by ` Self ` in expression and pattern contexts inside inherent
239
- and trait ` impl ` s.
240
-
241
227
## Grammar
242
228
243
229
Given:
@@ -262,30 +248,24 @@ expr : ... // <-- Original grammar of `expr`.
262
248
;
263
249
```
264
250
265
- ## Semantics - Expression contexts
266
-
267
- The semantics of the syntax ` Self(x_0, .., x_n) ` is defined by adding into the
268
- value namespace, if ` Self ` refers to a tuple struct, a function:
269
-
270
- ``` rust
271
- const fn Self (x_0 : τ_0 , .. x : τ_n ) -> Self {
272
- Self { 0 : x_0 , .. n : x_n }
273
- }
274
- ```
251
+ ## Semantics
275
252
276
- The semantics of ` Self ` is defined by adding into the value namespace,
277
- if ` Self ` refers to a unit struct:
253
+ When entering one of the following contexts, a Rust compiler will extend
254
+ the value namespace with ` Self ` which maps to the tuple constructor ` fn `
255
+ in the case of tuple struct, or a constant, in the case of a unit struct:
278
256
279
- ``` rust
280
- const Self : Self = Self {};
281
- ```
257
+ + inherent ` impl ` s where the ` Self ` type is a tuple or unit struct
258
+ + ` trait ` ` impl ` s where the ` Self ` type is a tuple or unit struct
282
259
283
- ## Semantics - Pattern contexts
260
+ As a result, when referring to a tuple struct, ` Self ` can be legally coerced
261
+ into an ` fn ` pointer which accepts and returns expressions of the same type as
262
+ the function pointer ` Self ` is referring to accepts.
284
263
285
- In a pattern context, the pattern ` Self(x_0, .., x_n) ` is desugared to the
286
- pattern ` Self { 0: v0, 1: v1, .. } ` . Similarly, the pattern ` Self ` is desugared
287
- to ` Self {} ` . A rust compiler is free to use different mechanics as these
288
- semantics are preserved.
264
+ Another consequence is that ` Self(p_0, .., p_n) ` and ` Self ` become
265
+ legal patterns. This works since ` TupleCtor(p_0, .., p_n) ` patterns are
266
+ handled by resolving them in the value namespace and checking that they
267
+ resolve to a tuple constructor. Since by definition, ` Self ` referring
268
+ to a tuple struct resolves to a tuple constructor, this is OK.
289
269
290
270
## Implementation notes
291
271
0 commit comments