Skip to content

Commit 2e74f61

Browse files
committed
Make changes as requested by the Rust team
This adjusts the proposal to propose `T: ?Sized` instead of `T: Sized?`, and changes the syntax for traits to `trait Trait for ?Sized` instead of `trait Trait: Sized?`.
1 parent a7a45b3 commit 2e74f61

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

text/0000-dst-syntax.md

+21-23
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Summary
66
=======
77

88
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.
1111

1212
Motivation
1313
==========
@@ -79,8 +79,8 @@ before being dropped. However, many generic functions assume that any parameter
7979
passed to them can be dropped. `Drop` could be made a default bound to resolve
8080
this, and `Drop?` would remove this bound from a type parameter.
8181

82-
The problem with `Sized?`
83-
-------------------------
82+
The problem with `Sized? T`
83+
---------------------------
8484

8585
There is some inconsistency present with the `Sized` syntax. After going through
8686
multiple syntaxes for DST, all of which were keywords preceding type parameters,
@@ -116,46 +116,43 @@ trait Foo<T> where Sized? T {
116116
}
117117
```
118118

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.
125122

126123
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.
128125

129126
Detailed design
130127
===============
131128

132-
Change the syntax for dynamically sized type parameters to `T: Sized?`:
129+
Change the syntax for dynamically sized type parameters to `T: ?Sized`:
133130

134131
```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; }
138135
// etc.
139136
```
140137

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:
143140

144141
```rust
145-
trait Foo: Sized? { ... }
142+
trait Foo for ?Sized { ... }
146143
```
147144

148145
Allow using this syntax in `where` clauses:
149146

150147
```rust
151-
fn foo<T>(x: &T) where T: Sized? { ... }
148+
fn foo<T>(x: &T) where T: ?Sized { ... }
152149
```
153150

154151
Drawbacks
155152
=========
156153

157154
- 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
159156
actually an anti-bound (it removes a bound), it (in some ways) makes sense to
160157
put it on the opposite side of a type parameter to show this.
161158

@@ -172,10 +169,11 @@ Alternatives
172169
of the previous syntaxes are discussed in the ‘History of the DST syntax’
173170
section of this RFC.
174171

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
176173
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.
179177

180178
Unresolved questions
181179
====================

0 commit comments

Comments
 (0)