chiark / gitweb /
clippy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 Aug 2020 01:10:32 +0000 (02:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 Aug 2020 01:10:32 +0000 (02:10 +0100)
src/api.rs
src/cmdlistener.rs
src/error.rs
src/gamestate.rs
src/global.rs
src/pieces.rs
src/sse.rs
src/updates.rs

index 8fa5210940a4b78d6f7f134f68cd84ecd7c9d42b..3edf31d5fdb26db5e09eade85918f321d120a31b 100644 (file)
@@ -81,16 +81,16 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
 
     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(());
index 6022473fffdb6beab3a3f8fe68e6fa6443359b64..97cca97aaf19afde9895b786ee47502fe62c8021 100644 (file)
@@ -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 {
index 327a279821802b27ac707adbcc35d571580fc488..8d77df34a599561efa1eb6570538bb493dd7091c 100644 (file)
@@ -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;
 }
 
index cb8c8a04d874a034b403032d4461ce67f8f1a61a..8868962f03f796ccc5ebc91d3f1109d6984aab2a 100644 (file)
@@ -120,7 +120,7 @@ impl TryFrom<f64> 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,
     };
index 9b41422c606db929a69a60ad17b6fc92a4da1ca1..f29f3420689d4e59f407bcd156fe7e307eb19d70 100644 (file)
@@ -1,3 +1,4 @@
+#![allow(clippy::let_and_return)]
 
 use crate::imports::*;
 use lazy_static::lazy_static;
@@ -196,7 +197,7 @@ impl Borrow<str> 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<Arc<InstanceName>> =
       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 */);
index de532ef39be9e5c7409b7c7cc31838d89527425c..1013e2b8e063f1ccd0634bec91113cd7fdc9f6cf 100644 (file)
@@ -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<dyn Piece> {
-    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<Vec<(Pos, Box<dyn Piece>)>,SE> {
   Ok(vec![
     ([ 90, 80 ],
index 477b08b9a5ef33bcd216ec3122364db643dc4516..ce57ecac9a4c5c37604f1a92894521600602541e 100644 (file)
@@ -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> {
-    self.0.index_output(inner).map(|v| UpdateId(v))
+    self.0.index_output(inner).map(UpdateId)
   }
   fn zero() -> Self { UpdateId(0) }
 }
index 7cdff5c9962e11bddb01e9272aeb490dfc25ead4..dd43cf34a7575c298ed8ad775d522c3a9d883843 100644 (file)
@@ -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();