diff --git a/Cargo.toml b/Cargo.toml index 98bf598fb7..545011120d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,10 +66,11 @@ which = "8.0.0" [lints.rust] mismatched_lifetime_syntaxes = "allow" unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] } +unreachable_pub = "deny" [lints.clippy] all = { level = "deny", priority = -1 } -arbitrary-source-item-ordering = "deny" +arbitrary_source_item_ordering = "deny" enum_glob_use = "allow" ignore_without_reason = "allow" needless_pass_by_value = "allow" diff --git a/src/compile_error.rs b/src/compile_error.rs index 6064099bab..50a7d06bea 100644 --- a/src/compile_error.rs +++ b/src/compile_error.rs @@ -11,7 +11,7 @@ impl<'src> CompileError<'src> { self.token } - pub(crate) fn new(token: Token<'src>, kind: CompileErrorKind<'src>) -> CompileError<'src> { + pub(crate) fn new(token: Token<'src>, kind: CompileErrorKind<'src>) -> Self { Self { token, kind: kind.into(), diff --git a/src/count.rs b/src/count.rs index b6504c99c5..ae451d4153 100644 --- a/src/count.rs +++ b/src/count.rs @@ -1,6 +1,6 @@ use super::*; -pub struct Count(pub T, pub usize); +pub(crate) struct Count(pub T, pub usize); impl Display for Count { fn fmt(&self, f: &mut Formatter) -> fmt::Result { diff --git a/src/enclosure.rs b/src/enclosure.rs index d1cf3eada1..30363a213a 100644 --- a/src/enclosure.rs +++ b/src/enclosure.rs @@ -1,12 +1,12 @@ use super::*; -pub struct Enclosure { +pub(crate) struct Enclosure { enclosure: &'static str, value: T, } impl Enclosure { - pub fn tick(value: T) -> Enclosure { + pub(crate) fn tick(value: T) -> Self { Self { enclosure: "`", value, diff --git a/src/error.rs b/src/error.rs index ba4eeb1753..81a6ef5f9e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -329,8 +329,8 @@ impl<'src> From> for Error<'src> { } } -impl<'src> From for Error<'src> { - fn from(dotenv_error: dotenvy::Error) -> Error<'src> { +impl From for Error<'_> { + fn from(dotenv_error: dotenvy::Error) -> Self { Self::Dotenv { dotenv_error } } } diff --git a/src/expression.rs b/src/expression.rs index ab4d21f275..d736f07f1f 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -9,15 +9,12 @@ use super::*; #[derive(PartialEq, Debug, Clone)] pub(crate) enum Expression<'src> { /// `lhs && rhs` - And { - lhs: Box>, - rhs: Box>, - }, + And { lhs: Box, rhs: Box }, /// `assert(condition, error)` Assert { name: Name<'src>, condition: Condition<'src>, - error: Box>, + error: Box, }, /// `contents` Backtick { @@ -27,33 +24,27 @@ pub(crate) enum Expression<'src> { /// `name(arguments)` Call { thunk: Thunk<'src> }, /// `lhs + rhs` - Concatenation { - lhs: Box>, - rhs: Box>, - }, + Concatenation { lhs: Box, rhs: Box }, /// `if condition { then } else { otherwise }` Conditional { condition: Condition<'src>, - then: Box>, - otherwise: Box>, + then: Box, + otherwise: Box, }, // `f"format string"` FormatString { start: StringLiteral<'src>, - expressions: Vec<(Expression<'src>, StringLiteral<'src>)>, + expressions: Vec<(Self, StringLiteral<'src>)>, }, /// `(contents)` - Group { contents: Box> }, + Group { contents: Box }, /// `lhs / rhs` Join { - lhs: Option>>, - rhs: Box>, + lhs: Option>, + rhs: Box, }, /// `lhs || rhs` - Or { - lhs: Box>, - rhs: Box>, - }, + Or { lhs: Box, rhs: Box }, /// `"string_literal"` or `'string_literal'` StringLiteral { string_literal: StringLiteral<'src> }, /// `variable` diff --git a/src/justfile.rs b/src/justfile.rs index b6e06395fc..0bfcfb4c95 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -12,7 +12,7 @@ pub(crate) struct Justfile<'src> { pub(crate) loaded: Vec, #[serde(skip)] pub(crate) module_path: String, - pub(crate) modules: Table<'src, Justfile<'src>>, + pub(crate) modules: Table<'src, Self>, #[serde(skip)] pub(crate) name: Option>, #[serde(skip)] @@ -80,7 +80,7 @@ impl<'src> Justfile<'src> { config: &'run Config, dotenv: &'run BTreeMap, root: &'run Scope<'src, 'run>, - scopes: &mut BTreeMap, &'run Scope<'src, 'run>)>, + scopes: &mut BTreeMap)>, search: &'run Search, ) -> RunResult<'src> { let scope = Evaluator::evaluate_assignments(config, dotenv, self, root, search)?; @@ -265,15 +265,19 @@ impl<'src> Justfile<'src> { is_dependency: bool, ran: &Ran, recipe: &Recipe<'src>, - scopes: &BTreeMap, &Scope<'src, '_>)>, + scopes: &BTreeMap)>, search: &Search, ) -> RunResult<'src> { - let mutex = ran.mutex(recipe, arguments); + { + let mutex = ran.mutex(recipe, arguments); - let mut guard = mutex.lock().unwrap(); + let mut guard = mutex.lock().unwrap(); - if *guard { - return Ok(()); + if *guard { + return Ok(()); + } + + *guard = true; } if !config.yes && !recipe.confirm()? { @@ -332,8 +336,6 @@ impl<'src> Justfile<'src> { search, )?; - *guard = true; - Ok(()) } @@ -345,7 +347,7 @@ impl<'src> Justfile<'src> { evaluator: &mut Evaluator<'src, 'run>, ran: &Ran, recipe: &Recipe<'src>, - scopes: &BTreeMap, &Scope<'src, 'run>)>, + scopes: &BTreeMap)>, search: &Search, ) -> RunResult<'src> { if context.config.no_dependencies { diff --git a/src/keyword.rs b/src/keyword.rs index 1f0d9186b0..bae639ebaa 100644 --- a/src/keyword.rs +++ b/src/keyword.rs @@ -38,7 +38,7 @@ pub(crate) enum Keyword { } impl Keyword { - pub(crate) fn from_lexeme(lexeme: &str) -> Option { + pub(crate) fn from_lexeme(lexeme: &str) -> Option { lexeme.parse().ok() } diff --git a/src/list.rs b/src/list.rs index 00eb81aa86..9580ddc859 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,32 +1,32 @@ use super::*; -pub struct List + Clone> { +pub(crate) struct List + Clone> { conjunction: &'static str, values: I, } impl + Clone> List { - pub fn or>(values: II) -> Self { + pub(crate) fn or>(values: II) -> Self { Self { conjunction: "or", values: values.into_iter(), } } - pub fn and>(values: II) -> Self { + pub(crate) fn and>(values: II) -> Self { Self { conjunction: "and", values: values.into_iter(), } } - pub fn or_ticked>( + pub(crate) fn or_ticked>( values: II, ) -> List, impl Iterator> + Clone> { List::or(values.into_iter().map(Enclosure::tick)) } - pub fn and_ticked>( + pub(crate) fn and_ticked>( values: II, ) -> List, impl Iterator> + Clone> { List::and(values.into_iter().map(Enclosure::tick)) diff --git a/src/output_error.rs b/src/output_error.rs index 9f8f3e1ba2..4533284345 100644 --- a/src/output_error.rs +++ b/src/output_error.rs @@ -17,7 +17,7 @@ pub(crate) enum OutputError { } impl OutputError { - pub(crate) fn result_from_exit_status(exit_status: ExitStatus) -> Result<(), OutputError> { + pub(crate) fn result_from_exit_status(exit_status: ExitStatus) -> Result<(), Self> { match exit_status.code() { Some(0) => Ok(()), Some(code) => Err(Self::Code(code)), diff --git a/src/positional.rs b/src/positional.rs index 2db8ffee01..5c8c05c77c 100644 --- a/src/positional.rs +++ b/src/positional.rs @@ -27,7 +27,7 @@ use super::*; /// For modes that do take other arguments, the search argument is simply /// prepended to rest. #[cfg_attr(test, derive(PartialEq, Eq, Debug))] -pub struct Positional { +pub(crate) struct Positional { /// Everything else pub arguments: Vec, /// Overrides from values of the form `[a-zA-Z_][a-zA-Z0-9_-]*=.*` @@ -37,7 +37,9 @@ pub struct Positional { } impl Positional { - pub fn from_values<'values>(values: Option>) -> Self { + pub(crate) fn from_values<'values>( + values: Option>, + ) -> Self { let mut overrides = Vec::new(); let mut search_directory = None; let mut arguments = Vec::new(); diff --git a/src/shebang.rs b/src/shebang.rs index eae43a88ea..d629674483 100644 --- a/src/shebang.rs +++ b/src/shebang.rs @@ -30,7 +30,7 @@ impl<'line> Shebang<'line> { }) } - pub fn interpreter_filename(&self) -> &str { + pub(crate) fn interpreter_filename(&self) -> &str { self .interpreter .split(['/', '\\']) diff --git a/src/show_whitespace.rs b/src/show_whitespace.rs index a98c0247bd..ad48ac8679 100644 --- a/src/show_whitespace.rs +++ b/src/show_whitespace.rs @@ -1,7 +1,7 @@ use super::*; /// String wrapper that uses nonblank characters to display spaces and tabs -pub struct ShowWhitespace<'str>(pub &'str str); +pub(crate) struct ShowWhitespace<'str>(pub &'str str); impl Display for ShowWhitespace<'_> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { diff --git a/src/signal.rs b/src/signal.rs index ed78a60795..67cb167edf 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -20,8 +20,8 @@ pub(crate) enum Signal { impl Signal { #[cfg(not(windows))] - pub(crate) const ALL: &'static [Signal] = &[ - Signal::Hangup, + pub(crate) const ALL: &'static [Self] = &[ + Self::Hangup, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", @@ -30,10 +30,10 @@ impl Signal { target_os = "netbsd", target_os = "openbsd", ))] - Signal::Info, - Signal::Interrupt, - Signal::Quit, - Signal::Terminate, + Self::Info, + Self::Interrupt, + Self::Quit, + Self::Terminate, ]; pub(crate) fn code(self) -> i32 { @@ -66,7 +66,7 @@ impl Display for Signal { f, "{}", match self { - Signal::Hangup => "SIGHUP", + Self::Hangup => "SIGHUP", #[cfg(any( target_os = "dragonfly", target_os = "freebsd", @@ -75,10 +75,10 @@ impl Display for Signal { target_os = "netbsd", target_os = "openbsd", ))] - Signal::Info => "SIGINFO", - Signal::Interrupt => "SIGINT", - Signal::Quit => "SIGQUIT", - Signal::Terminate => "SIGTERM", + Self::Info => "SIGINFO", + Self::Interrupt => "SIGINT", + Self::Quit => "SIGQUIT", + Self::Terminate => "SIGTERM", } ) } @@ -108,9 +108,9 @@ impl From for nix::sys::signal::Signal { impl TryFrom for Signal { type Error = io::Error; - fn try_from(n: u8) -> Result { + fn try_from(n: u8) -> Result { match n { - 1 => Ok(Signal::Hangup), + 1 => Ok(Self::Hangup), #[cfg(any( target_os = "dragonfly", target_os = "freebsd", @@ -119,10 +119,10 @@ impl TryFrom for Signal { target_os = "netbsd", target_os = "openbsd", ))] - 29 => Ok(Signal::Info), - 2 => Ok(Signal::Interrupt), - 3 => Ok(Signal::Quit), - 15 => Ok(Signal::Terminate), + 29 => Ok(Self::Info), + 2 => Ok(Self::Interrupt), + 3 => Ok(Self::Quit), + 15 => Ok(Self::Terminate), _ => Err(io::Error::other(format!("unexpected signal: {n}"))), } } diff --git a/src/subcommand.rs b/src/subcommand.rs index 55a0ce8601..1fb8deab31 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -83,7 +83,7 @@ impl Subcommand { &config.search_config, )?; - if let Edit = self { + if matches!(self, Edit) { return Self::edit(&search); } @@ -617,10 +617,8 @@ impl Subcommand { } let no_groups = ordered_groups.len() == 1 && ordered_groups.first() == Some(&None); - let mut groups_count = 0; - if !no_groups { - groups_count = ordered_groups.len(); - } + + let groups_count = if no_groups { 0 } else { ordered_groups.len() }; for (i, group) in ordered_groups.into_iter().enumerate() { if i > 0 { diff --git a/src/summary.rs b/src/summary.rs index 6fa77421ef..0066b2622e 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -184,42 +184,42 @@ impl Assignment { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub enum Expression { And { - lhs: Box, - rhs: Box, + lhs: Box, + rhs: Box, }, Assert { condition: Condition, - error: Box, + error: Box, }, Backtick { command: String, }, Call { name: String, - arguments: Vec, + arguments: Vec, }, Concatenation { - lhs: Box, - rhs: Box, + lhs: Box, + rhs: Box, }, Conditional { - lhs: Box, - rhs: Box, - then: Box, - otherwise: Box, + lhs: Box, + rhs: Box, + then: Box, + otherwise: Box, operator: ConditionalOperator, }, FormatString { start: String, - expressions: Vec<(Expression, String)>, + expressions: Vec<(Self, String)>, }, Join { - lhs: Option>, - rhs: Box, + lhs: Option>, + rhs: Box, }, Or { - lhs: Box, - rhs: Box, + lhs: Box, + rhs: Box, }, String { text: String, @@ -241,13 +241,13 @@ impl Expression { condition: full::Condition { lhs, rhs, operator }, error, .. - } => Expression::Assert { + } => Self::Assert { condition: Condition { - lhs: Box::new(Expression::new(lhs)), - rhs: Box::new(Expression::new(rhs)), + lhs: Box::new(Self::new(lhs)), + rhs: Box::new(Self::new(rhs)), operator: ConditionalOperator::new(*operator), }, - error: Box::new(Expression::new(error)), + error: Box::new(Self::new(error)), }, Backtick { contents, .. } => Self::Backtick { command: (*contents).clone(), @@ -281,11 +281,11 @@ impl Expression { args: (a, rest), .. } => { - let mut arguments = vec![Expression::new(a)]; + let mut arguments = vec![Self::new(a)]; for arg in rest { - arguments.push(Expression::new(arg)); + arguments.push(Self::new(arg)); } - Expression::Call { + Self::Call { name: name.lexeme().to_owned(), arguments, } diff --git a/src/thunk.rs b/src/thunk.rs index df17dec0f0..f72e8e383e 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -63,7 +63,7 @@ impl<'src> Thunk<'src> { pub(crate) fn resolve( name: Name<'src>, mut arguments: Vec>, - ) -> CompileResult<'src, Thunk<'src>> { + ) -> CompileResult<'src, Self> { function::get(name.lexeme()).map_or( Err(name.error(CompileErrorKind::UnknownFunction { function: name.lexeme(), diff --git a/src/verbosity.rs b/src/verbosity.rs index 65db6952e2..14a6988c7f 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -32,7 +32,7 @@ impl Verbosity { self >= Self::Grandiloquent } - pub const fn default() -> Self { + pub(crate) const fn default() -> Self { Self::Taciturn } } diff --git a/tests/test.rs b/tests/test.rs index d7c60d5c99..37161d30d6 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -358,7 +358,7 @@ impl Test { } } -pub fn assert_eval_eq(expression: &str, result: &str) { +pub(crate) fn assert_eval_eq(expression: &str, result: &str) { Test::new() .justfile(format!("x := {expression}")) .args(["--evaluate", "x"])