Skip to content

Commit

Permalink
rust: Add workspace level lints
Browse files Browse the repository at this point in the history
This allows sharing them easily, as we have multiple crates.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 3, 2024
1 parent 3beb011 commit 0d95360
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ debug = true
codegen-units = 1
inherits = "release"
lto = "yes"

[workspace.lints.rust]
# Require an extra opt-in for unsafe
unsafe_code = "deny"
# Absolutely must handle errors
unused_must_use = "forbid"

[workspace.lints.clippy]
# These should only be in local code
dbg_macro = "deny"
todo = "deny"
# These two are in my experience the lints which are most likely
# to trigger, and among the least valuable to fix.
needless_borrow = "allow"
needless_borrows_for_generic_args = "allow"
3 changes: 3 additions & 0 deletions rust/composefs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ system-deps = "6"
[dev-dependencies]
anyhow = "1"
tempfile = "3"

[lints]
workspace = true
32 changes: 16 additions & 16 deletions rust/composefs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod tests {

#[test]
#[cfg(feature = "v1_0_4")]
#[allow(unsafe_code)]
fn test_fd_enable_fsverity() -> Result<()> {
// We can't require fsverity in our test suite, so just verify we can call the
// function.
Expand All @@ -41,22 +42,21 @@ mod tests {
}

#[test]
#[allow(unsafe_code)]
fn test_digest() -> Result<()> {
unsafe {
let mut tf = tempfile::tempfile()?;
tf.write_all(b"hello world")?;
let mut buf = [0u8; LCFS_SHA256_DIGEST_LEN];
tf.seek(std::io::SeekFrom::Start(0))?;
let r = lcfs_compute_fsverity_from_fd(buf.as_mut_ptr(), tf.as_raw_fd());
assert_eq!(r, 0);
assert_eq!(
buf,
[
30, 46, 170, 66, 2, 215, 80, 164, 17, 116, 238, 69, 73, 112, 185, 44, 27, 194,
249, 37, 177, 227, 80, 118, 216, 199, 213, 245, 99, 98, 186, 100
]
);
Ok(())
}
let mut tf = tempfile::tempfile()?;
tf.write_all(b"hello world")?;
let mut buf = [0u8; LCFS_SHA256_DIGEST_LEN];
tf.seek(std::io::SeekFrom::Start(0))?;
let r = unsafe { lcfs_compute_fsverity_from_fd(buf.as_mut_ptr(), tf.as_raw_fd()) };
assert_eq!(r, 0);
assert_eq!(
buf,
[
30, 46, 170, 66, 2, 215, 80, 164, 17, 116, 238, 69, 73, 112, 185, 44, 27, 194, 249,
37, 177, 227, 80, 118, 216, 199, 213, 245, 99, 98, 186, 100
]
);
Ok(())
}
}
3 changes: 3 additions & 0 deletions rust/composefs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ composefs-sys = { version = "0.1.0", path = "../composefs-sys" }
[dev-dependencies]
tar = "0.4.38"
tempfile = "3.2.0"

[lints]
workspace = true
8 changes: 0 additions & 8 deletions rust/composefs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
//! The core functionality exposed at the moment is just support for creating
//! and parsing composefs "superblock" entries.
// See https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![forbid(unused_must_use)]
#![deny(unsafe_code)]
#![deny(clippy::dbg_macro)]
#![deny(clippy::todo)]

use std::{
fs::File,
io::{BufRead, BufReader},
Expand Down

0 comments on commit 0d95360

Please sign in to comment.