6
6
=======
7
7
8
8
Change the syntax for dynamically sized type parameters from ` Sized? T ` to `T:
9
- Sized? ` , and change the syntax for traits for dynamically sized types to ` trait
10
- Foo: Sized? ` . Extend this new syntax to work with ` where` clauses.
9
+ ?Sized ` , and change the syntax for traits for dynamically sized types to ` trait
10
+ Foo for ?Sized ` . Extend this new syntax to work with ` where` clauses.
11
11
12
12
Motivation
13
13
==========
@@ -79,8 +79,8 @@ before being dropped. However, many generic functions assume that any parameter
79
79
passed to them can be dropped. ` Drop ` could be made a default bound to resolve
80
80
this, and ` Drop? ` would remove this bound from a type parameter.
81
81
82
- The problem with ` Sized? `
83
- -------------------------
82
+ The problem with ` Sized? T `
83
+ ---------------------------
84
84
85
85
There is some inconsistency present with the ` Sized ` syntax. After going through
86
86
multiple syntaxes for DST, all of which were keywords preceding type parameters,
@@ -116,46 +116,43 @@ trait Foo<T> where Sized? T {
116
116
}
117
117
```
118
118
119
- Furthermore, another syntax had to be invented for traits for which ` Self ` can
120
- be unsized:
121
-
122
- ``` rust
123
- trait Foo for Sized ? { ... }
124
- ```
119
+ Furthermore, the ` ? ` on ` Sized? ` comes after the trait name, whereas most
120
+ unary-operator-like symbols in the Rust language come before what they are
121
+ attached to.
125
122
126
123
This RFC proposes to change the syntax for dynamically sized type parameters to
127
- ` T: Sized? ` to resolve these issues.
124
+ ` T: ?Sized ` to resolve these issues.
128
125
129
126
Detailed design
130
127
===============
131
128
132
- Change the syntax for dynamically sized type parameters to ` T: Sized? ` :
129
+ Change the syntax for dynamically sized type parameters to ` T: ?Sized ` :
133
130
134
131
``` rust
135
- fn foo <T : Sized ? >(x : & T ) { ... }
136
- struct Foo <T : Send + Sized ? + Sync > { field : Box <T > }
137
- trait Bar { type Baz : Sized ? ; }
132
+ fn foo <T : ? Sized >(x : & T ) { ... }
133
+ struct Foo <T : Send + ? Sized + Sync > { field : Box <T > }
134
+ trait Bar { type Baz : ? Sized ; }
138
135
// etc.
139
136
```
140
137
141
- Change the syntax for traits for dynamically-sized types to look like the syntax
142
- for bounds on ` Self ` :
138
+ Change the syntax for traits for dynamically-sized types to have a prefix ` ? `
139
+ instead of a postfix one :
143
140
144
141
``` rust
145
- trait Foo : Sized ? { ... }
142
+ trait Foo for ? Sized { ... }
146
143
```
147
144
148
145
Allow using this syntax in ` where ` clauses:
149
146
150
147
``` rust
151
- fn foo <T >(x : & T ) where T : Sized ? { ... }
148
+ fn foo <T >(x : & T ) where T : ? Sized { ... }
152
149
```
153
150
154
151
Drawbacks
155
152
=========
156
153
157
154
- The current syntax uses position to distinguish between removing and adding
158
- bounds, while the proposed syntax only uses a symbol. Since ` Sized? ` is
155
+ bounds, while the proposed syntax only uses a symbol. Since ` ?Sized ` is
159
156
actually an anti-bound (it removes a bound), it (in some ways) makes sense to
160
157
put it on the opposite side of a type parameter to show this.
161
158
@@ -172,10 +169,11 @@ Alternatives
172
169
of the previous syntaxes are discussed in the ‘History of the DST syntax’
173
170
section of this RFC.
174
171
175
- - Change the syntax to ` T: ? Sized ` instead. This is more consistent with things
172
+ - Change the syntax to ` T: Sized? ` instead. This is less consistent with things
176
173
like negative bounds (which would probably be something like ` T: !Foo ` ), and
177
- uses a prefix operator, which is more consistent with other parts of Rust’s
178
- syntax.
174
+ uses a suffix operator, which is less consistent with other parts of Rust’s
175
+ syntax. It is, however, closer to the current syntax (` Sized? T ` ), and looks
176
+ more natural because of how ` ? ` is used in natural languages such as English.
179
177
180
178
Unresolved questions
181
179
====================
0 commit comments