Skip to content

Commit e6a4fb0

Browse files
committed
Merge branch origin/master into dtolnay/ptr
Conflicts: src/lib.rs
2 parents 426fe21 + 08590c8 commit e6a4fb0

File tree

4 files changed

+55
-49
lines changed

4 files changed

+55
-49
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
- rust: beta
66
env: FEATURES="serde_impl"
77
- rust: nightly
8-
env: FEATURES="serde_impl nightly"
8+
env: FEATURES="serde_impl nightly clippy"
99
script:
1010
- cargo build --features "$FEATURES"
1111
- cargo test --features "$FEATURES"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ nightly = []
2020
serde_impl = ["serde", "serde_json"]
2121

2222
[dependencies]
23+
clippy = { version = "0.*", optional = true }
2324
serde = { version = "^0.7", optional = true }
2425
serde_json = { version = "^0.7", optional = true }

deploy-docs.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ git init
1010
git config user.email '[email protected]'
1111
git config user.name 'FlashCat'
1212
git remote add upstream "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git"
13-
git fetch upstream gh-pages
14-
git reset upstream/gh-pages
1513

1614
touch .
1715

1816
git add -A .
19-
git commit -m "rebuild pages at ${rev}"
20-
git push -q upstream HEAD:gh-pages
17+
git commit -qm "rebuild pages at ${rev}"
18+
git push -q upstream HEAD:gh-pages --force

src/lib.rs

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! A HashMap wrapper that holds key-value pairs in insertion order.
11+
//! A `HashMap` wrapper that holds key-value pairs in insertion order.
1212
//!
1313
//! # Examples
1414
//!
@@ -28,12 +28,15 @@
2828
//! ```
2929
3030
#![forbid(missing_docs)]
31-
#![cfg_attr(feature = "nightly", feature(hashmap_public_hasher))]
3231
#![cfg_attr(all(feature = "nightly", test), feature(test))]
3332

33+
#![cfg_attr(feature = "clippy", feature(plugin))]
34+
#![cfg_attr(feature = "clippy", plugin(clippy))]
35+
#![cfg_attr(feature = "clippy", deny(clippy))]
36+
3437
// Optional Serde support
3538
#[cfg(feature = "serde_impl")]
36-
mod serde;
39+
pub mod serde;
3740

3841
use std::borrow::Borrow;
3942
use std::cmp::Ordering;
@@ -310,7 +313,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
310313
self.detach(node_ptr);
311314
self.attach(node_ptr);
312315
}
313-
return value;
316+
value
314317
}
315318

