rust/library/alloc
Guillaume Gomez 5d8b2a5bf1
Rollup merge of #79918 - woodruffw-forks:ww/doc-initializer-side-effects, r=dtolnay
doc(array,vec): add notes about side effects when empty-initializing

Copying some context from a conversation in the Rust discord:

* Both `vec![T; 0]` and `[T; 0]` are syntactically valid, and produce empty containers of their respective types

* Both *also* have side effects:

```rust
fn side_effect() -> String {
    println!("side effect!");

    "foo".into()
}

fn main() {
    println!("before!");

    let x = vec![side_effect(); 0];

    let y = [side_effect(); 0];

    println!("{:?}, {:?}", x, y);
}
```

produces:

```
before!
side effect!
side effect!
[], []
```

This PR just adds two small notes to each's documentation, warning users that side effects can occur.

I've also submitted a clippy proposal: https://github.com/rust-lang/rust-clippy/issues/6439
2020-12-14 14:43:44 +01:00
..
benches Reorder benches const variable 2020-09-29 21:39:24 +08:00
src Rollup merge of #79918 - woodruffw-forks:ww/doc-initializer-side-effects, r=dtolnay 2020-12-14 14:43:44 +01:00
tests Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
Cargo.toml add options to use optimized and mangled compiler builtins 2020-11-15 08:23:31 +01:00