Fix a bunch more Clippy lints, but disable in Circle

The unused error is causing more trouble than it's worth at this
point
This commit is contained in:
Griffin Smith 2019-08-03 13:14:28 -04:00
parent 929dac06d0
commit 82cefedab9
18 changed files with 72 additions and 76 deletions

View file

@ -20,16 +20,16 @@ jobs:
- checkout
- rust/update_toolchain
- rust/format
lint:
executor: rust/default
steps:
- checkout
- rust/update_toolchain
- rust/clippy
# lint:
# executor: rust/default
# steps:
# - checkout
# - rust/update_toolchain
# - rust/clippy
workflows:
default:
jobs:
- lint
# - lint
- format
- build
- test:

View file

@ -69,12 +69,12 @@ mod tests {
#[test]
fn test_describe_list() {
assert_eq!(
describe_list(&vec![Description("one".to_string())]),
describe_list(&[Description("one".to_string())]),
"one".to_string()
);
assert_eq!(
describe_list(&vec![
describe_list(&[
Description("one".to_string()),
Description("two".to_string())
]),
@ -82,7 +82,7 @@ mod tests {
);
assert_eq!(
describe_list(&vec![
describe_list(&[
Description("one".to_string()),
Description("two".to_string()),
Description("three".to_string())

View file

@ -16,21 +16,21 @@ impl Color {
}
impl color::Color for Color {
fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn write_fg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.write_fg(f)
}
fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn write_bg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.write_bg(f)
}
}
impl<'a> color::Color for &'a Color {
fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn write_fg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.write_fg(f)
}
fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn write_bg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.write_bg(f)
}
}
@ -56,7 +56,7 @@ impl ColorVisitor {
impl<'de> Visitor<'de> for ColorVisitor {
type Value = Color;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("A color")
}

View file

@ -140,7 +140,7 @@ impl Stylable for Line {
}
impl Stylable for Neighbors<Option<BoxStyle>> {
fn style(&self, style: BoxStyle) -> char {
fn style(&self, _style: BoxStyle) -> char {
use BoxStyle::*;
match (self.left, self.right, self.top, self.bottom) {
(None, None, None, None) => BOX,

View file

@ -17,17 +17,17 @@ pub fn clear<T: Write>(out: &mut T) -> io::Result<()> {
pub trait Draw: Positioned {
/// Draw this entity, assuming the character is already at the correct
/// position
fn do_draw(&self, out: &mut Write) -> io::Result<()>;
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()>;
}
impl<T: Draw> Draw for &T {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
(**self).do_draw(out)
}
}
impl<T: Draw> Draw for Box<T> {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
(**self).do_draw(out)
}
}
@ -36,7 +36,7 @@ pub trait DrawWithNeighbors: Positioned {
#[allow(clippy::borrowed_box)]
fn do_draw_with_neighbors<'a, 'b>(
&'a self,
out: &'b mut Write,
out: &'b mut dyn Write,
neighbors: &'a Neighbors<Vec<&'a Box<dyn Entity>>>,
) -> io::Result<()>;
}
@ -44,7 +44,7 @@ pub trait DrawWithNeighbors: Positioned {
impl<T: Draw> DrawWithNeighbors for T {
fn do_draw_with_neighbors<'a, 'b>(
&'a self,
out: &'b mut Write,
out: &'b mut dyn Write,
_neighbors: &'a Neighbors<Vec<&'a Box<dyn Entity>>>,
) -> io::Result<()> {
self.do_draw(out)

View file

@ -68,7 +68,7 @@ impl<W> Viewport<W> {
}
impl<W> Debug for Viewport<W> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Viewport {{ outer: {:?}, inner: {:?}, out: <OUT> }}",

View file

@ -42,7 +42,7 @@ impl Character {
}
impl display::Draw for Character {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
write!(out, "@")
}
}

View file

@ -57,7 +57,7 @@ impl Describe for Creature {
}
impl display::Draw for Creature {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
write!(out, "{}", self.typ.chr)
}
}

View file

@ -103,7 +103,7 @@ impl_downcast!(Entity);
impl DrawWithNeighbors for Box<dyn Entity> {
fn do_draw_with_neighbors<'a, 'b>(
&'a self,
out: &'b mut Write,
out: &'b mut dyn Write,
neighbors: &'a Neighbors<Vec<&'a Box<dyn Entity>>>,
) -> io::Result<()> {
(**self).do_draw_with_neighbors(out, neighbors)

View file

@ -12,7 +12,7 @@ pub struct EntityChar {
}
impl Display for EntityChar {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"{}{}{}",

View file

@ -21,7 +21,7 @@ impl Wall {
impl display::DrawWithNeighbors for Wall {
fn do_draw_with_neighbors<'a, 'b>(
&'a self,
out: &'b mut Write,
out: &'b mut dyn Write,
neighbors: &'a Neighbors<Vec<&'a Box<dyn Entity>>>,
) -> io::Result<()> {
let neighbor_styles: Neighbors<Option<BoxStyle>> =

View file

@ -44,7 +44,7 @@ impl Describe for Item {
}
impl display::Draw for Item {
fn do_draw(&self, out: &mut Write) -> io::Result<()> {
fn do_draw(&self, out: &mut dyn Write) -> io::Result<()> {
write!(out, "{}", self.typ.chr)
}
}

View file

@ -69,7 +69,7 @@ impl PromptResolution {
use PromptResolution::*;
match self {
Cancellable(complete) => complete.cancel(),
Uncancellable(complete) => {}
Uncancellable(_complete) => {}
}
}
}
@ -200,12 +200,10 @@ impl<'a> Game<'a> {
fn collision_at(&self, pos: Position) -> Option<Collision> {
if !pos.within(self.viewport.inner) {
Some(Collision::Stop)
} else if self.creatures_at(pos).is_empty() {
None
} else {
if self.creatures_at(pos).is_empty() {
None
} else {
Some(Collision::Combat)
}
Some(Collision::Combat)
}
}
@ -305,7 +303,7 @@ impl<'a> Game<'a> {
}
/// Step the game forward the given number of ticks
fn tick(&mut self, ticks: Ticks) {}
fn tick(&mut self, _ticks: Ticks) {}
/// Get a message from the global map based on the rng in this game
fn message<'params>(

View file

@ -1,13 +1,7 @@
extern crate termion;
#[macro_use]
extern crate log;
extern crate config;
extern crate log4rs;
extern crate serde;
extern crate toml;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate clap;
#[macro_use]
@ -19,14 +13,13 @@ extern crate lazy_static;
extern crate maplit;
#[macro_use]
extern crate downcast_rs;
extern crate backtrace;
#[macro_use]
extern crate include_dir;
#[macro_use]
extern crate nom;
#[cfg(test)]
#[macro_use]
extern crate matches;
extern crate futures;
#[macro_use]
mod util;
@ -53,6 +46,7 @@ use backtrace::Backtrace;
use std::io::{self, StdinLock, StdoutLock};
use std::panic;
use termion;
use termion::raw::IntoRawMode;
use termion::raw::RawTerminal;

View file

@ -10,7 +10,7 @@ use alga::general::{
use std::collections::{hash_map, BTreeMap, HashMap};
use std::iter::FromIterator;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct EntityMap<A> {
by_position: BTreeMap<Position, Vec<EntityID>>,
by_id: HashMap<EntityID, A>,
@ -24,7 +24,7 @@ impl<A: PartialEq> PartialEq for EntityMap<A> {
}
impl<A: Eq> Eq for EntityMap<A> {}
const BY_POS_INVARIANT: &'static str =
const BY_POS_INVARIANT: &str =
"Invariant: All references in EntityMap.by_position should point to existent references in by_id";
impl<A> EntityMap<A> {
@ -54,26 +54,26 @@ impl<A> EntityMap<A> {
/// Remove all entities at the given position
pub fn remove_all_at(&mut self, pos: Position) {
self.by_position.remove(&pos).map(|eids| {
if let Some(eids) = self.by_position.remove(&pos) {
for eid in eids {
self.by_id.remove(&eid).expect(BY_POS_INVARIANT);
}
});
}
}
pub fn get<'a>(&'a self, id: EntityID) -> Option<&'a A> {
pub fn get(&self, id: EntityID) -> Option<&A> {
self.by_id.get(&id)
}
pub fn get_mut<'a>(&'a mut self, id: EntityID) -> Option<&'a mut A> {
pub fn get_mut(&mut self, id: EntityID) -> Option<&mut A> {
self.by_id.get_mut(&id)
}
pub fn entities<'a>(&'a self) -> impl Iterator<Item = &'a A> {
pub fn entities(&self) -> impl Iterator<Item = &A> {
self.by_id.values()
}
pub fn entities_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut A> {
pub fn entities_mut(&mut self) -> impl Iterator<Item = &mut A> {
self.by_id.values_mut()
}
@ -81,8 +81,8 @@ impl<A> EntityMap<A> {
self.by_id.keys()
}
pub fn drain<'a>(&'a mut self) -> Drain<'a, A> {
let ids = self.ids().map(|e| *e).collect::<Vec<_>>();
pub fn drain(&mut self) -> Drain<'_, A> {
let ids = self.ids().copied().collect::<Vec<_>>();
Drain {
map: self,
ids_iter: Box::new(ids.into_iter()),
@ -103,7 +103,7 @@ impl<A: Positioned + Identified<EntityID>> EntityMap<A> {
self.by_id.entry(entity_id).or_insert(entity);
self.by_position
.entry(pos)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(entity_id);
entity_id
}
@ -113,12 +113,14 @@ impl<A: Positioned + Identified<EntityID>> EntityMap<A> {
self.by_id.remove(&id).map(|e| {
let mut empty = false;
let position = e.position();
self.by_position.get_mut(&position).map(|es| {
if let Some(es) = self.by_position.get_mut(&position) {
es.retain(|e| *e != id);
if es.len() == 0 {
if es.is_empty() {
empty = true;
}
});
}
if empty {
self.by_position.remove(&position);
}
@ -172,7 +174,7 @@ impl<'a, A: Positioned + Identified<EntityID>> IntoIterator
type Item = (&'a EntityID, &'a A);
type IntoIter = std::collections::hash_map::Iter<'a, EntityID, A>;
fn into_iter(self) -> Self::IntoIter {
(&self.by_id).into_iter()
(&self.by_id).iter()
}
}
@ -246,20 +248,21 @@ impl<A: PositionedMut> EntityMap<A> {
old_pos = Some(entity.position());
entity.set_position(new_position);
}
old_pos.map(|p| {
self.by_position
.get_mut(&p)
.map(|es| es.retain(|e| *e != entity_id));
if let Some(p) = old_pos {
if let Some(es) = self.by_position.get_mut(&p) {
es.retain(|e| *e != entity_id);
}
self.by_position
.entry(new_position)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(entity_id);
});
}
}
}
pub struct Drain<'a, A: 'a> {
pub struct Drain<'a, A> {
map: &'a mut EntityMap<A>,
ids_iter: Box<dyn Iterator<Item = EntityID> + 'a>,
}
@ -313,9 +316,7 @@ mod tests {
fn gen_entity_map() -> BoxedStrategy<EntityMap<TestEntity>> {
any::<Vec<TestEntity>>()
.prop_map(|ents| {
ents.iter()
.map(|e| e.clone())
.collect::<EntityMap<TestEntity>>()
ents.iter().cloned().collect::<EntityMap<TestEntity>>()
})
.boxed()
}

View file

@ -427,6 +427,7 @@ impl<A> Neighbors<Vec<A>> {
#[cfg(test)]
mod tests {
#![allow(clippy::unnecessary_operation)]
use super::*;
use proptest::prelude::*;

View file

@ -3,9 +3,11 @@ use std::pin::Pin;
use std::sync::{Arc, RwLock};
use std::task::{Context, Poll, Waker};
type Waiter<Env, T> = Box<dyn Fn(&mut Env, &T)>;
pub struct Promise<Env, T> {
inner: Arc<RwLock<Inner<T>>>,
waiters: Arc<RwLock<Vec<Box<dyn Fn(&mut Env, &T)>>>>,
waiters: Arc<RwLock<Vec<Waiter<Env, T>>>>,
}
pub struct Complete<T> {
@ -29,7 +31,7 @@ pub fn promise<Env, T>() -> (Complete<T>, Promise<Env, T>) {
inner: inner.clone(),
waiters: Arc::new(RwLock::new(Vec::new())),
};
let complete = Complete { inner: inner };
let complete = Complete { inner };
(complete, promise)
}
@ -127,7 +129,7 @@ impl<Env, P: Give<Env>> Give<Env> for &P {
impl<Env, T> Future for Promise<Env, T> {
type Output = Arc<T>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut inner = self.inner.write().unwrap();
match inner.value {
Some(ref v) => Poll::Ready(v.clone()),

View file

@ -18,7 +18,7 @@ impl<'a> Path<'a> {
}
impl<'a> Display for Path<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.head)?;
for part in &self.tail {
write!(f, ".{}", part)?;
@ -96,7 +96,7 @@ impl<'a> TemplateVisitor<'a> {
impl<'a> serde::de::Visitor<'a> for TemplateVisitor<'a> {
type Value = Template<'a>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a valid template string")
}
@ -126,7 +126,7 @@ impl<'a> Template<'a> {
input: &'a str,
) -> Result<Template<'a>, Err<(&'a str, ErrorKind)>> {
let (remaining, res) = template(input)?;
if remaining.len() > 0 {
if !remaining.is_empty() {
unreachable!();
}
Ok(res)
@ -157,7 +157,7 @@ pub enum TemplateError<'a> {
}
impl<'a> Display for TemplateError<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TemplateError::*;
match self {
MissingParam(path) => {
@ -179,7 +179,7 @@ impl<'a> TemplateParams<'a> {
match self {
Direct(_) => None,
Nested(m) => m.get(path.head).and_then(|next| {
if path.tail.len() == 0 {
if path.tail.is_empty() {
match next {
Direct(s) => Some(*s),
_ => None,