Fix compilation errors with binding modifier "ref" after switch to 2024 edition.

Fix the following and alike errors after switch to 2024 edition:

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/fs.rs:552:27
    |
552 |             ByFingerprint(ref fp) => self.link_by_fingerprint(fp),
    |                           ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/fs.rs:552:13
    |
552 |             ByFingerprint(ref fp) => self.link_by_fingerprint(fp),
    |             ^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
552 -             ByFingerprint(ref fp) => self.link_by_fingerprint(fp),
552 +             ByFingerprint(fp) => self.link_by_fingerprint(fp),
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/fs.rs:553:21
    |
553 |             ByKeyID(ref keyid) => self.link_by_keyid(keyid),
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/fs.rs:553:13
    |
553 |             ByKeyID(ref keyid) => self.link_by_keyid(keyid),
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
553 -             ByKeyID(ref keyid) => self.link_by_keyid(keyid),
553 +             ByKeyID(keyid) => self.link_by_keyid(keyid),
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/fs.rs:554:21
    |
554 |             ByEmail(ref email) => self.link_by_email(email),
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/fs.rs:554:13
    |
554 |             ByEmail(ref email) => self.link_by_email(email),
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
554 -             ByEmail(ref email) => self.link_by_email(email),
554 +             ByEmail(email) => self.link_by_email(email),
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/sqlite.rs:278:27
    |
