Skip to content

[WIP] Add {HashMap,HashSet} to std's prelude #63418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,17 @@ This lint detects imports that are never used. Some
example code that triggers this lint:

```rust
use std::collections::HashMap;
use std::collections::BTreeMap;
```

This will produce:

```text
warning: unused import: `std::collections::HashMap`
warning: unused import: `std::collections::BTreeMap`
--> src/main.rs:1:5
|
1 | use std::collections::HashMap;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1 | use std::collections::BTreeMap;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
```

Expand Down
1 change: 0 additions & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
//!
//! ```
//! use std::cell::{RefCell, RefMut};
//! use std::collections::HashMap;
//! use std::rc::Rc;
//!
//! fn main() {
Expand Down
1 change: 0 additions & 1 deletion src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ pub trait BuildHasher {
/// [`HashMap`]:
///
/// ```
/// use std::collections::HashMap;
/// use std::hash::{BuildHasherDefault, Hasher};
///
/// #[derive(Default)]
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ impl<T: fmt::Debug> Option<T> {
/// ```
/// #![feature(option_expect_none)]
///
/// use std::collections::HashMap;
/// let mut squares = HashMap::new();
/// for i in -10..=10 {
/// // This will not panic, since all keys are unique.
Expand All @@ -1004,7 +1003,6 @@ impl<T: fmt::Debug> Option<T> {
/// ```{.should_panic}
/// #![feature(option_expect_none)]
///
/// use std::collections::HashMap;
/// let mut sqrts = HashMap::new();
/// for i in -10..=10 {
/// // This will panic, since both negative and positive `i` will
Expand Down Expand Up @@ -1035,7 +1033,6 @@ impl<T: fmt::Debug> Option<T> {
/// ```
/// #![feature(option_unwrap_none)]
///
/// use std::collections::HashMap;
/// let mut squares = HashMap::new();
/// for i in -10..=10 {
/// // This will not panic, since all keys are unique.
Expand All @@ -1046,7 +1043,6 @@ impl<T: fmt::Debug> Option<T> {
/// ```{.should_panic}
/// #![feature(option_unwrap_none)]
///
/// use std::collections::HashMap;
/// let mut sqrts = HashMap::new();
/// for i in -10..=10 {
/// // This will panic, since both negative and positive `i` will
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_data_structures/owning_ref/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod owning_ref {
use std::cmp::{PartialEq, Ord, PartialOrd, Ordering};
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::rc::Rc;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -379,7 +378,6 @@ mod owning_ref_mut {
use std::cmp::{PartialEq, Ord, PartialOrd, Ordering};
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;

#[derive(Debug, PartialEq)]
struct Example(u32, String, [u8; 3]);
Expand Down
1 change: 0 additions & 1 deletion src/librustc_data_structures/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
//! depending on the value of cfg!(parallel_compiler).

use std::collections::HashMap;
use std::hash::{Hash, BuildHasher};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ An undeclared type or module was used.
Erroneous code example:

```compile_fail,E0433
let map = HashMap::new();
let map = BTreeMap::new();
// error: failed to resolve: use of undeclared type or module `HashMap`
```

Expand All @@ -1259,8 +1259,8 @@ forget to import it:


```
use std::collections::HashMap; // HashMap has been imported.
let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
use std::collections::BTreeMap; // BTreeMap has been imported.
let map: BTreeMap<u32, u32> = BTreeMap::new(); // So it can be used!
```
"##,

Expand Down
6 changes: 0 additions & 6 deletions src/libserialize/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ fn test_as_null(){
#[test]
fn test_encode_hashmap_with_numeric_key() {
use std::str::from_utf8;
use std::collections::HashMap;
let mut hm: HashMap<usize, bool> = HashMap::new();
hm.insert(1, true);
let mut mem_buf = Vec::new();
Expand All @@ -864,7 +863,6 @@ fn test_encode_hashmap_with_numeric_key() {
#[test]
fn test_prettyencode_hashmap_with_numeric_key() {
use std::str::from_utf8;
use std::collections::HashMap;
let mut hm: HashMap<usize, bool> = HashMap::new();
hm.insert(1, true);
let mut mem_buf = Vec::new();
Expand Down Expand Up @@ -930,7 +928,6 @@ fn test_prettyencoder_indent_level_param() {

#[test]
fn test_hashmap_with_enum_key() {
use std::collections::HashMap;
#[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
enum Enum {
Foo,
Expand All @@ -947,7 +944,6 @@ fn test_hashmap_with_enum_key() {

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

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

#[test]
fn test_encode_hashmap_with_arbitrary_key() {
use std::collections::HashMap;
#[derive(PartialEq, Eq, Hash, RustcEncodable)]
struct ArbitraryType(usize);
let mut hm: HashMap<ArbitraryType, bool> = HashMap::new();
Expand Down
1 change: 0 additions & 1 deletion src/libserialize/tests/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ fn test_sequence() {

#[test]
fn test_hash_map() {
use std::collections::HashMap;
let mut map = HashMap::new();
for i in -100i64..100i64 {
map.insert(i * 100000, i * 10000);
Expand Down
Loading