Skip to content

Commit 31cd367

Browse files
Auto merge of rust-lang#148545 - cramertj:alloc-map, r=Amanieu
Add allocator parameter to HashMap Hashbrown support originally added in rust-lang/hashbrown#133 Part of rust-lang/wg-allocators#7 ~See also: hashset support in rust-lang#148550 (Edit: merged into this PR for crater)
2 parents 4586feb + ef7616d commit 31cd367

12 files changed

Lines changed: 547 additions & 264 deletions

library/std/src/collections/hash/map.rs

Lines changed: 216 additions & 73 deletions
Large diffs are not rendered by default.

library/std/src/collections/hash/set.rs

Lines changed: 286 additions & 143 deletions
Large diffs are not rendered by default.

tests/ui/generics/wrong-number-of-args.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ mod stdlib {
321321
//~| ERROR struct takes at least 2
322322
//~| HELP add missing
323323

324-
type D = HashMap<usize, String, char, f64>;
325-
//~^ ERROR struct takes at most 3
326-
//~| HELP remove the
327-
328324
type E = HashMap<>;
329325
//~^ ERROR struct takes at least 2 generic arguments but 0 generic arguments
330326
//~| HELP add missing

tests/ui/generics/wrong-number-of-args.stderr

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -926,16 +926,8 @@ help: add missing generic arguments
926926
LL | type C = HashMap<'static, K, V>;
927927
| ++++++
928928

929-
error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments were supplied
930-
--> $DIR/wrong-number-of-args.rs:324:18
931-
|
932-
LL | type D = HashMap<usize, String, char, f64>;
933-
| ^^^^^^^ ----- help: remove the unnecessary generic argument
934-
| |
935-
| expected at most 3 generic arguments
936-
937929
error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied
938-
--> $DIR/wrong-number-of-args.rs:328:18
930+
--> $DIR/wrong-number-of-args.rs:324:18
939931
|
940932
LL | type E = HashMap<>;
941933
| ^^^^^^^ expected at least 2 generic arguments
@@ -946,7 +938,7 @@ LL | type E = HashMap<K, V>;
946938
| ++++
947939

948940
error[E0107]: missing generics for enum `Result`
949-
--> $DIR/wrong-number-of-args.rs:334:18
941+
--> $DIR/wrong-number-of-args.rs:330:18
950942
|
951943
LL | type A = Result;
952944
| ^^^^^^ expected 2 generic arguments
@@ -957,7 +949,7 @@ LL | type A = Result<T, E>;
957949
| ++++++
958950

959951
error[E0107]: enum takes 2 generic arguments but 1 generic argument was supplied
960-
--> $DIR/wrong-number-of-args.rs:338:18
952+
--> $DIR/wrong-number-of-args.rs:334:18
961953
|
962954
LL | type B = Result<String>;
963955
| ^^^^^^ ------ supplied 1 generic argument
@@ -970,15 +962,15 @@ LL | type B = Result<String, E>;
970962
| +++
971963

972964
error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was supplied
973-
--> $DIR/wrong-number-of-args.rs:342:18
965+
--> $DIR/wrong-number-of-args.rs:338:18
974966
|
975967
LL | type C = Result<'static>;
976968
| ^^^^^^--------- help: remove the unnecessary generics
977969
| |
978970
| expected 0 lifetime arguments
979971

980972
error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied
981-
--> $DIR/wrong-number-of-args.rs:342:18
973+
--> $DIR/wrong-number-of-args.rs:338:18
982974
|
983975
LL | type C = Result<'static>;
984976
| ^^^^^^ expected 2 generic arguments
@@ -989,15 +981,15 @@ LL | type C = Result<'static, T, E>;
989981
| ++++++
990982

991983
error[E0107]: enum takes 2 generic arguments but 3 generic arguments were supplied
992-
--> $DIR/wrong-number-of-args.rs:348:18
984+
--> $DIR/wrong-number-of-args.rs:344:18
993985
|
994986
LL | type D = Result<usize, String, char>;
995987
| ^^^^^^ ------ help: remove the unnecessary generic argument
996988
| |
997989
| expected 2 generic arguments
998990

999991
error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied
1000-
--> $DIR/wrong-number-of-args.rs:352:18
992+
--> $DIR/wrong-number-of-args.rs:348:18
1001993
|
1002994
LL | type E = Result<>;
1003995
| ^^^^^^ expected 2 generic arguments
@@ -1007,7 +999,7 @@ help: add missing generic arguments
1007999
LL | type E = Result<T, E>;
10081000
| ++++
10091001

1010-
error: aborting due to 71 previous errors
1002+
error: aborting due to 70 previous errors
10111003

10121004
Some errors have detailed explanations: E0106, E0107.
10131005
For more information about an error, try `rustc --explain E0106`.

tests/ui/inference/issue-71732.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | .get(&"key".into())
1010
- impl Borrow<str> for String;
1111
- impl<T> Borrow<T> for T
1212
where T: ?Sized;
13-
note: required by a bound in `HashMap::<K, V, S>::get`
13+
note: required by a bound in `HashMap::<K, V, S, A>::get`
1414
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
1515
help: consider specifying the generic argument
1616
|

tests/ui/moves/suggest-clone-when-some-obligation-is-unmet.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | let mut copy: Vec<U> = map.clone().into_values().collect();
66
| |
77
| move occurs because value has type `HashMap<T, U, Hash128_1>`, which does not implement the `Copy` trait
88
|
9-
note: `HashMap::<K, V, S>::into_values` takes ownership of the receiver `self`, which moves value
9+
note: `HashMap::<K, V, S, A>::into_values` takes ownership of the receiver `self`, which moves value
1010
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
1111
note: if `Hash128_1` implemented `Clone`, you could clone the value
1212
--> $DIR/suggest-clone-when-some-obligation-is-unmet.rs:8:1

tests/ui/privacy/suggest-box-new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
let _ = std::collections::HashMap();
1515
//~^ ERROR expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
1616
let _ = std::collections::HashMap {};
17-
//~^ ERROR cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
17+
//~^ ERROR cannot construct `HashMap<_, _, _, _>` with struct literal syntax due to private fields
1818
let _ = Box {}; //~ ERROR cannot construct `Box<_, _>` with struct literal syntax due to private fields
1919

2020
// test that we properly instantiate the parameter of `Box::<T>::new` with an inference variable

tests/ui/privacy/suggest-box-new.stderr

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ LL | let _ = std::collections::HashMap();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
8+
::: $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
89
|
910
= note: `std::collections::HashMap` defined here
1011
help: you might have meant to use an associated function to build this type
1112
|
1213
LL | let _ = std::collections::HashMap::new();
1314
| +++++
1415
LL - let _ = std::collections::HashMap();
15-
LL + let _ = std::collections::HashMap::with_capacity(_);
16+
LL + let _ = std::collections::HashMap::new_in(_);
1617
|
1718
LL - let _ = std::collections::HashMap();
18-
LL + let _ = std::collections::HashMap::with_hasher(_);
19+
LL + let _ = std::collections::HashMap::with_capacity(_);
1920
|
2021
LL - let _ = std::collections::HashMap();
21-
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
22+
LL + let _ = std::collections::HashMap::with_capacity_in(_, _);
2223
|
24+
= and 4 other candidates
2325
help: consider using the `Default` trait
2426
|
2527
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
@@ -73,7 +75,7 @@ LL - })),
7375
LL + wtf: Some(<Box as std::default::Default>::default()),
7476
|
7577

