Skip to content

Commit 8ea1d96

Browse files
committed
typofix
1 parent 9e2260e commit 8ea1d96

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

text/0000-unsized-rvalues.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,33 @@ Provide some optimization guarantees that unnecessary temporaries will not creat
1717

1818
There are 2 motivations for this RFC:
1919

20-
1) Passing unsized values, such as trait objects, to functions by value is often desired. Currently, this must be done through a `Box<T>` with an unnecessary allocation.
20+
1. Passing unsized values, such as trait objects, to functions by value is often desired. Currently, this must be done through a `Box<T>` with an unnecessary allocation.
2121

22-
One particularly common example is passing closures that consume their environment without using monomorphization. One would like for this code to work:
22+
One particularly common example is passing closures that consume their environment without using monomorphization. One would like for this code to work:
2323

24-
```Rust
25-
fn takes_closure(f: FnOnce()) { f(); }
26-
```
24+
```Rust
25+
fn takes_closure(f: FnOnce()) { f(); }
26+
```
2727

28-
But today you have to use a hack, such as taking a `Box<FnBox<()>>`.
28+
But today you have to use a hack, such as taking a `Box<FnBox<()>>`.
2929

30-
2) Allocating a runtime-sized variable on the stack is important for good performance in some use-cases - see RFC #1808, which this is intended to supersede.
30+
2. Allocating a runtime-sized variable on the stack is important for good performance in some use-cases - see RFC #1808, which this is intended to supersede.
3131

3232
# Detailed design
3333
[design]: #detailed-design
3434

3535
## Unsized Rvalues - language
3636

3737
Remove the rule that requires all locals and rvalues to have a sized type. Instead, require the following:
38-
a) The following expressions must always return a Sized type:
39-
a1) Function calls, method calls, operator expressions
38+
39+
1. The following expressions must always return a Sized type:
40+
1. Function calls, method calls, operator expressions
4041
- implementing unsized return values for function calls would require the *called function* to do the alloca in our stack frame.
41-
a2) ADT expressions
42+
2. ADT expressions
4243
- see alternatives
43-
a3) cast expressions
44+
3. cast expressions
4445
- this seems like an implementation simplicity thing. These can only be trivial casts.
45-
b) The RHS of assignment expressions must always have a Sized type.
46+
2. The RHS of assignment expressions must always have a Sized type.
4647
- Assigning an unsized type is impossible because we don't know how much memory is available at the destination. This applies to ExprAssign assignments and not to StmtLet let-statements.
4748

4849
This also allows passing unsized values to functions, with the ABI being as if a `&move` pointer was passed (a `(by-move-data, extra)` pair). This also means that methods taking `self` by value are object-safe, though vtable shims are sometimes needed to translate the ABI (as the callee-side intentionally does not pass `extra` to the fn in the vtable, no vtable shim is needed if the vtable function already takes its argument indirectly).
@@ -59,9 +60,9 @@ fn foo(s1: Box<StringData>, s2: Box<StringData>, cond: bool) {
5960
// this creates a VLA copy of either `s1.1` or `s2.1` on
6061
// the stack.
6162
let mut s = if cond {
62-
s1.1
63+
s1.data
6364
} else {
64-
s2.1
65+
s2.data
6566
};
6667
drop(s1);
6768
drop(s2);
@@ -118,7 +119,7 @@ The "guaranteed temporary elimination" rules require more work to teach. It migh
118119

119120
In Unsafe code, it is very easy to create unintended temporaries, such as in:
120121
```Rust
121-
unsafe fnf poke(ptr: *mut [u8]) { /* .. */ }
122+
unsafe fn poke(ptr: *mut [u8]) { /* .. */ }
122123
unsafe fn foo(mut a: [u8]) {
123124
let ptr: *mut [u8] = &mut a;
124125
// here, `a` must be copied to a temporary, because

0 commit comments

Comments
 (0)