diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-12-14 14:43:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-14 14:43:44 +0100 |
| commit | 5d8b2a5bf1ab1a762a19964d7a6e54b4c7b65285 (patch) | |
| tree | 716f7ce83946241793086dbfd7c657ec99bf2ac2 /compiler/rustc_llvm/llvm-wrapper/Linker.cpp | |
| parent | 3c45bff23dfbb13d9d28afe5dba57c028ba156da (diff) | |
| parent | d986924eb13a103fc79c474eded47a663c91bb7f (diff) | |
| download | rust-5d8b2a5bf1ab1a762a19964d7a6e54b4c7b65285.tar.gz rust-5d8b2a5bf1ab1a762a19964d7a6e54b4c7b65285.zip | |
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
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/Linker.cpp')
0 files changed, 0 insertions, 0 deletions
