chiark / gitweb /
clippy: Miscellaneous minor changes, and allow lints
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 19:56:12 +0000 (20:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 19:56:12 +0000 (20:56 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/atmain.rs
clippy-options
daemon/cmdlistener.rs
wdriver/wdriver.rs
wdriver/wdt-altergame.rs

index ad9cbb18602d0b67c1df4031432c92f113927c88..085547f51cec1a507621f0177d39ed212b752b69 100644 (file)
@@ -142,7 +142,7 @@ fn updates_parser<R:Read>(input: R, out: &mut mpsc::Sender<Update>) {
 
 impl UsualCtx {
   #[throws(Explode)]
-  fn connect_player<'su>(&self, player: &Player) -> Session {
+  fn connect_player(&self, player: &Player) -> Session {
     let client = reqwest::blocking::Client::new();
     let loading = client.get(&player.url).send_parse_html()?;
     let ptoken = loading.e_attr("#loading_token", "data-ptoken").unwrap();
index 34a9920c972c1ab7dde6328a9d90941e312a3bc1..086cd8a816ad22ef9b909b71b9e379ca9f52a027 100644 (file)
@@ -39,3 +39,4 @@
 -A clippy::iter_nth_zero
 -A clippy::match_single_binding
 -A clippy::needless_update
+-A clippy::comparison_chain
index 674bedffa4aa5fde9f5afa4a9679a858465761ab..63f1494e4eeed2d89b58fb58cd8ede06144d521f 100644 (file)
@@ -75,6 +75,7 @@ struct AccountSpecified {
   auth: Authorisation<AccountName>, // but we did check permissions
 }
 
+#[allow(clippy::enum_variant_names)]
 enum PermissionCheckHow {
   Instance,
   InstanceOrOnlyAffectedAccount(AccountId),
@@ -120,7 +121,7 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
   {
     (
       AccountsGuard::lock(),
-      Instance::lookup_by_name_unauth(&game)?,
+      Instance::lookup_by_name_unauth(game)?,
     )
   }
 
@@ -139,9 +140,9 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
   {
     let bundles = gref.lock_bundles();
     let mut igu = gref.lock()?;
-    let (mut ig, auth) = cs.check_acl(&ag, &mut igu, PCH::Instance, perms)?;
+    let (ig, auth) = cs.check_acl(ag, &mut igu, PCH::Instance, perms)?;
     let bundles = bundles.by(auth);
-    let r = f(&mut ig, bundles)?;
+    let r = f(ig, bundles)?;
     (r, auth)
   }
 
@@ -263,7 +264,7 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       let ag = AccountsGuard::lock();
       let names = if all == Some(true) {
         let auth = cs.superuser().ok_or(ME::AuthorisationError)?;
-        ag.list_accounts_all(auth.into())
+        ag.list_accounts_all(auth)
       } else {
         let AccountSpecified { notional_account, auth, .. } =
           cs.account.as_ref().ok_or(ME::SpecifyAccount)?;
@@ -316,8 +317,8 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
         let (ag, gref) = start_access_game(&game)?;
         access_bundles(
           cs,&ag,&gref, &[TP::UploadBundles],
-          &mut |mut ig, mut bundles: BundlesGuard<'_>| {
-            bundles.start_upload(&mut ig, kind)
+          &mut |ig, mut bundles: BundlesGuard<'_>| {
+            bundles.start_upload(ig, kind)
           }
         )?
       };
@@ -362,8 +363,8 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       let (ag, gref) = start_access_game(&game)?;
       access_bundles(
         cs,&ag,&gref, &[TP::ClearBundles],
-        &mut |mut ig, mut bundles: BundlesGuard<'_>| {
-          bundles.clear(&mut ig)
+        &mut |ig, mut bundles: BundlesGuard<'_>| {
+          bundles.clear(ig)
         })?;
       Fine
     }
@@ -405,9 +406,9 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
     }
 
     MC::DestroyGame { game } => {
-      let mut ag = AccountsGuard::lock();
+      let ag = AccountsGuard::lock();
       let mut games = games_lock();
-      let auth = authorise_by_account(cs, &mut ag, &game)?;
+      let auth = authorise_by_account(cs, &ag, &game)?;
       let gref = Instance::lookup_by_name_locked(&games, &game, auth)?;
       let ig = gref.lock_even_destroying();
       Instance::destroy_game(&mut games, ig, auth)?;
@@ -457,12 +458,12 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
     }
 
     MC::SshListKeys => {
-      let (ag, acctid, auth) = start_access_ssh_keys(&cs)?;
+      let (ag, acctid, auth) = start_access_ssh_keys(cs)?;
       let list = ag.sshkeys_report(acctid, auth)?;
       MR::SshKeys(list)
     }
     MC::SshAddKey { akl } => {
-      let (mut ag, acctid, auth) = start_access_ssh_keys(&cs)?;
+      let (mut ag, acctid, auth) = start_access_ssh_keys(cs)?;
       let (index, id) = ag.sshkeys_add(acctid, akl, auth)?;
       MR::SshKeyAdded { index, id }
     }
@@ -615,7 +616,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
                       -> Result<LogEntry, MgmtError> + '_>
   ) -> ExecuteGameInsnResults<'igr, 'ig>
   {
-    let ig = cs.check_acl(&ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
+    let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
 
     // Clear out old stuff
     let mut insns = vec![];
@@ -730,7 +731,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         html: hformat!("{} [{}] joined the game", nick, account),
       };
       let timezone = &arecord.timezone;
-      let tz = tz_from_str(&timezone);
+      let tz = tz_from_str(timezone);
       let gpl = GPlayer {
         nick: nick.to_string(),
         layout: arecord.layout,
@@ -756,7 +757,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
     },
 
     MGI::DeletePieceAlias(alias) => {
-      let ig = cs.check_acl(&ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
+      let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
       ig.pcaliases.remove(&alias);
       no_updates(ig, MGR::Fine)
     },
@@ -790,7 +791,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
     }
 
     MGI::Synch => {
-      let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Play])?;
+      let (ig, _) = cs.check_acl(ag, ig, PCH::Instance, &[TP::Play])?;
       let (_gen, mgr) = some_synch_core(ig)?;
       no_updates(ig, mgr)
     }