278 |             ByFingerprint(ref fp) => query_simple(
    |                           ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/sqlite.rs:278:13
    |
278 |             ByFingerprint(ref fp) => query_simple(
    |             ^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
278 -             ByFingerprint(ref fp) => query_simple(
278 +             ByFingerprint(fp) => query_simple(
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/sqlite.rs:283:21
    |
283 |             ByKeyID(ref keyid) => query_simple(
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/sqlite.rs:283:13
    |
283 |             ByKeyID(ref keyid) => query_simple(
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
283 -             ByKeyID(ref keyid) => query_simple(
283 +             ByKeyID(keyid) => query_simple(
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/sqlite.rs:288:21
    |
288 |             ByEmail(ref email) => query_simple(
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/sqlite.rs:288:13
    |
288 |             ByEmail(ref email) => query_simple(
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
288 -             ByEmail(ref email) => query_simple(
288 +             ByEmail(email) => query_simple(
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/lib.rs:194:27
    |
194 |             ByFingerprint(ref fp) => self.by_fpr(fp),
    |                           ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/lib.rs:194:13
    |
194 |             ByFingerprint(ref fp) => self.by_fpr(fp),
    |             ^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
194 -             ByFingerprint(ref fp) => self.by_fpr(fp),
194 +             ByFingerprint(fp) => self.by_fpr(fp),
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/lib.rs:195:21
    |
195 |             ByKeyID(ref keyid) => self.by_kid(keyid),
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/lib.rs:195:13
    |
195 |             ByKeyID(ref keyid) => self.by_kid(keyid),
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
195 -             ByKeyID(ref keyid) => self.by_kid(keyid),
195 +             ByKeyID(keyid) => self.by_kid(keyid),
    |

error: binding modifiers may only be written when the default binding mode is `move`
   --> database/src/lib.rs:196:21
    |
196 |             ByEmail(ref email) => self.by_email(email),
    |                     ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: matching on a reference type with a non-reference pattern changes the default binding mode
   --> database/src/lib.rs:196:13
    |
196 |             ByEmail(ref email) => self.by_email(email),
    |             ^^^^^^^^^^^^^^^^^^ this matches on type `&_`
help: remove the unnecessary binding modifier
    |
196 -             ByEmail(ref email) => self.by_email(email),
196 +             ByEmail(email) => self.by_email(email),
    |

Changes:
- Remove unnecessary "ref" binding modifiers in match statements as in
  later Rust editions so called match ergonomics modified binding
  behavior and "ref" when matching reference is not needed any more.
This commit is contained in:
Zeke Fast
2025-04-27 01:32:15 +02:00
parent e90a2e2888
commit 58959e112e
8 changed files with 56 additions and 56 deletions

View File

@@ -549,9 +549,9 @@ impl<'a> Database<'a> for Filesystem {
fn lookup_primary_fingerprint(&self, term: &Query) -> Option<Fingerprint> {
use super::Query::*;
let path = match term {
ByFingerprint(ref fp) => self.link_by_fingerprint(fp),
ByKeyID(ref keyid) => self.link_by_keyid(keyid),
ByEmail(ref email) => self.link_by_email(email),
ByFingerprint(fp) => self.link_by_fingerprint(fp),
ByKeyID(keyid) => self.link_by_keyid(keyid),
ByEmail(email) => self.link_by_email(email),
_ => return None,
};
path.read_link()

View File

@@ -191,9 +191,9 @@ pub trait Database<'a>: Sync + Send {
fn lookup(&self, term: &Query) -> Result<Option<Cert>> {
use self::Query::*;
let armored = match term {
ByFingerprint(ref fp) => self.by_fpr(fp),
ByKeyID(ref keyid) => self.by_kid(keyid),
ByEmail(ref email) => self.by_email(email),
ByFingerprint(fp) => self.by_fpr(fp),
ByKeyID(keyid) => self.by_kid(keyid),
ByEmail(email) => self.by_email(email),
_ => None,
};

View File

@@ -275,17 +275,17 @@ impl<'a> Database<'a> for Sqlite {
let conn = self.pool.get().unwrap();
match term {
ByFingerprint(ref fp) => query_simple(
ByFingerprint(fp) => query_simple(
&conn,
"SELECT primary_fingerprint FROM cert_identifiers WHERE fingerprint = ?1",
params![fp],
),
ByKeyID(ref keyid) => query_simple(
ByKeyID(keyid) => query_simple(
&conn,
"SELECT primary_fingerprint FROM cert_identifiers WHERE keyid = ?1",
params![keyid],
),
ByEmail(ref email) => query_simple(
ByEmail(email) => query_simple(
&conn,
"SELECT primary_fingerprint FROM emails WHERE email = ?1",
params![email],

View File

@@ -1518,7 +1518,7 @@ fn cert_without_uid(cert: Cert, removed_uid: &UserID) -> Cert {
.into_packet_pile()
.into_children()
.filter(|pkt| match pkt {
Packet::UserID(ref uid) => uid != removed_uid,
Packet::UserID(uid) => uid != removed_uid,
_ => true,
});
Cert::from_packets(packets).unwrap()

View File

@@ -76,7 +76,7 @@ fn delete(db: &KeyDatabase, query: &Query, all_bindings: bool, mut all: bool) ->
// First, delete the bindings.
if all_bindings || all {
results.push(("all bindings".into(), db.set_email_unpublished_all(&fp)));
} else if let Query::ByEmail(ref email) = query {
} else if let Query::ByEmail(email) = query {
results.push((email.to_string(), db.set_email_unpublished(&fp, email)));
} else {
unreachable!()

View File

@@ -465,7 +465,7 @@ impl PacketDumper {
let ii = format!("{} ", i);
match secrets {
SecretKeyMaterial::Unencrypted(ref u) => {
SecretKeyMaterial::Unencrypted(u) => {
writeln!(output, "{}", i)?;
writeln!(output, "{} Unencrypted", ii)?;
if pd.mpis {
@@ -514,7 +514,7 @@ impl PacketDumper {
})?;
}
}
SecretKeyMaterial::Encrypted(ref e) => {
SecretKeyMaterial::Encrypted(e) => {
writeln!(output, "{}", i)?;
writeln!(output, "{} Encrypted", ii)?;
write!(output, "{} S2K: ", ii)?;
@@ -533,17 +533,17 @@ impl PacketDumper {
}
match p {
Unknown(ref u) => {
Unknown(u) => {
writeln!(output, "{} Tag: {}", i, u.tag())?;
writeln!(output, "{} Error: {}", i, u.error())?;
}
PublicKey(ref k) => dump_key(self, output, i, k)?,
PublicSubkey(ref k) => dump_key(self, output, i, k)?,
SecretKey(ref k) => dump_key(self, output, i, k)?,
SecretSubkey(ref k) => dump_key(self, output, i, k)?,
PublicKey(k) => dump_key(self, output, i, k)?,
PublicSubkey(k) => dump_key(self, output, i, k)?,
SecretKey(k) => dump_key(self, output, i, k)?,
SecretSubkey(k) => dump_key(self, output, i, k)?,
Signature(ref s) => {
Signature(s) => {
writeln!(output, "{} Version: {}", i, s.version())?;
writeln!(output, "{} Type: {}", i, s.typ())?;
writeln!(output, "{} Pk algo: {}", i, s.pk_algo())?;
@@ -624,7 +624,7 @@ impl PacketDumper {
}
}
OnePassSig(ref o) => {
OnePassSig(o) => {
writeln!(output, "{} Version: {}", i, o.version())?;
writeln!(output, "{} Type: {}", i, o.typ())?;
writeln!(output, "{} Pk algo: {}", i, o.pk_algo())?;
@@ -633,7 +633,7 @@ impl PacketDumper {
writeln!(output, "{} Last: {}", i, o.last())?;
}
Trust(ref p) => {
Trust(p) => {
writeln!(output, "{} Value:", i)?;
let mut hd = hex::Dumper::new(
&mut output,
@@ -642,7 +642,7 @@ impl PacketDumper {
hd.write_ascii(p.value())?;
}
UserID(ref u) => {
UserID(u) => {
writeln!(
output,
"{} Value: {}",
@@ -651,7 +651,7 @@ impl PacketDumper {
)?;
}
UserAttribute(ref u) => {
UserAttribute(u) => {
use self::openpgp::packet::user_attribute::{Image, Subpacket};
for subpacket in u.subpackets() {
@@ -689,7 +689,7 @@ impl PacketDumper {
Marker(_) => {}
Literal(ref l) => {
Literal(l) => {
writeln!(output, "{} Format: {}", i, l.format())?;
if let Some(filename) = l.filename() {
writeln!(
@@ -704,11 +704,11 @@ impl PacketDumper {
}
}
CompressedData(ref c) => {
CompressedData(c) => {
writeln!(output, "{} Algorithm: {}", i, c.algo())?;
}
PKESK(ref p) => {
PKESK(p) => {
writeln!(output, "{} Version: {}", i, p.version())?;
writeln!(output, "{} Recipient: {}", i, p.recipient())?;
writeln!(output, "{} Pk algo: {}", i, p.pk_algo())?;
@@ -749,10 +749,10 @@ impl PacketDumper {
}
}
SKESK(ref s) => {
SKESK(s) => {
writeln!(output, "{} Version: {}", i, s.version())?;
match s {
self::openpgp::packet::SKESK::V4(ref s) => {
self::openpgp::packet::SKESK::V4(s) => {
writeln!(output, "{} Symmetric algo: {}", i, s.symmetric_algo())?;
write!(output, "{} S2K: ", i)?;
self.dump_s2k(output, i, s.s2k())?;
@@ -761,7 +761,7 @@ impl PacketDumper {
}
}
self::openpgp::packet::SKESK::V5(ref s) => {
self::openpgp::packet::SKESK::V5(s) => {
writeln!(output, "{} Symmetric algo: {}", i, s.symmetric_algo())?;
writeln!(output, "{} AEAD: {}", i, s.aead_algo())?;
write!(output, "{} S2K: ", i)?;
@@ -780,11 +780,11 @@ impl PacketDumper {
}
}
SEIP(ref s) => {
SEIP(s) => {
writeln!(output, "{} Version: {}", i, s.version())?;
}
MDC(ref m) => {
MDC(m) => {
writeln!(output, "{} Digest: {}", i, hex::encode(m.digest()))?;
writeln!(
output,
@@ -794,7 +794,7 @@ impl PacketDumper {
)?;
}
AED(ref a) => {
AED(a) => {
writeln!(output, "{} Version: {}", i, a.version())?;
writeln!(output, "{} Symmetric algo: {}", i, a.symmetric_algo())?;
writeln!(output, "{} AEAD: {}", i, a.aead())?;
@@ -903,7 +903,7 @@ impl PacketDumper {
"{} Trust signature: level {} trust {}",
i, level, trust
)?,
RegularExpression(ref r) => write!(
RegularExpression(r) => write!(
output,
"{} Regular expression: {}",
i,
@@ -913,7 +913,7 @@ impl PacketDumper {
KeyExpirationTime(t) => {
write!(output, "{} Key expiration time: {}", i, t.convert())?
}
PreferredSymmetricAlgorithms(ref c) => write!(
PreferredSymmetricAlgorithms(c) => write!(
output,
"{} Symmetric algo preferences: {}",
i,
@@ -929,7 +929,7 @@ impl PacketDumper {
write!(output, ", sensitive")?;
}
}
Issuer(ref is) => write!(output, "{} Issuer: {}", i, is)?,
Issuer(is) => write!(output, "{} Issuer: {}", i, is)?,
NotationData(n) => {
if n.flags().human_readable() {
write!(output, "{} Notation: {}", i, n)?;
@@ -950,7 +950,7 @@ impl PacketDumper {
hexdump_unknown(output, n.value())?;
}
}
PreferredHashAlgorithms(ref h) => write!(
PreferredHashAlgorithms(h) => write!(
output,
"{} Hash preferences: {}",
i,
@@ -959,7 +959,7 @@ impl PacketDumper {
.collect::<Vec<String>>()
.join(", ")
)?,
PreferredCompressionAlgorithms(ref c) => write!(
PreferredCompressionAlgorithms(c) => write!(
output,
"{} Compression preferences: {}",
i,
@@ -968,30 +968,30 @@ impl PacketDumper {
.collect::<Vec<String>>()
.join(", ")
)?,
KeyServerPreferences(ref p) => {
KeyServerPreferences(p) => {
write!(output, "{} Keyserver preferences: {:?}", i, p)?
}
PreferredKeyServer(ref k) => write!(
PreferredKeyServer(k) => write!(
output,
"{} Preferred keyserver: {}",
i,
String::from_utf8_lossy(k)
)?,
PrimaryUserID(p) => write!(output, "{} Primary User ID: {}", i, p)?,
PolicyURI(ref p) => write!(
PolicyURI(p) => write!(
output,
"{} Policy URI: {}",
i,
String::from_utf8_lossy(p)
)?,
KeyFlags(ref k) => write!(output, "{} Key flags: {:?}", i, k)?,
SignersUserID(ref u) => write!(
KeyFlags(k) => write!(output, "{} Key flags: {:?}", i, k)?,
SignersUserID(u) => write!(
output,
"{} Signer's User ID: {}",
i,
String::from_utf8_lossy(u)
)?,
ReasonForRevocation { code, ref reason } => {
ReasonForRevocation { code, reason } => {
let reason = String::from_utf8_lossy(reason);
write!(
output,
@@ -1002,11 +1002,11 @@ impl PacketDumper {
reason
)?
}
Features(ref f) => write!(output, "{} Features: {:?}", i, f)?,
Features(f) => write!(output, "{} Features: {:?}", i, f)?,
SignatureTarget {
pk_algo,
hash_algo,
ref digest,
digest,
} => write!(
output,
"{} Signature target: {}, {}, {}",
@@ -1020,8 +1020,8 @@ impl PacketDumper {
{
write!(output, "{} Embedded signature: ", i)?
}
IssuerFingerprint(ref fp) => write!(output, "{} Issuer Fingerprint: {}", i, fp)?,
PreferredAEADAlgorithms(ref c) => write!(
IssuerFingerprint(fp) => write!(output, "{} Issuer Fingerprint: {}", i, fp)?,
PreferredAEADAlgorithms(c) => write!(
output,
"{} AEAD preferences: {}",
i,
@@ -1030,7 +1030,7 @@ impl PacketDumper {
.collect::<Vec<String>>()
.join(", ")
)?,
IntendedRecipient(ref fp) => write!(output, "{} Intended Recipient: {}", i, fp)?,
IntendedRecipient(fp) => write!(output, "{} Intended Recipient: {}", i, fp)?,
AttestedCertifications(digests) => {
write!(output, "{} Attested Certifications:", i)?;
if digests.is_empty() {
@@ -1050,7 +1050,7 @@ impl PacketDumper {
match s.value() {
Unknown { .. } => (),
NotationData { .. } => (),
EmbeddedSignature(ref sig) => {
EmbeddedSignature(sig) => {
if s.critical() {
write!(output, " (critical)")?;
}
@@ -1078,14 +1078,14 @@ impl PacketDumper {
writeln!(output, "Simple")?;
writeln!(output, "{} Hash: {}", i, hash)?;
}
Salted { hash, ref salt } => {
Salted { hash, salt } => {
writeln!(output, "Salted")?;
writeln!(output, "{} Hash: {}", i, hash)?;
writeln!(output, "{} Salt: {}", i, hex::encode(salt))?;
}
Iterated {
hash,
ref salt,
salt,
hash_bytes,
} => {
writeln!(output, "Iterated")?;

View File

@@ -14,7 +14,7 @@ impl I18NHelper {
}
pub fn get_catalog(&self, lang: &str) -> &gettext::Catalog {
let (_, ref catalog) = self
let (_, catalog) = self
.catalogs
.iter()
.find(|(candidate, _)| *candidate == lang)

View File

@@ -34,10 +34,10 @@ pub enum Hkp {
impl fmt::Display for Hkp {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Hkp::Fingerprint { ref fpr, .. } => write!(f, "{}", fpr),
Hkp::KeyID { ref keyid, .. } => write!(f, "{}", keyid),
Hkp::Email { ref email, .. } => write!(f, "{}", email),
Hkp::ShortKeyID { ref query, .. } => write!(f, "{}", query),
Hkp::Fingerprint { fpr, .. } => write!(f, "{}", fpr),
Hkp::KeyID { keyid, .. } => write!(f, "{}", keyid),
Hkp::Email { email, .. } => write!(f, "{}", email),
Hkp::ShortKeyID { query, .. } => write!(f, "{}", query),
}
}
}