Skip to content

Commit

Permalink
Merge pull request #96 from jfrimmel/clippy
Browse files Browse the repository at this point in the history
Fix all actionable clippy lints and re-enable clippy in CI
  • Loading branch information
jfrimmel authored Sep 18, 2024
2 parents 1c7bba0 + e4511ff commit f9e323b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.51.0"
9 changes: 9 additions & 0 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ jobs:
- run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
# Check for code issues
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup component add clippy
- name: Run linter
run: cargo clippy --color=always -- -D warnings
13 changes: 5 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ fn display_generic_error(error: &valgrind::xml::Error) {
eprintln!(
"{:>12} {}",
"Error".red().bold(),
error
.main_info
.as_ref()
.map(String::as_str)
.unwrap_or("unknown"),
error.main_info.as_ref().map_or("unknown", String::as_str)
);

let stack = &error.stack_trace[0]; // always available
Expand All @@ -83,10 +79,11 @@ fn display_generic_error(error: &valgrind::xml::Error) {
display_stack_trace(
msg.map_or_else(|| "additional stack trace", String::as_str),
stack,
)
})
);
});
}

/// Write out the full stack trace (indented to match other messages).
fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) {
eprintln!("{:>12} {}", "Info".cyan().bold(), msg);
stack
Expand All @@ -98,7 +95,7 @@ fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) {
fn main() {
panic::replace_hook();

let number_of_arguments = || env::args_os().skip(0).count();
let number_of_arguments = || env::args_os().skip(1).count();
let help_requested = || env::args_os().any(|arg| arg == "--help" || arg == "-h");
let is_cargo_subcommand = || env::args_os().nth(1).map_or(false, |arg| arg == "valgrind");
if number_of_arguments() == 0 || help_requested() {
Expand Down
1 change: 1 addition & 0 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const PANIC_HEADER: &str = "
///
/// This is helpful for printing debug information to the panic message.
#[macro_export]
#[allow(clippy::module_name_repetitions)] // necessary for exported macro
macro_rules! panic_with {
($e:expr) => {
std::panic::panic_any($e)
Expand Down
2 changes: 1 addition & 1 deletion src/valgrind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where

// additional options to pass to valgrind?
if let Ok(additional_args) = env::var("VALGRINDFLAGS") {
valgrind.args(additional_args.split(" "));
valgrind.args(additional_args.split(' '));
}

let cargo = valgrind
Expand Down
32 changes: 16 additions & 16 deletions src/valgrind/xml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ pub enum Kind {
}
impl Kind {
/// Query, if the current error kind is a memory leak
pub(crate) fn is_leak(&self) -> bool {
pub(crate) const fn is_leak(self) -> bool {
match self {
Kind::LeakDefinitelyLost
| Kind::LeakStillReachable
| Kind::LeakIndirectlyLost
| Kind::LeakPossiblyLost => true,
Kind::InvalidFree
| Kind::MismatchedFree
| Kind::InvalidRead
| Kind::InvalidWrite
| Kind::InvalidJump
| Kind::Overlap
| Kind::InvalidMemPool
| Kind::UninitCondition
| Kind::UninitValue
| Kind::SyscallParam
| Kind::ClientCheck => false,
Self::LeakDefinitelyLost
| Self::LeakStillReachable
| Self::LeakIndirectlyLost
| Self::LeakPossiblyLost => true,
Self::InvalidFree
| Self::MismatchedFree
| Self::InvalidRead
| Self::InvalidWrite
| Self::InvalidJump
| Self::Overlap
| Self::InvalidMemPool
| Self::UninitCondition
| Self::UninitValue
| Self::SyscallParam
| Self::ClientCheck => false,
}
}
}
Expand Down

0 comments on commit f9e323b

Please sign in to comment.