@@ -919,7 +920,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           new_links[k] = Some(url.into());
         }
         let new_links = Arc::new(new_links);
-        *ig_links = new_links.clone();
+        *ig_links = new_links;
         Ok(
           hformat!("{} set the links to off-server game resources",
                    who)
@@ -934,7 +935,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         let show: Html = (kind, url.as_str()).to_html();
         new_links[kind] = Some(url.into());
         let new_links = Arc::new(new_links);
-        *ig_links = new_links.clone();
+        *ig_links = new_links;
         Ok(
           hformat!("{} set the link {}",
                   who, show)
@@ -947,7 +948,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         let mut new_links: LinksTable = (**ig_links).clone();
         new_links[kind] = None;
         let new_links = Arc::new(new_links);
-        *ig_links = new_links.clone();
+        *ig_links = new_links;
         Ok(
           hformat!("{} removed the link {}",
                   who, &kind)
@@ -985,13 +986,13 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         hformat!("{} [{}] left the game [{}]"
                 ,
                 (|| Some(gpl?.nick))()
-                .unwrap_or("<partial data!>".into())
+                .unwrap_or_else(|| "<partial data!>".into())
                 ,
                 (||{
                   let (record, _) = ag.lookup(ipl?.acctid).ok()?;
                   Some(record.account.to_string())
                 })()
-                .unwrap_or("<account deleted>".into())
+                .unwrap_or_else(|| "<account deleted>".into())
                 ,
                 &account
                 )
@@ -1014,7 +1015,6 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       if let Some(gpc) = gpc {
         gpc.occult.passive_delete_hook(&mut gs.occults, piece);
         if gpc.occult.is_active() {
-          drop(gpc);
           xupdates.append(
             &mut
               remove_occultation(
@@ -1022,8 +1022,8 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
                 &mut gs.players,
                 &mut gs.pieces,
                 &mut gs.occults,
-                &mut ig.ipieces,
-                &mut ig.ioccults,
+                &ig.ipieces,
+                &ig.ioccults,
                 to_permute,
                 piece)?
           );
@@ -1142,7 +1142,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
     },
 
     MGI::ClearLog => {
-      let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
+      let (ig, _) = cs.check_acl(ag, ig, PCH::Instance, &[TP::Super])?;
       for gpl in ig.gs.players.values_mut() {
         gpl.movehist.clear();
       }
@@ -1167,7 +1167,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
     },
 
     MGI::SetACL { acl } => {
-      let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
+      let (ig, _) = cs.check_acl(ag, ig, PCH::Instance, &[TP::Super])?;
       ig.acl = acl.into();
       let mut log = vec![ LogEntry {
         html: hformat!("{} set the table access control list",
@@ -1359,8 +1359,8 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
   });
 
   if let Some(uu) = uu {
-    let mut ig = igu.by_mut(Authorisation::promise_any());
-    let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None);
+    let ig = igu.by_mut(Authorisation::promise_any());
+    let mut prepub = PrepareUpdatesBuffer::new(ig, None);
     uu(&mut prepub);
     prepub.finish();
   }
@@ -1773,7 +1773,7 @@ fn authorise_by_account(cs: &CommandStreamData, ag: &AccountsGuard,
     return y.so_promise();
   }
 
-  if &current.notional_account == &wanted.account {
+  if current.notional_account == wanted.account {
     current.auth.map(
       // Not executed, exists as a proof.
       // we need this Box::leak because map wants us to return a ref
@@ -1815,7 +1815,7 @@ fn do_authorise_scope(cs: &CommandStreamData, ag: &AccountsGuard,
         if let Ok::<_,AccountNotFound>
           ((record, _acctid)) = ag.lookup(&wanted_base_account);
         if let
-          Some(auth) = record.ssh_keys.check(ag, &key, auth);
+          Some(auth) = record.ssh_keys.check(ag, key, auth);
         then { return Ok(auth) }
         else { throw!(AuthorisationError("ssh key not authorised".into())); }
       }
index 1f8a3ffcb27ce08c8bd61ebd224641f75dbba9f7..15c5c0e8821551b0f0087a3a358beae60e6d73a9 100644 (file)
@@ -565,7 +565,7 @@ impl Setup {
       ))
         .context("execute script to create window")?;
 
-      let js_logfile = JsLogfileImp::open(&self.core.ds, &name)?;
+      let js_logfile = JsLogfileImp::open(&self.core.ds, name)?;
       let js_logfile = Rc::new(RefCell::new(js_logfile));
       self.windows_squirreled.push(js_logfile.clone());
 
index 13fbb7b7fdc28ddb1b141b35aa1e162e0a62d1c8..ea3b3609ee2a7476b88a106686133600abd1ffe8 100644 (file)
@@ -31,8 +31,8 @@ impl Ctx {
         .collect();
       assert_eq!(relevant.len(), url.iter().len());
       if let Some(url) = url {
-        assert_eq!(relevant[0].0.get_attribute("href")?
-                   .as_ref().map(|s| s.as_str()), Some(url));
+        assert_eq!(relevant[0].0.get_attribute("href")?.as_deref(),
+                   Some(url));
       }
       Ok::<_,AE>(())
     })()
@@ -79,7 +79,7 @@ fn tests(UsualSetup { su, alice, ..}: UsualSetup) {
   test!(c, "reset", {
     let game_spec = &c.su.ds.subst("@specs@/penultima.game.toml")?;
     let mut alice = c.su.w(&c.alice)?;
-    alice.otter(&["reset"],&[&game_spec])?;
+    alice.otter(&["reset"],&[game_spec])?;
     alice.synch()?;
     let url = alice.current_url()?;
     alice.get(url)?;
@@ -90,7 +90,7 @@ fn tests(UsualSetup { su, alice, ..}: UsualSetup) {
     let pauseable = c.su.otter_pauseable();
     let game_spec = &c.su.ds.subst("@specs@/mao.game.toml")?;
     let mut alice = c.su.w(&c.alice)?;
-    alice.otter(&["reset"],&[&game_spec])?;
+    alice.otter(&["reset"],&[game_spec])?;
     alice.synch()?;
 
     let p1 = Pos::new(150,84);