commit f0300128db19bf86fa0d7f91906956ed0529398c
parent fdd04912f5008d319ca595580ac4805a20c9f945
Author: Zack Newman <zack@philomathiclife.com>
Date: Wed, 27 Mar 2024 14:06:48 -0600
add more lints
Diffstat:
7 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
name = "rpz"
readme = "README.md"
repository = "https://git.philomathiclife.com/repos/rpz/"
-version = "0.6.0"
+version = "0.6.1"
[lib]
name = "rpz"
@@ -20,18 +20,18 @@ name = "rpz"
path = "src/main.rs"
[dependencies]
-ascii_domain = { version = "0.6.0", default-features = false }
+ascii_domain = { version = "0.6.1", default-features = false }
num-bigint = { version = "0.4.4", default-features = false }
-reqwest = { version = "0.11.24", default-features = false, features = ["brotli", "deflate", "gzip", "rustls-tls-native-roots", "trust-dns"] }
-serde = { version = "1.0.196", default-features = false }
-superset_map = { version = "0.2.2", default-features = false }
+reqwest = { version = "0.12.2", default-features = false, features = ["brotli", "deflate", "gzip", "rustls-tls-native-roots", "trust-dns"] }
+serde = { version = "1.0.197", default-features = false }
+superset_map = { version = "0.2.3", default-features = false }
tokio = { version = "1.36.0", default-features = false, features = ["rt", "time"] }
-toml = { version = "0.8.10", default-features = false, features = ["parse"] }
+toml = { version = "0.8.12", default-features = false, features = ["parse"] }
url = { version = "2.5.0", default-features = false, features = ["serde"] }
-zfc = { version = "0.3.1", default-features = false }
+zfc = { version = "0.3.2", default-features = false }
[target.'cfg(target_os = "openbsd")'.dependencies]
-priv_sep = { version = "1.0.0", default-features = false, features = ["openbsd"], optional = true }
+priv_sep = { version = "1.0.1", default-features = false, features = ["openbsd"], optional = true }
[build-dependencies]
rustc_version = "0.4.0"
diff --git a/src/app.rs b/src/app.rs
@@ -153,10 +153,10 @@ impl<'unblock, 'block> Domains<'unblock, 'block> {
.into_iter()
.fold((), |(), file| doms.add_block_file::<T>(file, summaries));
}
- add_files::<Adblock>(self, &files.adblock, summaries);
- add_files::<DomainOnly>(self, &files.domain, summaries);
- add_files::<Hosts>(self, &files.hosts, summaries);
- add_files::<Wildcard>(self, &files.wildcard, summaries);
+ add_files::<Adblock<'_>>(self, &files.adblock, summaries);
+ add_files::<DomainOnly<'_>>(self, &files.domain, summaries);
+ add_files::<Hosts<'_>>(self, &files.hosts, summaries);
+ add_files::<Wildcard<'_>>(self, &files.wildcard, summaries);
}
/// Parses each line in the files in `files` as an `RpzDomain`.
/// For unblock files, the domain is added to `Domains::unblock`;
diff --git a/src/config.rs b/src/config.rs
@@ -100,7 +100,7 @@ impl<'de> Deserialize<'de> for Config {
impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field;
#[inline]
- fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str(
"'timeout', 'rpz', 'local_dir', 'adblock', 'domain', 'hosts', or 'wildcard'",
)
@@ -130,7 +130,7 @@ impl<'de> Deserialize<'de> for Config {
impl<'d> Visitor<'d> for ConfigVisitor {
type Value = Config;
#[inline]
- fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str("struct Config")
}
#[allow(clippy::as_conversions, clippy::cast_lossless, clippy::too_many_lines)]
@@ -188,7 +188,7 @@ impl<'de> Deserialize<'de> for Config {
impl<'d> Visitor<'d> for HashVisitor {
type Value = Urls;
#[inline]
- fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str("struct Urls")
}
#[inline]
@@ -309,7 +309,6 @@ impl<'de> Deserialize<'de> for Config {
#[cfg(test)]
mod tests {
use crate::Config;
- use toml;
#[test]
fn test_missing_fields() {
assert!(toml::from_str::<Config>("").is_err());
diff --git a/src/dom.rs b/src/dom.rs
@@ -56,12 +56,14 @@ impl error::Error for FirefoxDomainErr {}
const CHARS: &AllowedAscii<[u8; 78]> = &ASCII_FIREFOX;
/// Parses a `[u8]` into a `Domain` using `CHARS` with the added restriction that the `Domain` has a TLD
/// that is either all letters or has length of at least five and begins with `b"xn--"`.
+#[allow(clippy::indexing_slicing)]
#[inline]
fn domain_icann_tld<'a: 'b, 'b>(val: &'a [u8]) -> Result<Domain<&'b str>, FirefoxDomainErr> {
Domain::try_from_bytes(val, CHARS)
.map_err(FirefoxDomainErr::InvalidDomain)
.and_then(|dom| {
let tld = dom.tld();
+ // `tld.as_bytes()[..4]` won't panic since we check before that that the length is at least 5.
if tld.is_alphabetic() || (tld.len().get() > 4 && tld.as_bytes()[..4] == *b"xn--") {
Ok(dom.into())
} else {
@@ -227,6 +229,7 @@ impl<'a, T: ParsedDomain<'a>> Value<'a, T> {
/// [`Value::Domain`], the domain can be written to a
/// [response policy zone (RPZ)](https://en.wikipedia.org/wiki/Response_policy_zone) file.
pub trait ParsedDomain<'a>: Sized {
+ /// The error returned from [`Self::parse_value`].
type Error;
/// Parses a `str` into a `Value`.
/// # Errors
diff --git a/src/file.rs b/src/file.rs
@@ -142,7 +142,7 @@ impl<'de, const IS_DIR: bool> Deserialize<'de> for AbsFilePath<IS_DIR> {
impl<'de, const IS_DIR: bool> Visitor<'de> for FilePathVisitor<IS_DIR> {
type Value = AbsFilePath<IS_DIR>;
#[inline]
- fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str("struct AbsFilePath")
}
#[allow(clippy::arithmetic_side_effects)]
@@ -330,7 +330,7 @@ impl<'de> Deserialize<'de> for HttpUrl {
impl<'d> Visitor<'d> for UrlVisitor {
type Value = HttpUrl;
#[inline]
- fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
+ fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
formatter.write_str("struct HttpUrl")
}
#[inline]
@@ -630,10 +630,10 @@ impl Files {
let mut summaries = Vec::with_capacity(
self.adblock.len() + self.domain.len() + self.hosts.len() + self.wildcard.len(),
);
- insert::<Adblock>(doms, self.adblock.as_slice(), &mut summaries);
- insert::<DomainOnly>(doms, self.domain.as_slice(), &mut summaries);
- insert::<Hosts>(doms, self.hosts.as_slice(), &mut summaries);
- insert::<Wildcard>(doms, self.wildcard.as_slice(), &mut summaries);
+ insert::<Adblock<'_>>(doms, self.adblock.as_slice(), &mut summaries);
+ insert::<DomainOnly<'_>>(doms, self.domain.as_slice(), &mut summaries);
+ insert::<Hosts<'_>>(doms, self.hosts.as_slice(), &mut summaries);
+ insert::<Wildcard<'_>>(doms, self.wildcard.as_slice(), &mut summaries);
summaries
}
/// Returns `true` iff there are no files.
@@ -646,6 +646,12 @@ impl Files {
&& self.wildcard.is_empty()
}
}
+impl Default for Files {
+ #[inline]
+ fn default() -> Self {
+ Self::new()
+ }
+}
/// Block and unblock [`Files`] stored on the local file system.
#[derive(Debug)]
pub struct LocalFiles {
diff --git a/src/lib.rs b/src/lib.rs
@@ -14,6 +14,14 @@
#![feature(io_error_more)]
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
#![deny(
+ future_incompatible,
+ let_underscore,
+ missing_docs,
+ nonstandard_style,
+ rust_2018_compatibility,
+ rust_2018_idioms,
+ rust_2021_compatibility,
+ rust_2024_compatibility,
unsafe_code,
unused,
warnings,
diff --git a/src/main.rs b/src/main.rs
@@ -4,6 +4,14 @@
#![feature(never_type)]
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
#![deny(
+ future_incompatible,
+ let_underscore,
+ missing_docs,
+ nonstandard_style,
+ rust_2018_compatibility,
+ rust_2018_idioms,
+ rust_2021_compatibility,
+ rust_2024_compatibility,
unsafe_code,
unused,
warnings,
@@ -64,7 +72,7 @@ use std::{
sync::OnceLock,
};
use tokio::runtime::Builder;
-use toml::{self, de};
+use toml::de;
/// The HTTP(S) client that is used to download all files.
/// It is initialized exactly once in `main` before being used.
static CLIENT: OnceLock<Client> = OnceLock::new();