Skip to content

Commit e195181

Browse files
committed
Add HashMap to std prelude
* Fix `HashMap` redundantly import errors * Replace HashMap by BTreeMap in tests suggested by Jonas
1 parent cdff918 commit e195181

File tree

75 files changed

+47
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+47
-194
lines changed

src/doc/rustc/src/lints/listing/warn-by-default.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -796,17 +796,17 @@ This lint detects imports that are never used. Some
796796
example code that triggers this lint:
797797

798798
```rust
799-
use std::collections::HashMap;
799+
use std::collections::BTreeMap;
800800
```
801801

802802
This will produce:
803803

804804
```text
805-
warning: unused import: `std::collections::HashMap`
805+
warning: unused import: `std::collections::BTreeMap`
806806
--> src/main.rs:1:5
807807
|
808-
1 | use std::collections::HashMap;
809-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
808+
1 | use std::collections::BTreeMap;
809+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
810810
|
811811
```
812812

src/libcore/cell.rs

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
//!
6969
//! ```
7070
//! use std::cell::{RefCell, RefMut};
71-
//! use std::collections::HashMap;
7271
//! use std::rc::Rc;
7372
//!
7473
//! fn main() {

src/libcore/hash/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ pub trait BuildHasher {
478478
/// [`HashMap`]:
479479
///
480480
/// ```
481-
/// use std::collections::HashMap;
482481
/// use std::hash::{BuildHasherDefault, Hasher};
483482
///
484483
/// #[derive(Default)]

src/libcore/option.rs

-4
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ impl<T: fmt::Debug> Option<T> {
993993
/// ```
994994
/// #![feature(option_expect_none)]
995995
///
996-
/// use std::collections::HashMap;
997996
/// let mut squares = HashMap::new();
998997
/// for i in -10..=10 {
999998
/// // This will not panic, since all keys are unique.
@@ -1004,7 +1003,6 @@ impl<T: fmt::Debug> Option<T> {
10041003
/// ```{.should_panic}
10051004
/// #![feature(option_expect_none)]
10061005
///
1007-
/// use std::collections::HashMap;
10081006
/// let mut sqrts = HashMap::new();
10091007
/// for i in -10..=10 {
10101008
/// // This will panic, since both negative and positive `i` will
@@ -1035,7 +1033,6 @@ impl<T: fmt::Debug> Option<T> {
10351033
/// ```
10361034
/// #![feature(option_unwrap_none)]
10371035
///
1038-
/// use std::collections::HashMap;
10391036
/// let mut squares = HashMap::new();
10401037
/// for i in -10..=10 {
10411038
/// // This will not panic, since all keys are unique.
@@ -1046,7 +1043,6 @@ impl<T: fmt::Debug> Option<T> {
10461043
/// ```{.should_panic}
10471044
/// #![feature(option_unwrap_none)]
10481045
///
1049-
/// use std::collections::HashMap;
10501046
/// let mut sqrts = HashMap::new();
10511047
/// for i in -10..=10 {
10521048
/// // This will panic, since both negative and positive `i` will

src/librustc_data_structures/owning_ref/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod owning_ref {
44
use std::cmp::{PartialEq, Ord, PartialOrd, Ordering};
55
use std::hash::{Hash, Hasher};
66
use std::collections::hash_map::DefaultHasher;
7-
use std::collections::HashMap;
87
use std::rc::Rc;
98

109
#[derive(Debug, PartialEq)]
@@ -379,7 +378,6 @@ mod owning_ref_mut {
379378
use std::cmp::{PartialEq, Ord, PartialOrd, Ordering};
380379
use std::hash::{Hash, Hasher};
381380
use std::collections::hash_map::DefaultHasher;
382-
use std::collections::HashMap;
383381

384382
#[derive(Debug, PartialEq)]
385383
struct Example(u32, String, [u8; 3]);

src/librustc_data_structures/sync.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
1818
//! depending on the value of cfg!(parallel_compiler).
1919
20-
use std::collections::HashMap;
2120
use std::hash::{Hash, BuildHasher};
2221
use std::marker::PhantomData;
2322
use std::ops::{Deref, DerefMut};

src/librustc_resolve/error_codes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ An undeclared type or module was used.
12501250
Erroneous code example:
12511251
12521252
```compile_fail,E0433
1253-
let map = HashMap::new();
1253+
let map = BTreeMap::new();
12541254
// error: failed to resolve: use of undeclared type or module `HashMap`
12551255
```
12561256
@@ -1259,8 +1259,8 @@ forget to import it:
12591259
12601260
12611261
```
1262-
use std::collections::HashMap; // HashMap has been imported.
1263-
let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
1262+
use std::collections::BTreeMap; // BTreeMap has been imported.
1263+
let map: BTreeMap<u32, u32> = BTreeMap::new(); // So it can be used!
12641264
```
12651265
"##,
12661266

src/libserialize/tests/json.rs

-6
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@ fn test_as_null(){
849849
#[test]
850850
fn test_encode_hashmap_with_numeric_key() {
851851
use std::str::from_utf8;
852-
use std::collections::HashMap;
853852
let mut hm: HashMap<usize, bool> = HashMap::new();
854853
hm.insert(1, true);
855854
let mut mem_buf = Vec::new();
@@ -864,7 +863,6 @@ fn test_encode_hashmap_with_numeric_key() {
864863
#[test]
865864
fn test_prettyencode_hashmap_with_numeric_key() {
866865
use std::str::from_utf8;
867-
use std::collections::HashMap;
868866
let mut hm: HashMap<usize, bool> = HashMap::new();
869867
hm.insert(1, true);
870868
let mut mem_buf = Vec::new();
@@ -930,7 +928,6 @@ fn test_prettyencoder_indent_level_param() {
930928

931929
#[test]
932930
fn test_hashmap_with_enum_key() {
933-
use std::collections::HashMap;
934931
#[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
935932
enum Enum {
936933
Foo,
@@ -947,7 +944,6 @@ fn test_hashmap_with_enum_key() {
947944

948945
#[test]
949946
fn test_hashmap_with_numeric_key_can_handle_double_quote_delimited_key() {
950-
use std::collections::HashMap;
951947
let json_str = "{\"1\":true}";
952948
let json_obj = match from_str(json_str) {
953949
Err(_) => panic!("Unable to parse json_str: {:?}", json_str),
@@ -959,7 +955,6 @@ fn test_hashmap_with_numeric_key_can_handle_double_quote_delimited_key() {
959955

960956
#[test]
961957
fn test_hashmap_with_numeric_key_will_error_with_string_keys() {
962-
use std::collections::HashMap;
963958
let json_str = "{\"a\":true}";
964959
let json_obj = match from_str(json_str) {
965960
Err(_) => panic!("Unable to parse json_str: {:?}", json_str),
@@ -1267,7 +1262,6 @@ fn test_to_json() {
12671262

12681263
#[test]
12691264
fn test_encode_hashmap_with_arbitrary_key() {
1270-
use std::collections::HashMap;
12711265
#[derive(PartialEq, Eq, Hash, RustcEncodable)]
12721266
struct ArbitraryType(usize);
12731267
let mut hm: HashMap<ArbitraryType, bool> = HashMap::new();

src/libserialize/tests/opaque.rs

-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ fn test_sequence() {
263263

264264
#[test]
265265
fn test_hash_map() {
266-
use std::collections::HashMap;
267266
let mut map = HashMap::new();
268267
for i in -100i64..100i64 {
269268
map.insert(i * 100000, i * 10000);

0 commit comments

Comments
 (0)