Skip to content

Commit 41f485a

Browse files
committedApr 26, 2025
document that unit&typle structure expr can be qualified
+ simplify/clarify the grammar
1 parent 3bf3402 commit 41f485a

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed
 

‎src/expressions/struct-expr.md

+30-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ StructExprField ->
2323
2424
StructBase -> `..` Expression
2525
26-
StructExprTuple ->
27-
PathInExpression `(`
28-
( Expression (`,` Expression)* `,`? )?
29-
`)`
26+
StructExprTuple -> CallExpression
3027
31-
StructExprUnit -> PathInExpression
28+
StructExprUnit -> PathExpression
3229
```
3330

3431
r[expr.struct.intro]
@@ -129,6 +126,20 @@ let c = Position; // `c` is a function that takes 3 arguments.
129126
let pos = c(8, 6, 7); // Creates a `Position` value.
130127
```
131128

129+
> [!NOTE]
130+
> While the grammar permits qualified paths, the last segment can't be a type alias:
131+
>
132+
> ```rust
133+
> trait Tr { type T; }
134+
> impl<T> Tr for T { type T = T; }
135+
>
136+
> struct Tuple();
137+
> enum Enum { Tuple() }
138+
>
139+
> // <Unit as Tr>::T(); // causes an error -- `::T` is a type, not a value
140+
> <Enum as Tr>::T::Tuple(); // OK
141+
> ```
142+
132143
r[expr.struct.unit]
133144
## Unit struct expression
134145
@@ -142,6 +153,20 @@ let a = Gamma; // Gamma unit value.
142153
let b = Gamma{}; // Exact same value as `a`.
143154
```
144155
156+
> [!NOTE]
157+
> While the grammar permits qualified paths, the last segment can't be a type alias:
158+
>
159+
> ```rust
160+
> trait Tr { type T; }
161+
> impl<T> Tr for T { type T = T; }
162+
>
163+
> struct Unit;
164+
> enum Enum { Unit }
165+
>
166+
> // <Unit as Tr>::T; // causes an error -- `::T` is a type, not a value
167+
> <Enum as Tr>::T::Unit; // OK
168+
> ```
169+
145170
[call expression]: call-expr.md
146171
[enum variant]: ../items/enumerations.md
147172
[if let]: if-expr.md#if-let-expressions

0 commit comments

Comments
 (0)
Please sign in to comment.