76-
error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
78+
error: cannot construct `HashMap<_, _, _, _>` with struct literal syntax due to private fields
7779
--> $DIR/suggest-box-new.rs:16:13
7880
|
7981
LL | let _ = std::collections::HashMap {};
@@ -86,14 +88,15 @@ LL - let _ = std::collections::HashMap {};
8688
LL + let _ = std::collections::HashMap::new();
8789
|
8890
LL - let _ = std::collections::HashMap {};
89-
LL + let _ = std::collections::HashMap::with_capacity(_);
91+
LL + let _ = std::collections::HashMap::new_in(_);
9092
|
9193
LL - let _ = std::collections::HashMap {};
92-
LL + let _ = std::collections::HashMap::with_hasher(_);
94+
LL + let _ = std::collections::HashMap::with_capacity(_);
9395
|
9496
LL - let _ = std::collections::HashMap {};
95-
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
97+
LL + let _ = std::collections::HashMap::with_capacity_in(_, _);
9698
|
99+
= and 4 other candidates
97100
help: consider using the `Default` trait
98101
|
99102
LL - let _ = std::collections::HashMap {};

tests/ui/suggestions/multi-suggestion.ascii.stderr

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ LL | let _ = std::collections::HashMap();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
8+
::: $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
89
|
910
= note: `std::collections::HashMap` defined here
1011
help: you might have meant to use an associated function to build this type
1112
|
1213
LL | let _ = std::collections::HashMap::new();
1314
| +++++
1415
LL - let _ = std::collections::HashMap();
15-
LL + let _ = std::collections::HashMap::with_capacity(_);
16+
LL + let _ = std::collections::HashMap::new_in(_);
1617
|
1718
LL - let _ = std::collections::HashMap();
18-
LL + let _ = std::collections::HashMap::with_hasher(_);
19+
LL + let _ = std::collections::HashMap::with_capacity(_);
1920
|
2021
LL - let _ = std::collections::HashMap();
21-
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
22+
LL + let _ = std::collections::HashMap::with_capacity_in(_, _);
2223
|
24+
= and 4 other candidates
2325
help: consider using the `Default` trait
2426
|
2527
LL | let _ = <std::collections::HashMap as std::default::Default>::default();
@@ -73,7 +75,7 @@ LL - })),
7375
LL + wtf: Some(<Box as std::default::Default>::default()),
7476
|
7577

