rust/library
Dylan DPC 35188440b5
Rollup merge of #96089 - ojeda:no-vec-no_global_oom_handling, r=Mark-Simulacrum
`alloc`: make `vec!` unavailable under `no_global_oom_handling`

`alloc`: make `vec!` unavailable under `no_global_oom_handling`

The `vec!` macro has 3 rules, but two are not usable under
`no_global_oom_handling` builds of the standard library
(even with a zero size):

```rust
let _ = vec![42];    // Error: requires `exchange_malloc` lang_item.
let _ = vec![42; 0]; // Error: cannot find function `from_elem`.
```

Thus those two rules should not be available to begin with.

The remaining one, with an empty matcher, is just a shorthand for
`new()` and may not make as much sense to have alone, since the
idea behind `vec!` is to enable `Vec`s to be defined with the same
syntax as array expressions. Furthermore, the documentation can be
confusing since it shows the other rules.

Thus perhaps it is better and simpler to disable `vec!` entirely
under `no_global_oom_handling` environments, and let users call
`new()` instead:

```rust
let _: Vec<i32> = vec![];
let _: Vec<i32> = Vec::new();
```

Notwithstanding this, a `try_vec!` macro would be useful, such as
the one introduced in https://github.com/rust-lang/rust/pull/95051.

If the shorthand for `new()` is deemed worth keeping on its own,
then it may be interesting to have a separate `vec!` macro with
a single rule and different, simpler documentation.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-04-19 14:43:19 +02:00
..
alloc Rollup merge of #96089 - ojeda:no-vec-no_global_oom_handling, r=Mark-Simulacrum 2022-04-19 14:43:19 +02:00
backtrace@b02ed04a7e
core Auto merge of #92287 - JulianKnodt:slice_remainder, r=yaahc 2022-04-18 23:34:24 +00:00
panic_abort fix some unused constant warning on some Windows targets 2022-04-08 08:36:56 -04:00
panic_unwind
portable-simd portable-simd: use simd_arith_offset to avoid ptr-int transmutation 2022-04-12 11:09:26 -04:00
proc_macro Rollup merge of #95308 - bjorn3:more_stable_proc_macro, r=Mark-Simulacrum 2022-04-09 12:52:02 +02:00
profiler_builtins
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Auto merge of #96042 - m-ou-se:one-reentrant-mutex, r=Amanieu 2022-04-18 12:15:39 +00:00
stdarch@d215afe9d1 Bump stdarch 2022-04-11 21:40:31 -04:00
test Auto merge of #95678 - pietroalbini:pa-1.62.0-bootstrap, r=Mark-Simulacrum 2022-04-07 07:34:04 +00:00
unwind Auto merge of #95678 - pietroalbini:pa-1.62.0-bootstrap, r=Mark-Simulacrum 2022-04-07 07:34:04 +00:00