Skip to content

Commit

Permalink
chore: Add more lints
Browse files Browse the repository at this point in the history
Same as neqo.
  • Loading branch information
larseggert committed Jan 14, 2025
1 parent 9cd37ac commit d7a5bdc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
allow-mixed-uninlined-format-args = false
allow-unwrap-in-tests = true
doc-valid-idents = ["NetBSD", "OpenBSD", ".."]
35 changes: 35 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,42 @@ windows-bindgen = { version = "0.58", default-features = false, features = ["met
[features]
gecko = ["dep:mozbuild"]

[lints.rust]
absolute_paths_not_starting_with_crate = "warn"
ambiguous_negative_literals = "warn"
closure_returning_async_block = "warn"
explicit_outlives_requirements = "warn"
macro_use_extern_crate = "warn"
missing_abi = "warn"
non_ascii_idents = "warn"
redundant_imports = "warn"
redundant_lifetimes = "warn"
trivial_numeric_casts = "warn"
unit_bindings = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"
unused_macro_rules = "warn"
# unused_qualifications = "warn" // Try to re-enable when MSRV is > 1.76

[lints.clippy]
cargo = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
multiple_crate_versions = "allow"
cfg_not_test = "warn"
clone_on_ref_ptr = "warn"
create_dir = "warn"
if_then_some_else_none = "warn"
get_unwrap = "warn"
multiple_inherent_impl = "warn"
pathbuf_init_then_push = "warn"
redundant_type_annotations = "warn"
ref_patterns = "warn"
renamed_function_params = "warn"
semicolon_inside_block = "warn"
try_err = "warn"
unneeded_field_pattern = "warn"
unused_result_ok = "warn"
unused_trait_names = "warn"
unwrap_used = "warn"
unwrap_in_result = "warn"
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn bindgen() {
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/$BINDINGS file.
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join(BINDINGS);
let out_path =
std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap_or_default()).join(BINDINGS);
bindings
.write_to_file(out_path.clone())
.expect("Couldn't write bindings!");
Expand Down
24 changes: 9 additions & 15 deletions src/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

use std::{
ffi::CStr,
io::{Error, ErrorKind, Read, Result, Write},
io::{Error, ErrorKind, Read as _, Result, Write as _},
marker::PhantomData,
mem::size_of,
net::IpAddr,
num::TryFromIntError,
ops::Deref,
Expand Down Expand Up @@ -104,7 +103,9 @@ impl Drop for IfAddrs {
fn drop(&mut self) {
if !self.0.is_null() {
// Free the memory allocated by `getifaddrs`.
unsafe { freeifaddrs(self.0) };
unsafe {
freeifaddrs(self.0);
}
}
}
}
Expand Down Expand Up @@ -136,7 +137,7 @@ impl Deref for IfAddrPtr<'_> {
type Target = ifaddrs;

fn deref(&self) -> &Self::Target {
unsafe { self.ptr.as_ref().unwrap() }
unsafe { self.ptr.as_ref().expect("can deref") }
}
}

Expand Down Expand Up @@ -326,17 +327,10 @@ fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option<usize>)> {
// This is a reply to our query.
// This is the reply we are looking for.
// Some BSDs let us get the interface index and MTU directly from the reply.
let mtu: Option<usize> = if reply.rtm_rmx.rmx_mtu != 0 {
Some(
reply
.rtm_rmx
.rmx_mtu
.try_into()
.map_err(|e: TryFromIntError| unlikely_err(e.to_string()))?,
)
} else {
None
};
let mtu = (reply.rtm_rmx.rmx_mtu != 0)
.then(|| usize::try_from(reply.rtm_rmx.rmx_mtu))
.transpose()
.map_err(|e: TryFromIntError| unlikely_err(e.to_string()))?;
if reply.rtm_index != 0 {
// Some BSDs return the interface index directly.
return Ok((reply.rtm_index, mtu));
Expand Down
2 changes: 1 addition & 1 deletion src/routesocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::{
io::{Error, Read, Result, Write},
num::TryFromIntError,
os::fd::{AsRawFd, FromRawFd, OwnedFd},
os::fd::{AsRawFd, FromRawFd as _, OwnedFd},
sync::atomic::Ordering,
};

Expand Down

0 comments on commit d7a5bdc

Please sign in to comment.