76-
error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
78+
error: cannot construct `HashMap<_, _, _, _>` with struct literal syntax due to private fields
7779
--> $DIR/multi-suggestion.rs:19:13
7880
|
7981
LL | let _ = std::collections::HashMap {};
@@ -86,14 +88,15 @@ LL - let _ = std::collections::HashMap {};
8688
LL + let _ = std::collections::HashMap::new();
8789
|
8890
LL - let _ = std::collections::HashMap {};
89-
LL + let _ = std::collections::HashMap::with_capacity(_);
91+
LL + let _ = std::collections::HashMap::new_in(_);
9092
|
9193
LL - let _ = std::collections::HashMap {};
92-
LL + let _ = std::collections::HashMap::with_hasher(_);
94+
LL + let _ = std::collections::HashMap::with_capacity(_);
9395
|
9496
LL - let _ = std::collections::HashMap {};
95-
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
97+
LL + let _ = std::collections::HashMap::with_capacity_in(_, _);
9698
|
99+
= and 4 other candidates
97100
help: consider using the `Default` trait
98101
|
99102
LL - let _ = std::collections::HashMap {};

tests/ui/suggestions/multi-suggestion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ fn main() {
1717
let _ = std::collections::HashMap();
1818
//[ascii]~^ ERROR expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
1919
let _ = std::collections::HashMap {};
20-
//[ascii]~^ ERROR cannot construct `HashMap<_, _, _>` with struct literal syntax due to private fields
20+
//[ascii]~^ ERROR cannot construct `HashMap<_, _, _, _>` with struct literal syntax due to private fields
2121
let _ = Box {}; //[ascii]~ ERROR cannot construct `Box<_, _>` with struct literal syntax due to private fields
2222
}

0 commit comments

Comments
 (0)