Skip to content

Commit 1068655

Browse files
committed
cargo fix --edition-idioms
1 parent 3ac830c commit 1068655

16 files changed

+85
-119
lines changed

benches/bench.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(test)]
2-
extern crate fnv;
3-
extern crate rand;
2+
43
extern crate test;
54
#[macro_use]
65
extern crate lazy_static;
@@ -13,8 +12,6 @@ type FnvBuilder = BuildHasherDefault<FnvHasher>;
1312
use test::black_box;
1413
use test::Bencher;
1514

16-
extern crate indexmap;
17-
1815
use indexmap::IndexMap;
1916

2017
use std::collections::HashMap;

benches/faststring.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#![feature(test)]
2-
extern crate lazy_static;
3-
extern crate rand;
2+
43
extern crate test;
54

65
use test::Bencher;
76

8-
extern crate indexmap;
9-
107
use indexmap::IndexMap;
118

129
use std::collections::HashMap;

build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate autocfg;
2-
31
fn main() {
42
let ac = autocfg::new();
53
ac.emit_sysroot_crate("std");

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// We *mostly* avoid unsafe code, but `map::core::raw` allows it to use `RawTable` buckets.
22
#![deny(unsafe_code)]
3+
#![warn(rust_2018_idioms)]
34
#![doc(html_root_url = "https://docs.rs/indexmap/1/")]
45
#![no_std]
56

@@ -33,8 +34,6 @@
3334
//! to use alternate hashers:
3435
//!
3536
//! ```
36-
//! # extern crate fnv;
37-
//! # extern crate fxhash;
3837
//! use fnv::FnvBuildHasher;
3938
//! use fxhash::FxBuildHasher;
4039
//! use indexmap::{IndexMap, IndexSet};
@@ -86,8 +85,6 @@ extern crate alloc;
8685
#[macro_use]
8786
extern crate std;
8887

89-
extern crate hashbrown;
90-
9188
#[cfg(not(has_std))]
9289
use alloc::vec::{self, Vec};
9390

src/macros.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
/// ## Example
66
///
77
/// ```
8-
/// #[macro_use] extern crate indexmap;
9-
/// # fn main() {
8+
/// use indexmap::indexmap;
109
///
1110
/// let map = indexmap!{
1211
/// "a" => 1,
@@ -18,7 +17,6 @@
1817
///
1918
/// // "a" is the first key
2019
/// assert_eq!(map.keys().next(), Some(&"a"));
21-
/// # }
2220
/// ```
2321
macro_rules! indexmap {
2422
(@single $($x:tt)*) => (());
@@ -44,8 +42,7 @@ macro_rules! indexmap {
4442
/// ## Example
4543
///
4644
/// ```
47-
/// #[macro_use] extern crate indexmap;
48-
/// # fn main() {
45+
/// use indexmap::indexset;
4946
///
5047
/// let set = indexset!{
5148
/// "a",
@@ -57,7 +54,6 @@ macro_rules! indexmap {
5754
///
5855
/// // "a" is the first value
5956
/// assert_eq!(set.iter().next(), Some(&"a"));
60-
/// # }
6157
/// ```
6258
macro_rules! indexset {
6359
(@single $($x:tt)*) => (());

src/map.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ where
129129
V: fmt::Debug,
130130
S: BuildHasher,
131131
{
132-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
132+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133133
if cfg!(not(feature = "test_debug")) {
134134
f.debug_map().entries(self.iter()).finish()
135135
} else {
@@ -291,42 +291,42 @@ where
291291
/// in-place manipulation.
292292
///
293293
/// Computes in **O(1)** time (amortized average).
294-
pub fn entry(&mut self, key: K) -> Entry<K, V> {
294+
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
295295
let hash = self.hash(&key);
296296
self.core.entry(hash, key)
297297
}
298298

299299
/// Return an iterator over the key-value pairs of the map, in their order
300-
pub fn iter(&self) -> Iter<K, V> {
300+
pub fn iter(&self) -> Iter<'_, K, V> {
301301
Iter {
302302
iter: self.as_entries().iter(),
303303
}
304304
}
305305

306306
/// Return an iterator over the key-value pairs of the map, in their order
307-
pub fn iter_mut(&mut self) -> IterMut<K, V> {
307+
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
308308
IterMut {
309309
iter: self.as_entries_mut().iter_mut(),
310310
}
311311
}
312312

313313
/// Return an iterator over the keys of the map, in their order
314-
pub fn keys(&self) -> Keys<K, V> {
314+
pub fn keys(&self) -> Keys<'_, K, V> {
315315
Keys {
316316
iter: self.as_entries().iter(),
317317
}
318318
}
319319

320320
/// Return an iterator over the values of the map, in their order
321-
pub fn values(&self) -> Values<K, V> {
321+
pub fn values(&self) -> Values<'_, K, V> {
322322
Values {
323323
iter: self.as_entries().iter(),
324324
}
325325
}
326326

327327
/// Return an iterator over mutable references to the the values of the map,
328328
/// in their order
329-
pub fn values_mut(&mut self) -> ValuesMut<K, V> {
329+
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
330330
ValuesMut {
331331
iter: self.as_entries_mut().iter_mut(),
332332
}
@@ -663,7 +663,7 @@ where
663663

664664
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
665665
/// Keeps the allocated memory for reuse.
666-
pub fn drain(&mut self, range: RangeFull) -> Drain<K, V> {
666+
pub fn drain(&mut self, range: RangeFull) -> Drain<'_, K, V> {
667667
Drain {
668668
iter: self.core.drain(range),
669669
}
@@ -723,7 +723,7 @@ impl<K, V, S> IndexMap<K, V, S> {
723723
///
724724
/// [`keys`]: struct.IndexMap.html#method.keys
725725
/// [`IndexMap`]: struct.IndexMap.html
726-
pub struct Keys<'a, K: 'a, V: 'a> {
726+
pub struct Keys<'a, K, V> {
727727
pub(crate) iter: SliceIter<'a, Bucket<K, V>>,
728728
}
729729

@@ -755,7 +755,7 @@ impl<'a, K, V> Clone for Keys<'a, K, V> {
755755
}
756756

757757
impl<'a, K: fmt::Debug, V> fmt::Debug for Keys<'a, K, V> {
758-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
758+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
759759
f.debug_list().entries(self.clone()).finish()
760760
}
761761
}
@@ -767,7 +767,7 @@ impl<'a, K: fmt::Debug, V> fmt::Debug for Keys<'a, K, V> {
767767
///
768768
/// [`values`]: struct.IndexMap.html#method.values
769769
/// [`IndexMap`]: struct.IndexMap.html
770-
pub struct Values<'a, K: 'a, V: 'a> {
770+
pub struct Values<'a, K, V> {
771771
iter: SliceIter<'a, Bucket<K, V>>,
772772
}
773773

@@ -799,7 +799,7 @@ impl<'a, K, V> Clone for Values<'a, K, V> {
799799
}
800800

801801
impl<'a, K, V: fmt::Debug> fmt::Debug for Values<'a, K, V> {
802-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
802+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
803803
f.debug_list().entries(self.clone()).finish()
804804
}
805805
}
@@ -811,7 +811,7 @@ impl<'a, K, V: fmt::Debug> fmt::Debug for Values<'a, K, V> {
811811
///
812812
/// [`values_mut`]: struct.IndexMap.html#method.values_mut
813813
/// [`IndexMap`]: struct.IndexMap.html
814-
pub struct ValuesMut<'a, K: 'a, V: 'a> {
814+
pub struct ValuesMut<'a, K, V> {
815815
iter: SliceIterMut<'a, Bucket<K, V>>,
816816
}
817817

@@ -840,7 +840,7 @@ impl<'a, K, V> ExactSizeIterator for ValuesMut<'a, K, V> {
840840
///
841841
/// [`iter`]: struct.IndexMap.html#method.iter
842842
/// [`IndexMap`]: struct.IndexMap.html
843-
pub struct Iter<'a, K: 'a, V: 'a> {
843+
pub struct Iter<'a, K, V> {
844844
iter: SliceIter<'a, Bucket<K, V>>,
845845
}
846846

@@ -872,7 +872,7 @@ impl<'a, K, V> Clone for Iter<'a, K, V> {
872872
}
873873

874874
impl<'a, K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'a, K, V> {
875-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
875+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
876876
f.debug_list().entries(self.clone()).finish()
877877
}
878878
}
@@ -884,7 +884,7 @@ impl<'a, K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'a, K, V> {
884884
///
885885
/// [`iter_mut`]: struct.IndexMap.html#method.iter_mut
886886
/// [`IndexMap`]: struct.IndexMap.html
887-
pub struct IterMut<'a, K: 'a, V: 'a> {
887+
pub struct IterMut<'a, K, V> {
888888
iter: SliceIterMut<'a, Bucket<K, V>>,
889889
}
890890

@@ -936,7 +936,7 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
936936
}
937937

938938
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
939-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
939+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
940940
let iter = self.iter.as_slice().iter().map(Bucket::refs);
941941
f.debug_list().entries(iter).finish()
942942
}
@@ -949,11 +949,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
949949
///
950950
/// [`drain`]: struct.IndexMap.html#method.drain
951951
/// [`IndexMap`]: struct.IndexMap.html
952-
pub struct Drain<'a, K, V>
953-
where
954-
K: 'a,
955-
V: 'a,
956-
{
952+
pub struct Drain<'a, K, V> {
957953
pub(crate) iter: vec::Drain<'a, Bucket<K, V>>,
958954
}
959955

src/map/core.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ where
6262
K: fmt::Debug,
6363
V: fmt::Debug,
6464
{
65-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6666
f.debug_struct("IndexMapCore")
6767
.field("indices", &raw::DebugIndices(&self.indices))
6868
.field("entries", &self.entries)
@@ -129,7 +129,7 @@ impl<K, V> IndexMapCore<K, V> {
129129
self.entries.clear();
130130
}
131131

132-
pub(crate) fn drain(&mut self, range: RangeFull) -> Drain<Bucket<K, V>> {
132+
pub(crate) fn drain(&mut self, range: RangeFull) -> Drain<'_, Bucket<K, V>> {
133133
self.indices.clear();
134134
self.entries.drain(range)
135135
}
@@ -225,7 +225,7 @@ impl<K, V> IndexMapCore<K, V> {
225225

226226
/// Entry for an existing key-value pair or a vacant location to
227227
/// insert one.
228-
pub enum Entry<'a, K: 'a, V: 'a> {
228+
pub enum Entry<'a, K, V> {
229229
/// Existing slot with equivalent key.
230230
Occupied(OccupiedEntry<'a, K, V>),
231231
/// Vacant slot (no equivalent key in the map).
@@ -297,7 +297,7 @@ impl<'a, K, V> Entry<'a, K, V> {
297297
}
298298

299299
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Entry<'a, K, V> {
300-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
300+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
301301
match *self {
302302
Entry::Vacant(ref v) => f.debug_tuple(stringify!(Entry)).field(v).finish(),
303303
Entry::Occupied(ref o) => f.debug_tuple(stringify!(Entry)).field(o).finish(),
@@ -352,7 +352,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
352352
}
353353

354354
impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for OccupiedEntry<'a, K, V> {
355-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
355+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
356356
f.debug_struct(stringify!(OccupiedEntry))
357357
.field("key", self.key())
358358
.field("value", self.get())
@@ -364,7 +364,7 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for OccupiedEntry<'a
364364
/// It is part of the [`Entry`] enum.
365365
///
366366
/// [`Entry`]: enum.Entry.html
367-
pub struct VacantEntry<'a, K: 'a, V: 'a> {
367+
pub struct VacantEntry<'a, K, V> {
368368
map: &'a mut IndexMapCore<K, V>,
369369
hash: HashValue,
370370
key: K,
@@ -391,7 +391,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> {
391391
}
392392

393393
impl<'a, K: 'a + fmt::Debug, V: 'a> fmt::Debug for VacantEntry<'a, K, V> {
394-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
394+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
395395
f.debug_tuple(stringify!(VacantEntry))
396396
.field(self.key())
397397
.finish()
@@ -402,5 +402,5 @@ impl<'a, K: 'a + fmt::Debug, V: 'a> fmt::Debug for VacantEntry<'a, K, V> {
402402
fn assert_send_sync() {
403403
fn assert_send_sync<T: Send + Sync>() {}
404404
assert_send_sync::<IndexMapCore<i32, i32>>();
405-
assert_send_sync::<Entry<i32, i32>>();
405+
assert_send_sync::<Entry<'_, i32, i32>>();
406406
}

src/map/core/raw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type RawBucket = hashbrown::raw::Bucket<usize>;
1111

1212
pub(super) struct DebugIndices<'a>(pub &'a RawTable<usize>);
1313
impl fmt::Debug for DebugIndices<'_> {
14-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1515
let indices = unsafe { self.0.iter().map(|raw_bucket| raw_bucket.read()) };
1616
f.debug_list().entries(indices).finish()
1717
}
@@ -49,7 +49,7 @@ impl<K, V> IndexMapCore<K, V> {
4949
unsafe { self.indices.erase(raw_bucket) };
5050
}
5151

52-
pub(crate) fn entry(&mut self, hash: HashValue, key: K) -> Entry<K, V>
52+
pub(crate) fn entry(&mut self, hash: HashValue, key: K) -> Entry<'_, K, V>
5353
where
5454
K: Eq,
5555
{
@@ -193,7 +193,7 @@ impl<K, V> IndexMapCore<K, V> {
193193
/// [`Entry`]: enum.Entry.html
194194
// SAFETY: The lifetime of the map reference also constrains the raw bucket,
195195
// which is essentially a raw pointer into the map indices.
196-
pub struct OccupiedEntry<'a, K: 'a, V: 'a> {
196+
pub struct OccupiedEntry<'a, K, V> {
197197
map: &'a mut IndexMapCore<K, V>,
198198
raw_bucket: RawBucket,
199199
key: K,

0 commit comments

Comments
 (0)