From: Ian Jackson Date: Mon, 3 Aug 2020 01:10:32 +0000 (+0100) Subject: clippy X-Git-Tag: otter-0.2.0~1188 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c2cd996150e0608b97fabe637cccb953d3223f9e;p=otter.git clippy --- diff --git a/src/api.rs b/src/api.rs index 8fa52109..3edf31d5 100644 --- a/src/api.rs +++ b/src/api.rs @@ -81,16 +81,16 @@ fn api_piece_op(form : Json>) eprintln!("Q_GEN={:?} U_GEN={:?}", u_gen, q_gen); - if u_gen > q_gen { Err(GameError::Conflict)? } + if u_gen > q_gen { throw!(GameError::Conflict) } if pc.held != None && pc.held != Some(player) { - Err(GameError::PieceHeld)? + throw!(GameError::PieceHeld) }; let (update, logents) = form.op.op(gs,player,piece,&lens)?; Ok((update, logents)) })() { Err(err) => { let err : GameError = err; - if let GameError::InternalErrorSVG(svg) = err { Err(svg)? } + if let GameError::InternalErrorSVG(svg) = err { throw!(svg) } eprintln!("API {:?} => {:?}", &form, &err); }, Ok((update, logents)) => { @@ -123,7 +123,7 @@ impl ApiPieceOp for ApiPieceGrab { let pl = gs.players.byid(player).unwrap(); let pc = gs.pieces.byid_mut(piece).unwrap(); - if pc.held.is_some() { Err(GameError::PieceHeld)? } + if pc.held.is_some() { throw!(GameError::PieceHeld) } pc.held = Some(player); let update = PieceUpdateOp::Modify(()); @@ -155,7 +155,7 @@ impl ApiPieceOp for ApiPieceUngrab { let pl = gs.players.byid(player).unwrap(); let pc = gs.pieces.byid_mut(piece).unwrap(); - if pc.held != Some(player) { Err(GameError::PieceHeld)? } + if pc.held != Some(player) { throw!(GameError::PieceHeld) } pc.held = None; let update = PieceUpdateOp::Modify(()); diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 6022473f..97cca97a 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -100,9 +100,9 @@ impl CommandStream<'_> { { return Authorised::authorise(); } - Err(anyhow!("{}: euid mismatch: client={:?} server={:?} wanted={:?}{}", - &self.desc, client_euid, server_euid, wanted, - xinfo.unwrap_or("")))? + throw!(anyhow!("{}: euid mismatch: client={:?} server={:?} wanted={:?}{}", + &self.desc, client_euid, server_euid, wanted, + xinfo.unwrap_or(""))); } fn map_auth_err(&self, ae: AuthorisationError) -> MgmtError { diff --git a/src/error.rs b/src/error.rs index 327a2798..8d77df34 100644 --- a/src/error.rs +++ b/src/error.rs @@ -87,6 +87,7 @@ pub trait ById { pub trait IdForById { type Error; + #[allow(clippy::declare_interior_mutable_const)] // todo: report this const ERROR : Self::Error; } diff --git a/src/gamestate.rs b/src/gamestate.rs index cb8c8a04..8868962f 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -120,7 +120,7 @@ impl TryFrom for ZCoord { type Error = OnlineError; #[throws(OnlineError)] fn try_from(v: f64) -> ZCoord { - if !v.is_finite() { Err(OnlineError::InvalidZCoord)? } + if !v.is_finite() { throw!(OnlineError::InvalidZCoord) } ZCoord(v) } } @@ -147,7 +147,7 @@ impl PieceState { let pr = self; let mut defs = String::new(); let dragraise = match pr.p.thresh_dragraise(pri)? { - Some(n) if n < 0 => Err(SE::NegativeDragraise)?, + Some(n) if n < 0 => throw!(SE::NegativeDragraise), Some(n) => n, None => -1, }; diff --git a/src/global.rs b/src/global.rs index 9b41422c..f29f3420 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1,3 +1,4 @@ +#![allow(clippy::let_and_return)] use crate::imports::*; use lazy_static::lazy_static; @@ -196,7 +197,7 @@ impl Borrow for RawToken { impl InstanceRef { #[throws(InstanceLockError)] - pub fn lock<'g>(&'g self) -> InstanceGuard<'g> { + pub fn lock(&self) -> InstanceGuard<'_> { let c = self.0.lock()?; if !c.live { throw!(InstanceLockError::GameBeingDestroyed) } InstanceGuard { c, gref: self.clone() } @@ -205,6 +206,7 @@ impl InstanceRef { impl Instance { /// Returns `None` if a game with this name already exists + #[allow(clippy::new_ret_no_self)] #[throws(MgmtError)] pub fn new(name: InstanceName, gs: GameState) -> InstanceRef { let name = Arc::new(name); @@ -286,7 +288,7 @@ impl Instance { let out : Vec> = games.keys() .filter(|k| scope == None || scope == Some(&k.scope)) - .map(|k| k.clone()) + .cloned() .collect(); out } @@ -478,6 +480,7 @@ impl InstanceGuard<'_> { } wanted }; + #[allow(clippy::or_fun_call)] let out = players.iter().map(|&player| { let mut tokens = wanted.remove(player) .unwrap_or(vec![] /* dupe, somehow */); diff --git a/src/pieces.rs b/src/pieces.rs index de532ef3..1013e2b8 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -56,7 +56,7 @@ pub fn svg_rescale_path(input: &str, scale: f64) -> String { let mut first = iter::once(()); for w in input.split_ascii_whitespace() { - if !first.next().is_some() { write!(&mut out, " ")?; } + if first.next().is_none() { write!(&mut out, " ")?; } match w { "L" | "l" | "M" | "m" | "V" | "v" | "H" | "h" => map = ALWAYS_MAP, @@ -69,7 +69,7 @@ pub fn svg_rescale_path(input: &str, scale: f64) -> String { continue; } } - _ => Err(SE::UnknownOperator)?, + _ => throw!(SE::UnknownOperator), }; write!(&mut out, "{}", w)?; } @@ -180,9 +180,9 @@ impl PieceSpec for Disc { impl PieceSpec for Square { #[throws(SE)] fn load(&self) -> Box { - let (x, y) = match self.size.as_slice() { - &[s,] => (s,s), - &[x, y] => (x,y), + let (x, y) = match *self.size.as_slice() { + [s,] => (s,s), + [x, y] => (x,y), _ => throw!(SE::ImproperSizeSpec), }; let path = format!("M {} {} h {} v {} h {} z", @@ -196,6 +196,7 @@ impl PieceSpec for Square { } } +#[allow(clippy::type_complexity)] pub fn xxx_make_pieces() -> Result)>,SE> { Ok(vec![ ([ 90, 80 ], diff --git a/src/sse.rs b/src/sse.rs index 477b08b9..ce57ecac 100644 --- a/src/sse.rs +++ b/src/sse.rs @@ -1,3 +1,5 @@ +#![allow(clippy::while_let_loop)] +#![allow(clippy::blocks_in_if_conditions)] use crate::imports::*; @@ -36,6 +38,7 @@ impl Read for UpdateReader { let mut ig = self.gref.lock().map_err(|_| em("poison"))?; let orig_wanted = orig_buf.len(); + #[allow(clippy::useless_asref)] // todo: report this let mut buf = orig_buf.as_mut(); if self.init_confirmation_send.next().is_some() { @@ -122,7 +125,7 @@ impl StableIndexOffset for UpdateId { self.0.index_input(input.0) } fn index_output(&self, inner: usize) -> Option { - self.0.index_output(inner).map(|v| UpdateId(v)) + self.0.index_output(inner).map(UpdateId) } fn zero() -> Self { UpdateId(0) } } diff --git a/src/updates.rs b/src/updates.rs index 7cdff5c9..dd43cf34 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -188,7 +188,7 @@ impl<'r> PrepareUpdatesBuffer<'r> { let by_client = by_client.unwrap_or( (Default::default(), ClientSequence(0)) ); - let us = estimate.map(|e| Vec::with_capacity(e)).unwrap_or(vec![]); + let us = estimate.map_or(vec![], Vec::with_capacity); g.gs.gen.increment();