Skip to content

Commit 6cbcd59

Browse files
committed
document that unit&typle structure expr can be qualified
1 parent 3bf3402 commit 6cbcd59

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/expressions/struct-expr.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ StructExprField ->
2424
StructBase -> `..` Expression
2525
2626
StructExprTuple ->
27-
PathInExpression `(`
27+
PathExpression `(`
2828
( Expression (`,` Expression)* `,`? )?
2929
`)`
3030
31-
StructExprUnit -> PathInExpression
31+
StructExprUnit -> PathExpression
3232
```
3333

3434
r[expr.struct.intro]
@@ -129,6 +129,20 @@ let c = Position; // `c` is a function that takes 3 arguments.
129129
let pos = c(8, 6, 7); // Creates a `Position` value.
130130
```
131131

132+
> [!NOTE]
133+
> While the grammar permits qualified paths, the last segment can't be a type alias:
134+
>
135+
> ```rust
136+
> trait Tr { type T; }
137+
> impl<T> Tr for T { type T = T; }
138+
>
139+
> struct Tuple();
140+
> enum Enum { Tuple() }
141+
>
142+
> // <Unit as Tr>::T(); // causes an error -- `::T` is a type, not a value
143+
> <Enum as Tr>::T::Tuple(); // OK
144+
> ```
145+
132146
r[expr.struct.unit]
133147
## Unit struct expression
134148
@@ -142,6 +156,20 @@ let a = Gamma; // Gamma unit value.
142156
let b = Gamma{}; // Exact same value as `a`.
143157
```
144158
159+
> [!NOTE]
160+
> While the grammar permits qualified paths, the last segment can't be a type alias:
161+
>
162+
> ```rust
163+
> trait Tr { type T; }
164+
> impl<T> Tr for T { type T = T; }
165+
>
166+
> struct Unit;
167+
> enum Enum { Unit }
168+
>
169+
> // <Unit as Tr>::T; // causes an error -- `::T` is a type, not a value
170+
> <Enum as Tr>::T::Unit; // OK
171+
> ```
172+
145173
[call expression]: call-expr.md
146174
[enum variant]: ../items/enumerations.md
147175
[if let]: if-expr.md#if-let-expressions

0 commit comments

Comments
 (0)