316319
/// Removes and returns the value corresponding to the key from the map.
@@ -373,17 +376,17 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
373376
/// ```
374377
#[inline]
375378
pub fn pop_front(&mut self) -> Option<(K, V)> {
376-
if self.len() > 0 {
377-
let lru = unsafe { (*self.head).prev };
378-
self.detach(lru);
379-
return self.map
380-
.remove(&KeyRef{k: unsafe { &(*lru).key }})
381-
.map(|e| {
382-
let e = *unsafe { Box::from_raw(e) };
383-
(e.key, e.value)
384-
})
379+
if self.is_empty() {
380+
return None
385381
}
386-
None
382+
let lru = unsafe { (*self.head).prev };
383+
self.detach(lru);
384+
self.map
385+
.remove(&KeyRef{k: unsafe { &(*lru).key }})
386+
.map(|e| {
387+
let e = *unsafe { Box::from_raw(e) };
388+
(e.key, e.value)
389+
})
387390
}
388391

389392
/// Gets the first entry.
@@ -399,12 +402,13 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
399402
/// ```
400403
#[inline]
401404
pub fn front(&self) -> Option<(&K, &V)> {
402-
if self.len() > 0 {
403-
let lru = unsafe { (*self.head).prev };
404-
return self.map.get(&KeyRef{k: unsafe { &(*lru).key }})
405-
.map(|e| unsafe { (&(**e).key, &(**e).value) })
405+
if self.is_empty() {
406+
return None
406407
}
407-
None
408+
let lru = unsafe { (*self.head).prev };
409+
self.map
410+
.get(&KeyRef{k: unsafe { &(*lru).key }})
411+
.map(|e| unsafe { (&(**e).key, &(**e).value) })
408412
}
409413

410414
/// Removes the last entry.
@@ -422,17 +426,17 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
422426
/// ```
423427
#[inline]
424428
pub fn pop_back(&mut self) -> Option<(K, V)> {
425-
if self.len() > 0 {
426-
let mru = unsafe { (*self.head).next };
427-
self.detach(mru);
428-
return self.map
429-
.remove(&KeyRef{k: unsafe { &(*mru).key }})
430-
.map(|e| {
431-
let e = *unsafe { Box::from_raw(e) };
432-
(e.key, e.value)
433-
})
429+
if self.is_empty() {
430+
return None
434431
}
435-
None
432+
let mru = unsafe { (*self.head).next };
433+
self.detach(mru);
434+
self.map
435+
.remove(&KeyRef{k: unsafe { &(*mru).key }})
436+
.map(|e| {
437+
let e = *unsafe { Box::from_raw(e) };
438+
(e.key, e.value)
439+
})
436440
}
437441

438442
/// Gets the last entry.
@@ -448,12 +452,13 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
448452
/// ```
449453
#[inline]
450454
pub fn back(&mut self) -> Option<(&K, &V)> {
451-
if self.len() > 0 {
452-
let mru = unsafe { (*self.head).next };
453-
return self.map.get(&KeyRef{k: unsafe { &(*mru).key }})
454-
.map(|e| unsafe { (&(**e).key, &(**e).value) })
455+
if self.is_empty() {
456+
return None
455457
}
456-
None
458+
let mru = unsafe { (*self.head).next };
459+
self.map
460+
.get(&KeyRef{k: unsafe { &(*mru).key }})
461+
.map(|e| unsafe { (&(**e).key, &(**e).value) })
457462
}
458463

459464
/// Returns the number of key-value pairs in the map.
@@ -494,10 +499,10 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
494499
/// assert_eq!(None, iter.next());
495500
/// ```
496501
pub fn iter(&self) -> Iter<K, V> {
497-
let head = if ! self.head.is_null() {
498-
unsafe { (*self.head).prev }
499-
} else {
502+
let head = if self.head.is_null() {
500503
ptr::null_mut()
504+
} else {
505+
unsafe { (*self.head).prev }
501506
};
502507
Iter {
503508
head: head,
@@ -528,10 +533,10 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
528533
/// assert_eq!(&17, map.get(&"a").unwrap());
529534
/// ```
530535
pub fn iter_mut(&mut self) -> IterMut<K, V> {
531-
let head = if ! self.head.is_null() {
532-
unsafe { (*self.head).prev }
533-
} else {
536+
let head = if self.head.is_null() {
534537
ptr::null_mut()
538+
} else {
539+
unsafe { (*self.head).prev }
535540
};
536541
IterMut {
537542
head: head,
@@ -558,6 +563,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
558563
/// assert_eq!(&'b', keys.next().unwrap());
559564
/// assert_eq!(None, keys.next());
560565
/// ```
566+
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))] // false positive
561567
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
562568
fn first<A, B>((a, _): (A, B)) -> A { a }
563569
let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn ptr
@@ -582,6 +588,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
582588
/// assert_eq!(&20, values.next().unwrap());
583589
/// assert_eq!(None, values.next());
584590
/// ```
591+
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))] // false positive
585592
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
586593
fn second<A, B>((_, b): (A, B)) -> B { b }
587594
let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn ptr
@@ -822,8 +829,7 @@ impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V> {
822829
self.remaining -= 1;
823830
unsafe {
824831
self.tail = (*self.tail).next;
825-
let r = Some((&(*self.tail).key, &(*self.tail).value));
826-
r
832+
Some((&(*self.tail).key, &(*self.tail).value))
827833
}
828834
}
829835
}
@@ -837,8 +843,7 @@ impl<'a, K, V> DoubleEndedIterator for IterMut<'a, K, V> {
837843
self.remaining -= 1;
838844
unsafe {
839845
self.tail = (*self.tail).next;
840-
let r = Some((&(*self.tail).key, &mut (*self.tail).value));
841-
r
846+
Some((&(*self.tail).key, &mut (*self.tail).value))
842847
}
843848
}
844849
}
@@ -854,6 +859,7 @@ impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
854859

855860
/// An insertion-order iterator over a `LinkedHashMap`'s keys.
856861
pub struct Keys<'a, K: 'a, V: 'a> {
862+
#[cfg_attr(feature = "clippy", allow(type_complexity))]
857863
inner: iter::Map<Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
858864
}
859865

@@ -878,6 +884,7 @@ impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
878884

879885
/// An insertion-order iterator over a `LinkedHashMap`'s values.
880886
pub struct Values<'a, K: 'a, V: 'a> {
887+
#[cfg_attr(feature = "clippy", allow(type_complexity))]
881888
inner: iter::Map<Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
882889
}
883890

0 commit comments

Comments
 (0)