Auto merge of #78461 - TimDiekmann:vec-alloc, r=Amanieu

Add support for custom allocators in `Vec`

This follows the [roadmap](https://github.com/rust-lang/wg-allocators/issues/7) of the allocator WG to add custom allocators to collections.

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- #71873: Crater-test to solve rust-lang/wg-allocators#1
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate
This commit is contained in:
bors 2020-11-21 22:46:50 +00:00
commit a1a13b2bc4
13 changed files with 513 additions and 215 deletions

View file

@ -13,7 +13,7 @@
// gdb-check:$1 = &[i32](len: 4) = {0, 1, 2, 3}
// gdb-command: print vec
// gdb-check:$2 = Vec<u64>(len: 4, cap: [...]) = {4, 5, 6, 7}
// gdb-check:$2 = Vec<u64, alloc::alloc::Global>(len: 4, cap: [...]) = {4, 5, 6, 7}
// gdb-command: print str_slice
// gdb-check:$3 = "IAMA string slice!"
@ -74,7 +74,7 @@
// NOTE: While slices have a .natvis entry that works in VS & VS Code, it fails in CDB 10.0.18362.1
// cdb-command: dx vec,d
// cdb-check:vec,d [...] : { size=4 } [Type: [...]::Vec<u64>]
// cdb-check:vec,d [...] : { size=4 } [Type: [...]::Vec<u64, alloc::alloc::Global>]
// cdb-check: [size] : 4 [Type: [...]]
// cdb-check: [capacity] : [...] [Type: [...]]
// cdb-check: [0] : 4 [Type: unsigned __int64]

View file

@ -1,10 +1,11 @@
// aux-build:impl_trait_aux.rs
// edition:2018
// ignore-tidy-linelength
extern crate impl_trait_aux;
// @has impl_trait/fn.func.html
// @has - '//pre[@class="rust fn"]' "pub fn func<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
// @has - '//pre[@class="rust fn"]' "pub fn func<'a>(_x: impl Clone + Into<Vec<u8, Global>> + 'a)"
// @!has - '//pre[@class="rust fn"]' 'where'
pub use impl_trait_aux::func;
@ -31,7 +32,7 @@ pub use impl_trait_aux::func4;
pub use impl_trait_aux::async_fn;
// @has impl_trait/struct.Foo.html
// @has - '//*[@id="method.method"]//code' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
// @has - '//*[@id="method.method"]//code' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8, Global>> + 'a)"
// @!has - '//*[@id="method.method"]//code' 'where'
pub use impl_trait_aux::Foo;

View file

@ -6,7 +6,7 @@ LL | type Ty = Vec<[u8]>;
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `[u8]`

View file

@ -17,7 +17,7 @@ LL | let x: Vec<dyn Trait + Sized> = Vec::new();
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `dyn Trait`

View file

@ -1,4 +1,6 @@
use std::cell::Cell;
fn main() {
let _: Vec<&str, "a"> = Vec::new();
let _: Cell<&str, "a"> = Cell::new("");
//~^ ERROR wrong number of generic arguments
}

View file

@ -1,8 +1,8 @@
error[E0107]: wrong number of generic arguments: expected 1, found 2
--> $DIR/invalid-constant-in-args.rs:2:22
--> $DIR/invalid-constant-in-args.rs:4:23
|
LL | let _: Vec<&str, "a"> = Vec::new();
| ^^^ unexpected const argument
LL | let _: Cell<&str, "a"> = Cell::new("");
| ^^^ unexpected const argument
error: aborting due to previous error

View file

@ -6,7 +6,7 @@ LL | fn iceman(c: Vec<[i32]>) {}
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `[i32]`

View file

@ -7,7 +7,7 @@ impl Reactor {
input_cells: Vec::new()
//~^ ERROR cannot find value `input_cells` in this scope
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait
//~| ERROR wrong number of type arguments: expected 1, found 0
//~| ERROR wrong number of type arguments: expected at least 1, found 0
}
}

View file

@ -10,11 +10,11 @@ error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
LL | input_cells: Vec::new()
| ^^^^^ only `Fn` traits may use parentheses
error[E0107]: wrong number of type arguments: expected 1, found 0
error[E0107]: wrong number of type arguments: expected at least 1, found 0
--> $DIR/issue-34255-1.rs:7:22
|
LL | input_cells: Vec::new()
| ^^^^^^^^^^ expected 1 type argument
| ^^^^^^^^^^ expected at least 1 type argument
error: aborting due to 3 previous errors