Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Unsized Rvalues #51131

Merged
merged 10 commits into from
Aug 19, 2018
Prev Previous commit
Next Next commit
Update the unstable book regarding [e; dyn n].
  • Loading branch information
qnighy committed Aug 18, 2018
commit 438edc3d5e60f82f22db07b6e8562fc8836a4cbe
6 changes: 3 additions & 3 deletions src/doc/unstable-book/src/language-features/unsized-locals.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ One of the objectives of this feature is to allow `Box<dyn FnOnce>`, instead of

## Variable length arrays

The RFC also describes an extension to the array literal syntax `[e; n]`: you'll be able to specify non-const `n` to allocate variable length arrays on the stack.
The RFC also describes an extension to the array literal syntax: `[e; dyn n]`. In the syntax, `n` isn't necessarily a constant expression. The array is dynamically allocated on the stack and has the type of `[T]`, instead of `[T; n]`.

```rust,ignore
#![feature(unsized_locals)]

fn mergesort<T: Ord>(a: &mut [T]) {
let mut tmp = [T; a.len()];
let mut tmp = [T; dyn a.len()];
// ...
}

Expand All @@ -144,7 +144,7 @@ fn main() {
}
```

VLAs are not implemented yet.
VLAs are not implemented yet. The syntax isn't final, either. We may need an alternative syntax for Rust 2015 because, in Rust 2015, expressions like `[e; dyn(1)]` would be ambiguous. One possible alternative proposed in the RFC is `[e; n]`: if `n` captures one or more local variables, then it is considered as `[e; dyn n]`.

## Advisory on stack usage

Expand Down