From 629c75ff0453626f86f60c1913c5bf24a852a250 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 16 Sep 2021 16:44:40 +0300 Subject: [PATCH] Use stable rustfmt instead of nightly (#967) --- .github/workflows/build.yaml | 12 +-- justfile | 3 +- rustfmt.toml | 27 ++----- src/alias.rs | 2 +- src/analyzer.rs | 32 ++++---- src/assignment_resolver.rs | 20 ++--- src/ast.rs | 2 +- src/binding.rs | 4 +- src/color.rs | 8 +- src/compile_error.rs | 78 +++++++++--------- src/compile_error_kind.rs | 32 ++++---- src/config.rs | 54 +++++++------ src/config_error.rs | 8 +- src/dependency.rs | 2 +- src/enclosure.rs | 2 +- src/error.rs | 151 ++++++++++++++++++----------------- src/evaluator.rs | 39 ++++----- src/expression.rs | 10 +-- src/function_context.rs | 4 +- src/interrupt_handler.rs | 10 +-- src/justfile.rs | 51 ++++++------ src/lexer.rs | 69 ++++++++-------- src/list.rs | 10 +-- src/name.rs | 14 ++-- src/node.rs | 17 ++-- src/output.rs | 2 +- src/parameter.rs | 6 +- src/parser.rs | 45 ++++++----- src/position.rs | 2 +- src/positional.rs | 4 +- src/recipe.rs | 38 ++++----- src/recipe_context.rs | 6 +- src/recipe_resolver.rs | 6 +- src/scope.rs | 6 +- src/search.rs | 24 +++--- src/search_config.rs | 2 +- src/search_error.rs | 2 +- src/set.rs | 2 +- src/setting.rs | 2 +- src/settings.rs | 12 +-- src/shebang.rs | 2 +- src/string_kind.rs | 7 +- src/string_literal.rs | 4 +- src/subcommand.rs | 42 +++++----- src/suggestion.rs | 2 +- src/summary.rs | 58 +++++++------- src/testing.rs | 2 +- src/thunk.rs | 20 ++--- src/token.rs | 13 +-- src/token_kind.rs | 68 ++++++++-------- src/tree.rs | 4 +- src/unresolved_dependency.rs | 2 +- src/unresolved_recipe.rs | 8 +- src/variables.rs | 6 +- src/warning.rs | 2 +- 55 files changed, 537 insertions(+), 523 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4ed8340..9625ef2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -80,7 +80,7 @@ jobs: - name: Install Rust Toolchain run: | - rustup component add clippy + rustup component add clippy rustfmt rustup target add ${{ matrix.target }} rustup default "`cat rust-toolchain`-${{ matrix.target }}" @@ -108,16 +108,8 @@ jobs: - name: Clippy run: cargo clippy --all --all-targets --all-features - - name: Install Rustfmt Toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - target: ${{ matrix.target }} - profile: minimal - components: rustfmt - - name: Format - run: cargo +nightly fmt --all -- --check + run: cargo fmt --all -- --check - name: Completion Scripts if: ${{ matrix.os != 'windows-2016' }} diff --git a/justfile b/justfile index 3ed973d..059bb79 100755 --- a/justfile +++ b/justfile @@ -31,7 +31,7 @@ build: cargo lbuild fmt: - cargo +nightly fmt --all + cargo fmt --all watch +COMMAND='ltest': cargo watch --clear --exec "{{COMMAND}}" @@ -94,7 +94,6 @@ install: install-dev-deps: rustup install nightly rustup update nightly - rustup run nightly cargo install clippy cargo +nightly install cargo-fuzz cargo install cargo-check cargo install cargo-limit diff --git a/rustfmt.toml b/rustfmt.toml index 4e7d74f..84ec2a7 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,21 +1,6 @@ -comment_width = 80 -edition = "2018" -error_on_line_overflow = true -error_on_unformatted = true -format_code_in_doc_comments = true -format_macro_bodies = true -format_strings = true -imports_granularity = "Crate" -match_arm_blocks = false -match_block_trailing_comma = true -max_width = 100 -newline_style = "Unix" -normalize_comments = true -overflow_delimited_expr = true -reorder_impl_items = true -struct_field_align_threshold = 20 -tab_spaces = 2 -unstable_features = true -use_field_init_shorthand = true -use_try_shorthand = true -wrap_comments = true +edition = "2018" +max_width = 100 +newline_style = "Unix" +tab_spaces = 2 +use_field_init_shorthand = true +use_try_shorthand = true diff --git a/src/alias.rs b/src/alias.rs index 5dafe12..be00432 100644 --- a/src/alias.rs +++ b/src/alias.rs @@ -3,7 +3,7 @@ use crate::common::*; /// An alias, e.g. `name := target` #[derive(Debug, PartialEq, Clone)] pub(crate) struct Alias<'src, T = Rc>> { - pub(crate) name: Name<'src>, + pub(crate) name: Name<'src>, pub(crate) target: T, } diff --git a/src/analyzer.rs b/src/analyzer.rs index 83eba48..746781c 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -4,10 +4,10 @@ use CompileErrorKind::*; #[derive(Default)] pub(crate) struct Analyzer<'src> { - recipes: Table<'src, UnresolvedRecipe<'src>>, + recipes: Table<'src, UnresolvedRecipe<'src>>, assignments: Table<'src, Assignment<'src>>, - aliases: Table<'src, Alias<'src, Name<'src>>>, - sets: Table<'src, Set<'src>>, + aliases: Table<'src, Alias<'src, Name<'src>>>, + sets: Table<'src, Set<'src>>, } impl<'src> Analyzer<'src> { @@ -21,20 +21,20 @@ impl<'src> Analyzer<'src> { Item::Alias(alias) => { self.analyze_alias(&alias)?; self.aliases.insert(alias); - }, + } Item::Assignment(assignment) => { self.analyze_assignment(&assignment)?; self.assignments.insert(assignment); - }, + } Item::Comment(_) => (), Item::Recipe(recipe) => { self.analyze_recipe(&recipe)?; self.recipes.insert(recipe); - }, + } Item::Set(set) => { self.analyze_set(&set)?; self.sets.insert(set); - }, + } } } @@ -65,17 +65,17 @@ impl<'src> Analyzer<'src> { match set.value { Setting::DotenvLoad(dotenv_load) => { settings.dotenv_load = Some(dotenv_load); - }, + } Setting::Export(export) => { settings.export = export; - }, + } Setting::PositionalArguments(positional_arguments) => { settings.positional_arguments = positional_arguments; - }, + } Setting::Shell(shell) => { assert!(settings.shell.is_none()); settings.shell = Some(shell); - }, + } } } @@ -92,7 +92,7 @@ impl<'src> Analyzer<'src> { if let Some(original) = self.recipes.get(recipe.name.lexeme()) { return Err(recipe.name.token().error(DuplicateRecipe { recipe: original.name(), - first: original.line_number(), + first: original.line_number(), })); } @@ -102,7 +102,7 @@ impl<'src> Analyzer<'src> { for parameter in &recipe.parameters { if parameters.contains(parameter.name.lexeme()) { return Err(parameter.name.token().error(DuplicateParameter { - recipe: recipe.name.lexeme(), + recipe: recipe.name.lexeme(), parameter: parameter.name.lexeme(), })); } @@ -166,7 +166,7 @@ impl<'src> Analyzer<'src> { if let Some(original) = self.sets.get(set.name.lexeme()) { return Err(set.name.error(DuplicateSet { setting: original.name.lexeme(), - first: original.name.line, + first: original.name.line, })); } @@ -181,7 +181,7 @@ impl<'src> Analyzer<'src> { // Make sure the alias doesn't conflict with any recipe if let Some(recipe) = recipes.get(alias.name.lexeme()) { return Err(token.error(AliasShadowsRecipe { - alias: alias.name.lexeme(), + alias: alias.name.lexeme(), recipe_line: recipe.line_number(), })); } @@ -190,7 +190,7 @@ impl<'src> Analyzer<'src> { match recipes.get(alias.target.lexeme()) { Some(target) => Ok(alias.resolve(Rc::clone(target))), None => Err(token.error(UnknownAliasTarget { - alias: alias.name.lexeme(), + alias: alias.name.lexeme(), target: alias.target.lexeme(), })), } diff --git a/src/assignment_resolver.rs b/src/assignment_resolver.rs index c802e39..e086e40 100644 --- a/src/assignment_resolver.rs +++ b/src/assignment_resolver.rs @@ -4,8 +4,8 @@ use CompileErrorKind::*; pub(crate) struct AssignmentResolver<'src: 'run, 'run> { assignments: &'run Table<'src, Assignment<'src>>, - stack: Vec<&'src str>, - evaluated: BTreeSet<&'src str>, + stack: Vec<&'src str>, + evaluated: BTreeSet<&'src str>, } impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> { @@ -38,12 +38,12 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> { } else { let message = format!("attempted to resolve unknown assignment `{}`", name); let token = Token { - src: "", + src: "", offset: 0, - line: 0, + line: 0, column: 0, length: 0, - kind: TokenKind::Unspecified, + kind: TokenKind::Unspecified, }; return Err(CompileError { kind: Internal { message }, @@ -74,26 +74,26 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> { } else { Err(name.token().error(UndefinedVariable { variable })) } - }, + } Expression::Call { thunk } => match thunk { Thunk::Nullary { .. } => Ok(()), Thunk::Unary { arg, .. } => self.resolve_expression(arg), Thunk::Binary { args: [a, b], .. } => { self.resolve_expression(a)?; self.resolve_expression(b) - }, + } Thunk::Ternary { args: [a, b, c], .. } => { self.resolve_expression(a)?; self.resolve_expression(b)?; self.resolve_expression(c) - }, + } }, Expression::Concatination { lhs, rhs } => { self.resolve_expression(lhs)?; self.resolve_expression(rhs) - }, + } Expression::Conditional { lhs, rhs, @@ -105,7 +105,7 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> { self.resolve_expression(rhs)?; self.resolve_expression(then)?; self.resolve_expression(otherwise) - }, + } Expression::StringLiteral { .. } | Expression::Backtick { .. } => Ok(()), Expression::Group { contents } => self.resolve_expression(contents), } diff --git a/src/ast.rs b/src/ast.rs index cff7a63..5dfe982 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -6,7 +6,7 @@ use crate::common::*; #[derive(Debug, Clone)] pub(crate) struct Ast<'src> { /// Items in the justfile - pub(crate) items: Vec>, + pub(crate) items: Vec>, /// Non-fatal warnings encountered during parsing pub(crate) warnings: Vec, } diff --git a/src/binding.rs b/src/binding.rs index 185c4ad..817db2f 100644 --- a/src/binding.rs +++ b/src/binding.rs @@ -6,9 +6,9 @@ pub(crate) struct Binding<'src, V = String> { /// Export binding as an environment variable to child processes pub(crate) export: bool, /// Binding name - pub(crate) name: Name<'src>, + pub(crate) name: Name<'src>, /// Binding value - pub(crate) value: V, + pub(crate) value: V, } impl<'src, V> Keyed<'src> for Binding<'src, V> { diff --git a/src/color.rs b/src/color.rs index 18340c3..f64b5d3 100644 --- a/src/color.rs +++ b/src/color.rs @@ -6,8 +6,8 @@ use atty::Stream; #[derive(Copy, Clone, Debug, PartialEq)] pub(crate) struct Color { use_color: UseColor, - atty: bool, - style: Style, + atty: bool, + style: Style, } impl Color { @@ -120,8 +120,8 @@ impl Default for Color { fn default() -> Self { Self { use_color: UseColor::Auto, - atty: false, - style: Style::new(), + atty: false, + style: Style::new(), } } } diff --git a/src/compile_error.rs b/src/compile_error.rs index d3d9d89..21d856c 100644 --- a/src/compile_error.rs +++ b/src/compile_error.rs @@ -3,7 +3,7 @@ use crate::common::*; #[derive(Debug, PartialEq)] pub(crate) struct CompileError<'src> { pub(crate) token: Token<'src>, - pub(crate) kind: CompileErrorKind<'src>, + pub(crate) kind: CompileErrorKind<'src>, } impl<'src> CompileError<'src> { @@ -26,11 +26,11 @@ impl Display for CompileError<'_> { alias, recipe_line.ordinal(), )?; - }, + } BacktickShebang => { write!(f, "Backticks may not start with `#!`")?; - }, - CircularRecipeDependency { recipe, ref circle } => + } + CircularRecipeDependency { recipe, ref circle } => { if circle.len() == 2 { write!(f, "Recipe `{}` depends on itself", recipe)?; } else { @@ -40,11 +40,12 @@ impl Display for CompileError<'_> { recipe, circle.join(" -> ") )?; - }, + } + } CircularVariableDependency { variable, ref circle, - } => + } => { if circle.len() == 2 { write!(f, "Variable `{}` is defined in terms of itself", variable)?; } else { @@ -54,7 +55,8 @@ impl Display for CompileError<'_> { variable, circle.join(" -> ") )?; - }, + } + } DependencyArgumentCountMismatch { dependency, found, @@ -77,7 +79,7 @@ impl Display for CompileError<'_> { } else { write!(f, "at most {} {}", max, Count("argument", *max))?; } - }, + } DeprecatedEquals => { writeln!( f, @@ -87,7 +89,7 @@ impl Display for CompileError<'_> { f, "Please see this issue for more details: https://github.com/casey/just/issues/379" )?; - }, + } DuplicateAlias { alias, first } => { write!( f, @@ -96,14 +98,14 @@ impl Display for CompileError<'_> { first.ordinal(), self.token.line.ordinal(), )?; - }, + } DuplicateParameter { recipe, parameter } => { write!( f, "Recipe `{}` has duplicate parameter `{}`", recipe, parameter )?; - }, + } DuplicateRecipe { recipe, first } => { write!( f, @@ -112,7 +114,7 @@ impl Display for CompileError<'_> { first.ordinal(), self.token.line.ordinal() )?; - }, + } DuplicateSet { setting, first } => { write!( f, @@ -121,10 +123,10 @@ impl Display for CompileError<'_> { first.ordinal(), self.token.line.ordinal(), )?; - }, + } DuplicateVariable { variable } => { write!(f, "Variable `{}` has multiple definitions", variable)?; - }, + } ExpectedKeyword { expected, found } => write!( f, "Expected keyword {} but found identifier `{}`", @@ -133,7 +135,7 @@ impl Display for CompileError<'_> { )?, ExtraLeadingWhitespace => { write!(f, "Recipe line has extra leading whitespace")?; - }, + } FunctionArgumentCountMismatch { function, found, @@ -147,7 +149,7 @@ impl Display for CompileError<'_> { Count("argument", *found), expected )?; - }, + } InconsistentLeadingWhitespace { expected, found } => { write!( f, @@ -156,7 +158,7 @@ impl Display for CompileError<'_> { ShowWhitespace(expected), ShowWhitespace(found) )?; - }, + } Internal { ref message } => { write!( f, @@ -164,7 +166,7 @@ impl Display for CompileError<'_> { consider filing an issue: https://github.com/casey/just/issues/new", message )?; - }, + } InvalidEscapeSequence { character } => { let representation = match character { '`' => r"\`".to_owned(), @@ -174,7 +176,7 @@ impl Display for CompileError<'_> { _ => character.escape_default().collect(), }; write!(f, "`\\{}` is not a valid escape sequence", representation)?; - }, + } MismatchedClosingDelimiter { open, open_line, @@ -187,7 +189,7 @@ impl Display for CompileError<'_> { open.open(), open_line.ordinal(), )?; - }, + } MixedLeadingWhitespace { whitespace } => { write!( f, @@ -195,73 +197,73 @@ impl Display for CompileError<'_> { consist of tabs or spaces, but not both", ShowWhitespace(whitespace) )?; - }, + } ParameterFollowsVariadicParameter { parameter } => { write!(f, "Parameter `{}` follows variadic parameter", parameter)?; - }, + } ParameterShadowsVariable { parameter } => { write!( f, "Parameter `{}` shadows variable of the same name", parameter )?; - }, + } RequiredParameterFollowsDefaultParameter { parameter } => { write!( f, "Non-default parameter `{}` follows default parameter", parameter )?; - }, + } UndefinedVariable { variable } => { write!(f, "Variable `{}` not defined", variable)?; - }, + } UnexpectedCharacter { expected } => { write!(f, "Expected character `{}`", expected)?; - }, + } UnexpectedClosingDelimiter { close } => { write!(f, "Unexpected closing delimiter `{}`", close.close())?; - }, + } UnexpectedEndOfToken { expected } => { write!(f, "Expected character `{}` but found end-of-file", expected)?; - }, + } UnexpectedToken { ref expected, found, } => { write!(f, "Expected {}, but found {}", List::or(expected), found)?; - }, + } UnknownAliasTarget { alias, target } => { write!(f, "Alias `{}` has an unknown target `{}`", alias, target)?; - }, + } UnknownDependency { recipe, unknown } => { write!( f, "Recipe `{}` has unknown dependency `{}`", recipe, unknown )?; - }, + } UnknownFunction { function } => { write!(f, "Call to unknown function `{}`", function)?; - }, + } UnknownSetting { setting } => { write!(f, "Unknown setting `{}`", setting)?; - }, + } UnknownStartOfToken => { write!(f, "Unknown start of token:")?; - }, + } UnpairedCarriageReturn => { write!(f, "Unpaired carriage return")?; - }, + } UnterminatedBacktick => { write!(f, "Unterminated backtick")?; - }, + } UnterminatedInterpolation => { write!(f, "Unterminated interpolation")?; - }, + } UnterminatedString => { write!(f, "Unterminated string")?; - }, + } } Ok(()) diff --git a/src/compile_error_kind.rs b/src/compile_error_kind.rs index 5909480..af47107 100644 --- a/src/compile_error_kind.rs +++ b/src/compile_error_kind.rs @@ -3,7 +3,7 @@ use crate::common::*; #[derive(Debug, PartialEq)] pub(crate) enum CompileErrorKind<'src> { AliasShadowsRecipe { - alias: &'src str, + alias: &'src str, recipe_line: usize, }, BacktickShebang, @@ -13,13 +13,13 @@ pub(crate) enum CompileErrorKind<'src> { }, CircularVariableDependency { variable: &'src str, - circle: Vec<&'src str>, + circle: Vec<&'src str>, }, DependencyArgumentCountMismatch { dependency: &'src str, - found: usize, - min: usize, - max: usize, + found: usize, + min: usize, + max: usize, }, DeprecatedEquals, DuplicateAlias { @@ -27,33 +27,33 @@ pub(crate) enum CompileErrorKind<'src> { first: usize, }, DuplicateParameter { - recipe: &'src str, + recipe: &'src str, parameter: &'src str, }, DuplicateRecipe { recipe: &'src str, - first: usize, + first: usize, }, DuplicateSet { setting: &'src str, - first: usize, + first: usize, }, DuplicateVariable { variable: &'src str, }, ExpectedKeyword { expected: Vec, - found: &'src str, + found: &'src str, }, ExtraLeadingWhitespace, FunctionArgumentCountMismatch { function: &'src str, - found: usize, + found: usize, expected: usize, }, InconsistentLeadingWhitespace { expected: &'src str, - found: &'src str, + found: &'src str, }, Internal { message: String, @@ -62,8 +62,8 @@ pub(crate) enum CompileErrorKind<'src> { character: char, }, MismatchedClosingDelimiter { - close: Delimiter, - open: Delimiter, + close: Delimiter, + open: Delimiter, open_line: usize, }, MixedLeadingWhitespace { @@ -92,14 +92,14 @@ pub(crate) enum CompileErrorKind<'src> { }, UnexpectedToken { expected: Vec, - found: TokenKind, + found: TokenKind, }, UnknownAliasTarget { - alias: &'src str, + alias: &'src str, target: &'src str, }, UnknownDependency { - recipe: &'src str, + recipe: &'src str, unknown: &'src str, }, UnknownFunction { diff --git a/src/config.rs b/src/config.rs index c0a1772..43d84e0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,24 +14,24 @@ pub(crate) const DEFAULT_SHELL_ARG: &str = "-cu"; #[derive(Debug, PartialEq)] pub(crate) struct Config { - pub(crate) color: Color, - pub(crate) dry_run: bool, - pub(crate) highlight: bool, + pub(crate) color: Color, + pub(crate) dry_run: bool, + pub(crate) highlight: bool, pub(crate) invocation_directory: PathBuf, - pub(crate) list_heading: String, - pub(crate) list_prefix: String, - pub(crate) load_dotenv: bool, - pub(crate) search_config: SearchConfig, - pub(crate) shell: String, - pub(crate) shell_args: Vec, - pub(crate) shell_command: bool, - pub(crate) shell_present: bool, - pub(crate) subcommand: Subcommand, - pub(crate) unsorted: bool, - pub(crate) unstable: bool, - pub(crate) dotenv_filename: Option, - pub(crate) dotenv_path: Option, - pub(crate) verbosity: Verbosity, + pub(crate) list_heading: String, + pub(crate) list_prefix: String, + pub(crate) load_dotenv: bool, + pub(crate) search_config: SearchConfig, + pub(crate) shell: String, + pub(crate) shell_args: Vec, + pub(crate) shell_command: bool, + pub(crate) shell_present: bool, + pub(crate) subcommand: Subcommand, + pub(crate) unsorted: bool, + pub(crate) unstable: bool, + pub(crate) dotenv_filename: Option, + pub(crate) dotenv_path: Option, + pub(crate) verbosity: Verbosity, } mod cmd { @@ -416,15 +416,17 @@ impl Config { match (justfile, working_directory) { (None, None) => SearchConfig::FromInvocationDirectory, (Some(justfile), None) => SearchConfig::WithJustfile { justfile }, - (Some(justfile), Some(working_directory)) => + (Some(justfile), Some(working_directory)) => { SearchConfig::WithJustfileAndWorkingDirectory { justfile, working_directory, - }, - (None, Some(_)) => + } + } + (None, Some(_)) => { return Err(ConfigError::internal( "--working-directory set without --justfile", - )), + )) + } } } }; @@ -432,26 +434,26 @@ impl Config { for subcommand in cmd::ARGLESS { if matches.is_present(subcommand) { match (!overrides.is_empty(), !positional.arguments.is_empty()) { - (false, false) => {}, + (false, false) => {} (true, false) => { return Err(ConfigError::SubcommandOverrides { subcommand, overrides, }); - }, + } (false, true) => { return Err(ConfigError::SubcommandArguments { arguments: positional.arguments, subcommand, }); - }, + } (true, true) => { return Err(ConfigError::SubcommandOverridesAndArguments { arguments: positional.arguments, subcommand, overrides, }); - }, + } } } } @@ -497,7 +499,7 @@ impl Config { if positional.arguments.len() > 1 { return Err(ConfigError::SubcommandArguments { subcommand: cmd::EVALUATE, - arguments: positional + arguments: positional .arguments .into_iter() .skip(1) diff --git a/src/config_error.rs b/src/config_error.rs index 82cc1bb..ce4d3d7 100644 --- a/src/config_error.rs +++ b/src/config_error.rs @@ -23,7 +23,7 @@ pub(crate) enum ConfigError { ))] SubcommandArguments { subcommand: &'static str, - arguments: Vec, + arguments: Vec, }, #[snafu(display( "`--{}` used with unexpected overrides: {}", @@ -32,7 +32,7 @@ pub(crate) enum ConfigError { ))] SubcommandOverrides { subcommand: &'static str, - overrides: BTreeMap, + overrides: BTreeMap, }, #[snafu(display( "`--{}` used with unexpected overrides: {}; and arguments: {}", @@ -42,8 +42,8 @@ pub(crate) enum ConfigError { ] SubcommandOverridesAndArguments { subcommand: &'static str, - overrides: BTreeMap, - arguments: Vec, + overrides: BTreeMap, + arguments: Vec, }, } diff --git a/src/dependency.rs b/src/dependency.rs index 58dfde5..aa620c4 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -2,7 +2,7 @@ use crate::common::*; #[derive(PartialEq, Debug)] pub(crate) struct Dependency<'src> { - pub(crate) recipe: Rc>, + pub(crate) recipe: Rc>, pub(crate) arguments: Vec>, } diff --git a/src/enclosure.rs b/src/enclosure.rs index 2e90332..a9ac31a 100644 --- a/src/enclosure.rs +++ b/src/enclosure.rs @@ -5,7 +5,7 @@ use crate::common::*; pub struct Enclosure { enclosure: &'static str, - value: T, + value: T, } impl Enclosure { diff --git a/src/error.rs b/src/error.rs index 94186c2..ba3ffe8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,48 +3,48 @@ use crate::common::*; #[derive(Debug)] pub(crate) enum Error<'src> { ArgumentCountMismatch { - recipe: &'src str, + recipe: &'src str, parameters: Vec>, - found: usize, - min: usize, - max: usize, + found: usize, + min: usize, + max: usize, }, Backtick { - token: Token<'src>, + token: Token<'src>, output_error: OutputError, }, ChooserInvoke { - shell_binary: String, + shell_binary: String, shell_arguments: String, - chooser: OsString, - io_error: io::Error, + chooser: OsString, + io_error: io::Error, }, ChooserRead { - chooser: OsString, + chooser: OsString, io_error: io::Error, }, ChooserStatus { chooser: OsString, - status: ExitStatus, + status: ExitStatus, }, ChooserWrite { - chooser: OsString, + chooser: OsString, io_error: io::Error, }, Code { - recipe: &'src str, + recipe: &'src str, line_number: Option, - code: i32, + code: i32, }, CommandInvoke { - binary: OsString, + binary: OsString, arguments: Vec, - io_error: io::Error, + io_error: io::Error, }, CommandStatus { - binary: OsString, + binary: OsString, arguments: Vec, - status: ExitStatus, + status: ExitStatus, }, Compile { compile_error: CompileError<'src>, @@ -53,18 +53,18 @@ pub(crate) enum Error<'src> { config_error: ConfigError, }, Cygpath { - recipe: &'src str, + recipe: &'src str, output_error: OutputError, }, DefaultRecipeRequiresArguments { - recipe: &'src str, + recipe: &'src str, min_arguments: usize, }, Dotenv { dotenv_error: dotenv::Error, }, EditorInvoke { - editor: OsString, + editor: OsString, io_error: io::Error, }, EditorStatus { @@ -72,12 +72,12 @@ pub(crate) enum Error<'src> { status: ExitStatus, }, EvalUnknownVariable { - variable: String, + variable: String, suggestion: Option>, }, FunctionCall { function: Name<'src>, - message: String, + message: String, }, InitExists { justfile: PathBuf, @@ -86,11 +86,11 @@ pub(crate) enum Error<'src> { message: String, }, Io { - recipe: &'src str, + recipe: &'src str, io_error: io::Error, }, Load { - path: PathBuf, + path: PathBuf, io_error: io::Error, }, NoChoosableRecipes, @@ -99,29 +99,29 @@ pub(crate) enum Error<'src> { search_error: SearchError, }, Shebang { - recipe: &'src str, - command: String, + recipe: &'src str, + command: String, argument: Option, io_error: io::Error, }, Signal { - recipe: &'src str, + recipe: &'src str, line_number: Option, - signal: i32, + signal: i32, }, TmpdirIo { - recipe: &'src str, + recipe: &'src str, io_error: io::Error, }, Unknown { - recipe: &'src str, + recipe: &'src str, line_number: Option, }, UnknownOverrides { overrides: Vec, }, UnknownRecipes { - recipes: Vec, + recipes: Vec, suggestion: Option>, }, Unstable { @@ -204,7 +204,7 @@ impl<'src> ColorDisplay for Error<'src> { min, max, .. - } => + } => { if min == max { let expected = min; write!( @@ -234,17 +234,18 @@ impl<'src> ColorDisplay for Error<'src> { Count("argument", *found), max )?; - }, + } + } Backtick { output_error, .. } => match output_error { OutputError::Code(code) => { write!(f, "Backtick failed with exit code {}", code)?; - }, + } OutputError::Signal(signal) => { write!(f, "Backtick was terminated by signal {}", signal)?; - }, + } OutputError::Unknown => { write!(f, "Backtick failed for an unknown reason")?; - }, + } OutputError::Io(io_error) => { match io_error.kind() { io::ErrorKind::NotFound => write!( @@ -263,14 +264,14 @@ impl<'src> ColorDisplay for Error<'src> { io_error ), }?; - }, + } OutputError::Utf8(utf8_error) => { write!( f, "Backtick succeeded but stdout was not utf8: {}", utf8_error )?; - }, + } }, ChooserInvoke { shell_binary, @@ -286,7 +287,7 @@ impl<'src> ColorDisplay for Error<'src> { chooser.to_string_lossy(), io_error, )?; - }, + } ChooserRead { chooser, io_error } => { write!( f, @@ -294,7 +295,7 @@ impl<'src> ColorDisplay for Error<'src> { chooser.to_string_lossy(), io_error )?; - }, + } ChooserStatus { chooser, status } => { write!( f, @@ -302,7 +303,7 @@ impl<'src> ColorDisplay for Error<'src> { chooser.to_string_lossy(), status )?; - }, + } ChooserWrite { chooser, io_error } => { write!( f, @@ -310,12 +311,12 @@ impl<'src> ColorDisplay for Error<'src> { chooser.to_string_lossy(), io_error )?; - }, + } Code { recipe, line_number, code, - } => + } => { if let Some(n) = line_number { write!( f, @@ -324,7 +325,8 @@ impl<'src> ColorDisplay for Error<'src> { )?; } else { write!(f, "Recipe `{}` failed with exit code {}", recipe, code)?; - }, + } + } CommandInvoke { binary, arguments, @@ -340,7 +342,7 @@ impl<'src> ColorDisplay for Error<'src> { .join(" "), io_error, )?; - }, + } CommandStatus { binary, arguments, @@ -356,7 +358,7 @@ impl<'src> ColorDisplay for Error<'src> { .join(" "), status, )?; - }, + } Compile { compile_error } => Display::fmt(compile_error, f)?, Config { config_error } => Display::fmt(config_error, f)?, Cygpath { @@ -370,7 +372,7 @@ impl<'src> ColorDisplay for Error<'src> { path", code, recipe )?; - }, + } OutputError::Signal(signal) => { write!( f, @@ -378,7 +380,7 @@ impl<'src> ColorDisplay for Error<'src> { path", signal, recipe )?; - }, + } OutputError::Unknown => { write!( f, @@ -386,7 +388,7 @@ impl<'src> ColorDisplay for Error<'src> { interpreter path", recipe )?; - }, + } OutputError::Io(io_error) => { match io_error.kind() { io::ErrorKind::NotFound => write!( @@ -403,7 +405,7 @@ impl<'src> ColorDisplay for Error<'src> { ), _ => write!(f, "Could not run `cygpath` executable:\n{}", io_error), }?; - }, + } OutputError::Utf8(utf8_error) => { write!( f, @@ -411,7 +413,7 @@ impl<'src> ColorDisplay for Error<'src> { not utf8: {}", recipe, utf8_error )?; - }, + } }, DefaultRecipeRequiresArguments { recipe, @@ -424,10 +426,10 @@ impl<'src> ColorDisplay for Error<'src> { min_arguments, Count("argument", *min_arguments), )?; - }, + } Dotenv { dotenv_error } => { write!(f, "Failed to load environment file: {}", dotenv_error)?; - }, + } EditorInvoke { editor, io_error } => { write!( f, @@ -435,7 +437,7 @@ impl<'src> ColorDisplay for Error<'src> { editor.to_string_lossy(), io_error )?; - }, + } EditorStatus { editor, status } => { write!( f, @@ -443,7 +445,7 @@ impl<'src> ColorDisplay for Error<'src> { editor.to_string_lossy(), status )?; - }, + } EvalUnknownVariable { variable, suggestion, @@ -452,7 +454,7 @@ impl<'src> ColorDisplay for Error<'src> { if let Some(suggestion) = *suggestion { write!(f, "\n{}", suggestion)?; } - }, + } FunctionCall { function, message } => { write!( f, @@ -460,10 +462,10 @@ impl<'src> ColorDisplay for Error<'src> { function.lexeme(), message )?; - }, + } InitExists { justfile } => { write!(f, "Justfile `{}` already exists", justfile.display())?; - }, + } Internal { message } => { write!( f, @@ -471,7 +473,7 @@ impl<'src> ColorDisplay for Error<'src> { consider filing an issue: https://github.com/casey/just/issues/new", message )?; - }, + } Io { recipe, io_error } => { match io_error.kind() { io::ErrorKind::NotFound => write!( @@ -490,7 +492,7 @@ impl<'src> ColorDisplay for Error<'src> { recipe, io_error ), }?; - }, + } Load { io_error, path } => { write!( f, @@ -498,20 +500,20 @@ impl<'src> ColorDisplay for Error<'src> { path.display(), io_error )?; - }, + } NoChoosableRecipes => { write!(f, "Justfile contains no choosable recipes.")?; - }, + } NoRecipes => { write!(f, "Justfile contains no recipes.")?; - }, + } Search { search_error } => Display::fmt(search_error, f)?, Shebang { recipe, command, argument, io_error, - } => + } => { if let Some(argument) = argument { write!( f, @@ -524,12 +526,13 @@ impl<'src> ColorDisplay for Error<'src> { "Recipe `{}` with shebang `#!{}` execution error: {}", recipe, command, io_error )?; - }, + } + } Signal { recipe, line_number, signal, - } => + } => { if let Some(n) = line_number { write!( f, @@ -538,7 +541,8 @@ impl<'src> ColorDisplay for Error<'src> { )?; } else { write!(f, "Recipe `{}` was terminated by signal {}", recipe, signal)?; - }, + } + } TmpdirIo { recipe, io_error } => write!( f, "Recipe `{}` could not be run because of an IO error while trying to create a temporary \ @@ -548,7 +552,7 @@ impl<'src> ColorDisplay for Error<'src> { Unknown { recipe, line_number, - } => + } => { if let Some(n) = line_number { write!( f, @@ -557,7 +561,8 @@ impl<'src> ColorDisplay for Error<'src> { )?; } else { write!(f, "Recipe `{}` failed for an unknown reason", recipe)?; - }, + } + } UnknownOverrides { overrides } => { write!( f, @@ -565,7 +570,7 @@ impl<'src> ColorDisplay for Error<'src> { Count("Variable", overrides.len()), List::and_ticked(overrides), )?; - }, + } UnknownRecipes { recipes, suggestion, @@ -579,14 +584,14 @@ impl<'src> ColorDisplay for Error<'src> { if let Some(suggestion) = *suggestion { write!(f, "\n{}", suggestion)?; } - }, + } Unstable { message } => { write!( f, "{} Invoke `just` with the `--unstable` flag to enable unstable features.", message )?; - }, + } WriteJustfile { justfile, io_error } => { write!( f, @@ -594,7 +599,7 @@ impl<'src> ColorDisplay for Error<'src> { justfile.display(), io_error )?; - }, + } } write!(f, "{}", color.message().suffix())?; diff --git a/src/evaluator.rs b/src/evaluator.rs index 08fcfb5..a5148cb 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -2,11 +2,11 @@ use crate::common::*; pub(crate) struct Evaluator<'src: 'run, 'run> { assignments: Option<&'run Table<'src, Assignment<'src>>>, - config: &'run Config, - dotenv: &'run BTreeMap, - scope: Scope<'src, 'run>, - settings: &'run Settings<'run>, - search: &'run Search, + config: &'run Config, + dotenv: &'run BTreeMap, + scope: Scope<'src, 'run>, + settings: &'run Settings<'run>, + search: &'run Search, } impl<'src, 'run> Evaluator<'src, 'run> { @@ -64,22 +64,23 @@ impl<'src, 'run> Evaluator<'src, 'run> { message: format!("attempted to evaluate undefined variable `{}`", variable), }) } - }, + } Expression::Call { thunk } => { use Thunk::*; let context = FunctionContext { - dotenv: self.dotenv, + dotenv: self.dotenv, invocation_directory: &self.config.invocation_directory, - search: self.search, + search: self.search, }; match thunk { - Nullary { name, function, .. } => + Nullary { name, function, .. } => { function(&context).map_err(|message| Error::FunctionCall { function: *name, message, - }), + }) + } Unary { name, function, @@ -121,16 +122,18 @@ impl<'src, 'run> Evaluator<'src, 'run> { message, }), } - }, + } Expression::StringLiteral { string_literal } => Ok(string_literal.cooked.clone()), - Expression::Backtick { contents, token } => + Expression::Backtick { contents, token } => { if self.config.dry_run { Ok(format!("`{}`", contents)) } else { Ok(self.run_backtick(contents, token)?) - }, - Expression::Concatination { lhs, rhs } => - Ok(self.evaluate_expression(lhs)? + &self.evaluate_expression(rhs)?), + } + } + Expression::Concatination { lhs, rhs } => { + Ok(self.evaluate_expression(lhs)? + &self.evaluate_expression(rhs)?) + } Expression::Conditional { lhs, rhs, @@ -146,7 +149,7 @@ impl<'src, 'run> Evaluator<'src, 'run> { } else { self.evaluate_expression(otherwise) } - }, + } Expression::Group { contents } => self.evaluate_expression(contents), } } @@ -192,10 +195,10 @@ impl<'src, 'run> Evaluator<'src, 'run> { } else { evaluated += &lexeme; } - }, + } Fragment::Interpolation { expression } => { evaluated += &self.evaluate_expression(expression)?; - }, + } } } Ok(evaluated) diff --git a/src/expression.rs b/src/expression.rs index 67a54e6..71b450a 100644 --- a/src/expression.rs +++ b/src/expression.rs @@ -11,7 +11,7 @@ pub(crate) enum Expression<'src> { /// `contents` Backtick { contents: String, - token: Token<'src>, + token: Token<'src>, }, /// `name(arguments)` Call { thunk: Thunk<'src> }, @@ -22,11 +22,11 @@ pub(crate) enum Expression<'src> { }, /// `if lhs == rhs { then } else { otherwise }` Conditional { - lhs: Box>, - rhs: Box>, - then: Box>, + lhs: Box>, + rhs: Box>, + then: Box>, otherwise: Box>, - inverted: bool, + inverted: bool, }, /// `(contents)` Group { contents: Box> }, diff --git a/src/function_context.rs b/src/function_context.rs index bce0277..3a5a435 100644 --- a/src/function_context.rs +++ b/src/function_context.rs @@ -1,7 +1,7 @@ use crate::common::*; pub(crate) struct FunctionContext<'run> { - pub(crate) dotenv: &'run BTreeMap, + pub(crate) dotenv: &'run BTreeMap, pub(crate) invocation_directory: &'run Path, - pub(crate) search: &'run Search, + pub(crate) search: &'run Search, } diff --git a/src/interrupt_handler.rs b/src/interrupt_handler.rs index acba2dd..a1eb18d 100644 --- a/src/interrupt_handler.rs +++ b/src/interrupt_handler.rs @@ -1,9 +1,9 @@ use crate::common::*; pub(crate) struct InterruptHandler { - blocks: u32, + blocks: u32, interrupted: bool, - verbosity: Verbosity, + verbosity: Verbosity, } impl InterruptHandler { @@ -29,15 +29,15 @@ impl InterruptHandler { .color_display(Color::auto().stderr()) ); std::process::exit(EXIT_FAILURE); - }, + } } } fn new() -> Self { Self { - blocks: 0, + blocks: 0, interrupted: false, - verbosity: Verbosity::default(), + verbosity: Verbosity::default(), } } diff --git a/src/justfile.rs b/src/justfile.rs index 151c4fe..d6f2b3a 100644 --- a/src/justfile.rs +++ b/src/justfile.rs @@ -2,11 +2,11 @@ use crate::common::*; #[derive(Debug, PartialEq)] pub(crate) struct Justfile<'src> { - pub(crate) recipes: Table<'src, Rc>>, + pub(crate) recipes: Table<'src, Rc>>, pub(crate) assignments: Table<'src, Assignment<'src>>, - pub(crate) aliases: Table<'src, Alias<'src>>, - pub(crate) settings: Settings<'src>, - pub(crate) warnings: Vec, + pub(crate) aliases: Table<'src, Alias<'src>>, + pub(crate) settings: Settings<'src>, + pub(crate) warnings: Vec, } impl<'src> Justfile<'src> { @@ -33,16 +33,19 @@ impl<'src> Justfile<'src> { .recipes .keys() .map(|name| { - (edit_distance(name, input), Suggestion { - name, - target: None, - }) + ( + edit_distance(name, input), + Suggestion { name, target: None }, + ) }) .chain(self.aliases.iter().map(|(name, alias)| { - (edit_distance(name, input), Suggestion { - name, - target: Some(alias.target.name.lexeme()), - }) + ( + edit_distance(name, input), + Suggestion { + name, + target: Some(alias.target.name.lexeme()), + }, + ) })) .filter(|(distance, _suggestion)| distance < &3) .collect::>(); @@ -59,10 +62,10 @@ impl<'src> Justfile<'src> { .assignments .keys() .map(|name| { - (edit_distance(name, input), Suggestion { - name, - target: None, - }) + ( + edit_distance(name, input), + Suggestion { name, target: None }, + ) }) .filter(|(distance, _suggestion)| distance < &3) .collect::>(); @@ -168,7 +171,7 @@ impl<'src> Justfile<'src> { }; return Ok(()); - }, + } Subcommand::Evaluate { variable, .. } => { if let Some(variable) = variable { if let Some(value) = scope.value(variable) { @@ -176,7 +179,7 @@ impl<'src> Justfile<'src> { } else { return Err(Error::EvalUnknownVariable { suggestion: self.suggest_variable(&variable), - variable: variable.clone(), + variable: variable.clone(), }); } } else { @@ -197,8 +200,8 @@ impl<'src> Justfile<'src> { } return Ok(()); - }, - _ => {}, + } + _ => {} } let argvec: Vec<&str> = if !arguments.is_empty() { @@ -231,11 +234,11 @@ impl<'src> Justfile<'src> { let argument_count = cmp::min(tail.len(), recipe.max_arguments()); if !argument_range.range_contains(&argument_count) { return Err(Error::ArgumentCountMismatch { - recipe: recipe.name(), + recipe: recipe.name(), parameters: recipe.parameters.clone(), - found: tail.len(), - min: recipe.min_arguments(), - max: recipe.max_arguments(), + found: tail.len(), + min: recipe.min_arguments(), + max: recipe.max_arguments(), }); } grouped.push((recipe, &tail[0..argument_count])); diff --git a/src/lexer.rs b/src/lexer.rs index f68cf65..fee5411 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -13,27 +13,27 @@ use TokenKind::*; /// bad. pub(crate) struct Lexer<'src> { /// Source text - src: &'src str, + src: &'src str, /// Char iterator - chars: Chars<'src>, + chars: Chars<'src>, /// Tokens - tokens: Vec>, + tokens: Vec>, /// Current token start - token_start: Position, + token_start: Position, /// Current token end - token_end: Position, + token_end: Position, /// Next character to be lexed - next: Option, + next: Option, /// Next indent will start a recipe body recipe_body_pending: bool, /// Inside recipe body - recipe_body: bool, + recipe_body: bool, /// Indentation stack - indentation: Vec<&'src str>, + indentation: Vec<&'src str>, /// Interpolation token start stack interpolation_stack: Vec>, /// Current open delimiters - open_delimiters: Vec<(Delimiter, usize)>, + open_delimiters: Vec<(Delimiter, usize)>, } impl<'src> Lexer<'src> { @@ -50,7 +50,7 @@ impl<'src> Lexer<'src> { let start = Position { offset: 0, column: 0, - line: 0, + line: 0, }; Lexer { @@ -86,7 +86,7 @@ impl<'src> Lexer<'src> { self.next = self.chars.next(); Ok(()) - }, + } None => Err(self.internal_error("Lexer advanced past end of text")), } } @@ -202,12 +202,12 @@ impl<'src> Lexer<'src> { fn internal_error(&self, message: impl Into) -> CompileError<'src> { // Use `self.token_end` as the location of the error let token = Token { - src: self.src, + src: self.src, offset: self.token_end.offset, - line: self.token_end.line, + line: self.token_end.line, column: self.token_end.column, length: 0, - kind: Unspecified, + kind: Unspecified, }; CompileError { kind: CompileErrorKind::Internal { @@ -226,11 +226,12 @@ impl<'src> Lexer<'src> { UnterminatedString | UnterminatedBacktick => { let kind = match StringKind::from_token_start(self.lexeme()) { Some(kind) => kind, - None => - return self.internal_error("Lexer::error: expected string or backtick token start"), + None => { + return self.internal_error("Lexer::error: expected string or backtick token start") + } }; kind.delimiter().len() - }, + } // highlight the full token _ => self.lexeme().len(), }; @@ -250,7 +251,7 @@ impl<'src> Lexer<'src> { fn unterminated_interpolation_error(interpolation_start: Token<'src>) -> CompileError<'src> { CompileError { token: interpolation_start, - kind: UnterminatedInterpolation, + kind: UnterminatedInterpolation, } } @@ -304,7 +305,7 @@ impl<'src> Lexer<'src> { } else { self.lex_normal(first)?; }; - }, + } None => break, } } @@ -411,7 +412,7 @@ impl<'src> Lexer<'src> { }; Ok(()) - }, + } Continue => { if !self.indentation().is_empty() { for _ in self.indentation().chars() { @@ -422,7 +423,7 @@ impl<'src> Lexer<'src> { } Ok(()) - }, + } Decrease => { while self.indentation() != whitespace { self.lex_dedent(); @@ -437,14 +438,14 @@ impl<'src> Lexer<'src> { } Ok(()) - }, + } Mixed { whitespace } => { for _ in whitespace.chars() { self.advance()?; } Err(self.error(MixedLeadingWhitespace { whitespace })) - }, + } Inconsistent => { for _ in whitespace.chars() { self.advance()?; @@ -452,9 +453,9 @@ impl<'src> Lexer<'src> { Err(self.error(InconsistentLeadingWhitespace { expected: self.indentation(), - found: whitespace, + found: whitespace, })) - }, + } Increase => { while self.next_is_whitespace() { self.advance()?; @@ -472,7 +473,7 @@ impl<'src> Lexer<'src> { } Ok(()) - }, + } } } @@ -504,7 +505,7 @@ impl<'src> Lexer<'src> { _ => { self.advance()?; Err(self.error(UnknownStartOfToken)) - }, + } } } @@ -585,7 +586,7 @@ impl<'src> Lexer<'src> { .interpolation_stack .push(self.tokens[self.tokens.len() - 1]); Ok(()) - }, + } EndOfFile => Ok(()), } } @@ -644,11 +645,12 @@ impl<'src> Lexer<'src> { BracketR => self.close_delimiter(Bracket)?, ParenL => self.open_delimiter(Paren), ParenR => self.close_delimiter(Paren)?, - _ => + _ => { return Err(self.internal_error(format!( "Lexer::lex_delimiter called with non-delimiter token: `{}`", kind, - ))), + ))) + } } // Emit the delimiter token @@ -947,8 +949,9 @@ mod tests { Dedent | Eof => "", // Variable lexemes - Text | StringToken | Backtick | Identifier | Comment | Unspecified => - panic!("Token {:?} has no default lexeme", kind), + Text | StringToken | Backtick | Identifier | Comment | Unspecified => { + panic!("Token {:?} has no default lexeme", kind) + } } } @@ -992,7 +995,7 @@ mod tests { kind, }; assert_eq!(have, want); - }, + } } } diff --git a/src/list.rs b/src/list.rs index f2466ea..36da9bc 100644 --- a/src/list.rs +++ b/src/list.rs @@ -5,21 +5,21 @@ use crate::common::*; pub struct List + Clone> { conjunction: &'static str, - values: I, + values: I, } impl + Clone> List { pub fn or>(values: II) -> List { List { conjunction: "or", - values: values.into_iter(), + values: values.into_iter(), } } pub fn and>(values: II) -> List { List { conjunction: "and", - values: values.into_iter(), + values: values.into_iter(), } } @@ -68,11 +68,11 @@ impl + Clone> Display for List { write!(f, ", {}", c)?; current = Some(n); next = values.next(); - }, + } (Some(c), None) => { write!(f, ", {} {}", self.conjunction, c)?; return Ok(()); - }, + } _ => unreachable!("Iterator was fused, but returned Some after None"), } } diff --git a/src/name.rs b/src/name.rs index 935c132..4f8c4f6 100644 --- a/src/name.rs +++ b/src/name.rs @@ -6,9 +6,9 @@ use crate::common::*; pub(crate) struct Name<'src> { pub(crate) offset: usize, pub(crate) length: usize, - pub(crate) line: usize, + pub(crate) line: usize, pub(crate) column: usize, - pub(crate) src: &'src str, + pub(crate) src: &'src str, } impl<'src> Name<'src> { @@ -20,12 +20,12 @@ impl<'src> Name<'src> { /// Turn this name back into a token pub(crate) fn token(&self) -> Token<'src> { Token { - kind: TokenKind::Identifier, + kind: TokenKind::Identifier, offset: self.offset, length: self.length, - line: self.line, + line: self.line, column: self.column, - src: self.src, + src: self.src, } } @@ -34,9 +34,9 @@ impl<'src> Name<'src> { Name { offset: token.offset, length: token.length, - line: token.line, + line: token.line, column: token.column, - src: token.src, + src: token.src, } } diff --git a/src/node.rs b/src/node.rs index 2c4114c..7988184 100644 --- a/src/node.rs +++ b/src/node.rs @@ -71,7 +71,7 @@ impl<'src> Node<'src> for Expression<'src> { tree.push_mut(then.tree()); tree.push_mut(otherwise.tree()); tree - }, + } Expression::Call { thunk } => { use Thunk::*; @@ -82,14 +82,14 @@ impl<'src> Node<'src> for Expression<'src> { Unary { name, arg, .. } => { tree.push_mut(name.lexeme()); tree.push_mut(arg.tree()); - }, + } Binary { name, args: [a, b], .. } => { tree.push_mut(name.lexeme()); tree.push_mut(a.tree()); tree.push_mut(b.tree()); - }, + } Ternary { name, args: [a, b, c], @@ -99,11 +99,11 @@ impl<'src> Node<'src> for Expression<'src> { tree.push_mut(a.tree()); tree.push_mut(b.tree()); tree.push_mut(c.tree()); - }, + } } tree - }, + } Expression::Variable { name } => Tree::atom(name.lexeme()), Expression::StringLiteral { string_literal: StringLiteral { cooked, .. }, @@ -213,14 +213,15 @@ impl<'src> Node<'src> for Set<'src> { set.push_mut(self.name.lexeme().replace('-', "_")); match &self.value { - DotenvLoad(value) | Export(value) | PositionalArguments(value) => - set.push_mut(value.to_string()), + DotenvLoad(value) | Export(value) | PositionalArguments(value) => { + set.push_mut(value.to_string()); + } Shell(setting::Shell { command, arguments }) => { set.push_mut(Tree::string(&command.cooked)); for argument in arguments { set.push_mut(Tree::string(&argument.cooked)); } - }, + } } set diff --git a/src/output.rs b/src/output.rs index 680284e..8b5e2a3 100644 --- a/src/output.rs +++ b/src/output.rs @@ -28,7 +28,7 @@ pub(crate) fn output(mut command: Command) -> Result { .to_owned(), ), } - }, + } Err(io_error) => Err(OutputError::Io(io_error)), } } diff --git a/src/parameter.rs b/src/parameter.rs index 521392d..506b930 100644 --- a/src/parameter.rs +++ b/src/parameter.rs @@ -4,13 +4,13 @@ use crate::common::*; #[derive(PartialEq, Debug, Clone)] pub(crate) struct Parameter<'src> { /// The parameter name - pub(crate) name: Name<'src>, + pub(crate) name: Name<'src>, /// The kind of parameter - pub(crate) kind: ParameterKind, + pub(crate) kind: ParameterKind, /// An optional default expression pub(crate) default: Option>, /// Export parameter as environment variable - pub(crate) export: bool, + pub(crate) export: bool, } impl<'src> ColorDisplay for Parameter<'src> { diff --git a/src/parser.rs b/src/parser.rs index 74a6486..c6e0224 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -27,9 +27,9 @@ use TokenKind::*; /// contents of the set is printed in the resultant error message. pub(crate) struct Parser<'tokens, 'src> { /// Source tokens - tokens: &'tokens [Token<'src>], + tokens: &'tokens [Token<'src>], /// Index of the next un-parsed token - next: usize, + next: usize, /// Current expected tokens expected: BTreeSet, } @@ -58,7 +58,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { fn unexpected_token(&self) -> CompileResult<'src, CompileError<'src>> { self.error(CompileErrorKind::UnexpectedToken { expected: self.expected.iter().cloned().collect::>(), - found: self.next()?.kind, + found: self.next()?.kind, }) } @@ -101,10 +101,11 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { let mut rest = self.rest(); for kind in kinds { match rest.next() { - Some(token) => + Some(token) => { if token.kind != *kind { return false; - }, + } + } None => return false, } } @@ -322,22 +323,27 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { break; } else if self.next_is(Identifier) { match Keyword::from_lexeme(next.lexeme()) { - Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, Equals]) => - return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)), - Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, ColonEquals]) => - items.push(Item::Alias(self.parse_alias()?)), - Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, Equals]) => - return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)), + Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, Equals]) => { + return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)) + } + Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, ColonEquals]) => { + items.push(Item::Alias(self.parse_alias()?)); + } + Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, Equals]) => { + return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)) + } Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, ColonEquals]) => { self.presume_keyword(Keyword::Export)?; items.push(Item::Assignment(self.parse_assignment(true)?)); - }, + } Some(Keyword::Set) if self.next_are(&[Identifier, Identifier, ColonEquals]) || self.next_are(&[Identifier, Identifier, Eol]) || self.next_are(&[Identifier, Identifier, Eof]) => - items.push(Item::Set(self.parse_set()?)), - _ => + { + items.push(Item::Set(self.parse_set()?)); + } + _ => { if self.next_are(&[Identifier, Equals]) { return Err(self.get(1)?.error(CompileErrorKind::DeprecatedEquals)); } else if self.next_are(&[Identifier, ColonEquals]) { @@ -345,7 +351,8 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { } else { let doc = pop_doc_comment(&mut items, eol_since_last_comment); items.push(Item::Recipe(self.parse_recipe(doc, false)?)); - }, + } + } } } else if self.accepted(At)? { let doc = pop_doc_comment(&mut items, eol_since_last_comment); @@ -516,13 +523,13 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { 'r' => cooked.push('\r'), 't' => cooked.push('\t'), '\\' => cooked.push('\\'), - '\n' => {}, + '\n' => {} '"' => cooked.push('"'), other => { return Err( token.error(CompileErrorKind::InvalidEscapeSequence { character: other }), ); - }, + } } escape = false; } else if c == '\\' { @@ -715,7 +722,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { } else { return Err(identifier.error(CompileErrorKind::ExpectedKeyword { expected: vec![Keyword::True, Keyword::False], - found: identifier.lexeme(), + found: identifier.lexeme(), })); }; @@ -859,7 +866,7 @@ mod tests { kind, }; assert_eq!(have, want); - }, + } } } diff --git a/src/position.rs b/src/position.rs index e169ec6..face629 100644 --- a/src/position.rs +++ b/src/position.rs @@ -3,5 +3,5 @@ pub(crate) struct Position { pub(crate) offset: usize, pub(crate) column: usize, - pub(crate) line: usize, + pub(crate) line: usize, } diff --git a/src/positional.rs b/src/positional.rs index 3e3396b..c9a7a53 100644 --- a/src/positional.rs +++ b/src/positional.rs @@ -29,11 +29,11 @@ use crate::common::*; #[cfg_attr(test, derive(PartialEq, Debug))] pub struct Positional { /// Overrides from values of the form `[a-zA-Z_][a-zA-Z0-9_-]*=.*` - pub overrides: Vec<(String, String)>, + pub overrides: Vec<(String, String)>, /// An argument equal to '.', '..', or ending with `/` pub search_directory: Option, /// Everything else - pub arguments: Vec, + pub arguments: Vec, } impl Positional { diff --git a/src/recipe.rs b/src/recipe.rs index 72e4886..d909915 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -21,15 +21,15 @@ fn error_from_signal(recipe: &str, line_number: Option, exit_status: Exit /// A recipe, e.g. `foo: bar baz` #[derive(PartialEq, Debug, Clone)] pub(crate) struct Recipe<'src, D = Dependency<'src>> { - pub(crate) body: Vec>, + pub(crate) body: Vec>, pub(crate) dependencies: Vec, - pub(crate) doc: Option<&'src str>, - pub(crate) name: Name<'src>, - pub(crate) parameters: Vec>, - pub(crate) private: bool, - pub(crate) quiet: bool, - pub(crate) shebang: bool, - pub(crate) priors: usize, + pub(crate) doc: Option<&'src str>, + pub(crate) name: Name<'src>, + pub(crate) parameters: Vec>, + pub(crate) private: bool, + pub(crate) quiet: bool, + pub(crate) shebang: bool, + pub(crate) priors: usize, } impl<'src, D> Recipe<'src, D> { @@ -116,7 +116,7 @@ impl<'src, D> Recipe<'src, D> { .prefix("just") .tempdir() .map_err(|error| Error::TmpdirIo { - recipe: self.name(), + recipe: self.name(), io_error: error, })?; let mut path = tmp.path().to_path_buf(); @@ -125,7 +125,7 @@ impl<'src, D> Recipe<'src, D> { { let mut f = fs::File::create(&path).map_err(|error| Error::TmpdirIo { - recipe: self.name(), + recipe: self.name(), io_error: error, })?; let mut text = String::new(); @@ -153,14 +153,14 @@ impl<'src, D> Recipe<'src, D> { f.write_all(text.as_bytes()) .map_err(|error| Error::TmpdirIo { - recipe: self.name(), + recipe: self.name(), io_error: error, })?; } // make the script executable Platform::set_execute_permission(&path).map_err(|error| Error::TmpdirIo { - recipe: self.name(), + recipe: self.name(), io_error: error, })?; @@ -181,7 +181,7 @@ impl<'src, D> Recipe<'src, D> { // run it! match InterruptHandler::guard(|| command.status()) { - Ok(exit_status) => + Ok(exit_status) => { if let Some(code) = exit_status.code() { if code != 0 { return Err(Error::Code { @@ -192,7 +192,8 @@ impl<'src, D> Recipe<'src, D> { } } else { return Err(error_from_signal(self.name(), None, exit_status)); - }, + } + } Err(io_error) => { return Err(Error::Shebang { recipe: self.name(), @@ -200,7 +201,7 @@ impl<'src, D> Recipe<'src, D> { argument: shebang.argument.map(String::from), io_error, }); - }, + } }; } else { let mut lines = self.body.iter().peekable(); @@ -274,7 +275,7 @@ impl<'src, D> Recipe<'src, D> { cmd.export(context.settings, dotenv, &scope); match InterruptHandler::guard(|| cmd.status()) { - Ok(exit_status) => + Ok(exit_status) => { if let Some(code) = exit_status.code() { if code != 0 && !infallable_command { return Err(Error::Code { @@ -289,13 +290,14 @@ impl<'src, D> Recipe<'src, D> { Some(line_number), exit_status, )); - }, + } + } Err(io_error) => { return Err(Error::Io { recipe: self.name(), io_error, }); - }, + } }; } } diff --git a/src/recipe_context.rs b/src/recipe_context.rs index 7cacfe7..0c0dc34 100644 --- a/src/recipe_context.rs +++ b/src/recipe_context.rs @@ -1,8 +1,8 @@ use crate::common::*; pub(crate) struct RecipeContext<'src: 'run, 'run> { - pub(crate) config: &'run Config, - pub(crate) scope: Scope<'src, 'run>, - pub(crate) search: &'run Search, + pub(crate) config: &'run Config, + pub(crate) scope: Scope<'src, 'run>, + pub(crate) search: &'run Search, pub(crate) settings: &'run Settings<'src>, } diff --git a/src/recipe_resolver.rs b/src/recipe_resolver.rs index bb8215b..7e8a83a 100644 --- a/src/recipe_resolver.rs +++ b/src/recipe_resolver.rs @@ -4,8 +4,8 @@ use CompileErrorKind::*; pub(crate) struct RecipeResolver<'src: 'run, 'run> { unresolved_recipes: Table<'src, UnresolvedRecipe<'src>>, - resolved_recipes: Table<'src, Rc>>, - assignments: &'run Table<'src, Assignment<'src>>, + resolved_recipes: Table<'src, Rc>>, + assignments: &'run Table<'src, Assignment<'src>>, } impl<'src: 'run, 'run> RecipeResolver<'src, 'run> { @@ -107,7 +107,7 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> { } else { // dependency is unknown return Err(dependency.recipe.error(UnknownDependency { - recipe: recipe.name(), + recipe: recipe.name(), unknown: name, })); } diff --git a/src/scope.rs b/src/scope.rs index 5785d5d..9bf6a8f 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -2,21 +2,21 @@ use crate::common::*; #[derive(Debug)] pub(crate) struct Scope<'src: 'run, 'run> { - parent: Option<&'run Scope<'src, 'run>>, + parent: Option<&'run Scope<'src, 'run>>, bindings: Table<'src, Binding<'src, String>>, } impl<'src, 'run> Scope<'src, 'run> { pub(crate) fn child(&'run self) -> Scope<'src, 'run> { Scope { - parent: Some(self), + parent: Some(self), bindings: Table::new(), } } pub(crate) fn new() -> Scope<'src, 'run> { Scope { - parent: None, + parent: None, bindings: Table::new(), } } diff --git a/src/search.rs b/src/search.rs index c1ae20d..899c489 100644 --- a/src/search.rs +++ b/src/search.rs @@ -7,7 +7,7 @@ const JUSTFILE_NAMES: &[&str] = &["justfile", ".justfile"]; const PROJECT_ROOT_CHILDREN: &[&str] = &[".bzr", ".git", ".hg", ".svn", "_darcs"]; pub(crate) struct Search { - pub(crate) justfile: PathBuf, + pub(crate) justfile: PathBuf, pub(crate) working_directory: PathBuf, } @@ -26,7 +26,7 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::FromSearchDirectory { search_directory } => { let search_directory = Self::clean(invocation_directory, search_directory); @@ -39,7 +39,7 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::WithJustfile { justfile } => { let justfile = Self::clean(invocation_directory, justfile); @@ -50,13 +50,13 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::WithJustfileAndWorkingDirectory { justfile, working_directory, } => Ok(Self { - justfile: Self::clean(invocation_directory, justfile), + justfile: Self::clean(invocation_directory, justfile), working_directory: Self::clean(invocation_directory, working_directory), }), } @@ -76,7 +76,7 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::FromSearchDirectory { search_directory } => { let search_directory = Self::clean(invocation_directory, search_directory); @@ -89,7 +89,7 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::WithJustfile { justfile } => { let justfile = Self::clean(invocation_directory, justfile); @@ -100,13 +100,13 @@ impl Search { justfile, working_directory, }) - }, + } SearchConfig::WithJustfileAndWorkingDirectory { justfile, working_directory, } => Ok(Self { - justfile: Self::clean(invocation_directory, justfile), + justfile: Self::clean(invocation_directory, justfile), working_directory: Self::clean(invocation_directory, working_directory), }), } @@ -206,7 +206,7 @@ mod tests { fn not_found() { let tmp = testing::tempdir(); match Search::justfile(tmp.path()) { - Err(SearchError::NotFound) => {}, + Err(SearchError::NotFound) => {} _ => panic!("No justfile found error was expected"), } } @@ -226,7 +226,7 @@ mod tests { fs::write(&path, "default:\n\techo ok").unwrap(); path.pop(); match Search::justfile(path.as_path()) { - Err(SearchError::MultipleCandidates { .. }) => {}, + Err(SearchError::MultipleCandidates { .. }) => {} _ => panic!("Multiple candidates error was expected"), } } @@ -301,7 +301,7 @@ mod tests { path.pop(); path.push(DEFAULT_JUSTFILE_NAME); assert_eq!(found_path, path); - }, + } Err(err) => panic!("No errors were expected: {}", err), } } diff --git a/src/search_config.rs b/src/search_config.rs index 97f62f9..b9d4f9f 100644 --- a/src/search_config.rs +++ b/src/search_config.rs @@ -14,7 +14,7 @@ pub(crate) enum SearchConfig { WithJustfile { justfile: PathBuf }, /// Use user-specified justfile and working directory. WithJustfileAndWorkingDirectory { - justfile: PathBuf, + justfile: PathBuf, working_directory: PathBuf, }, } diff --git a/src/search_error.rs b/src/search_error.rs index cea46cf..1dfabb2 100644 --- a/src/search_error.rs +++ b/src/search_error.rs @@ -10,7 +10,7 @@ pub(crate) enum SearchError { ))] Io { directory: PathBuf, - io_error: io::Error, + io_error: io::Error, }, #[snafu(display("Justfile path had no parent: {}", path.display()))] JustfileHadNoParent { path: PathBuf }, diff --git a/src/set.rs b/src/set.rs index b72887a..0925b07 100644 --- a/src/set.rs +++ b/src/set.rs @@ -2,7 +2,7 @@ use crate::common::*; #[derive(Debug, Clone)] pub(crate) struct Set<'src> { - pub(crate) name: Name<'src>, + pub(crate) name: Name<'src>, pub(crate) value: Setting<'src>, } diff --git a/src/setting.rs b/src/setting.rs index 8f6b5b0..22e9266 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -10,7 +10,7 @@ pub(crate) enum Setting<'src> { #[derive(Debug, Clone, PartialEq)] pub(crate) struct Shell<'src> { - pub(crate) command: StringLiteral<'src>, + pub(crate) command: StringLiteral<'src>, pub(crate) arguments: Vec>, } diff --git a/src/settings.rs b/src/settings.rs index 8e4e046..afa02b0 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2,19 +2,19 @@ use crate::common::*; #[derive(Debug, PartialEq)] pub(crate) struct Settings<'src> { - pub(crate) dotenv_load: Option, - pub(crate) export: bool, + pub(crate) dotenv_load: Option, + pub(crate) export: bool, pub(crate) positional_arguments: bool, - pub(crate) shell: Option>, + pub(crate) shell: Option>, } impl<'src> Settings<'src> { pub(crate) fn new() -> Settings<'src> { Settings { - dotenv_load: None, - export: false, + dotenv_load: None, + export: false, positional_arguments: false, - shell: None, + shell: None, } } diff --git a/src/shebang.rs b/src/shebang.rs index 29f5330..e98647c 100644 --- a/src/shebang.rs +++ b/src/shebang.rs @@ -1,7 +1,7 @@ #[derive(Copy, Clone)] pub(crate) struct Shebang<'line> { pub(crate) interpreter: &'line str, - pub(crate) argument: Option<&'line str>, + pub(crate) argument: Option<&'line str>, } impl<'line> Shebang<'line> { diff --git a/src/string_kind.rs b/src/string_kind.rs index 04aee7e..07bd23b 100644 --- a/src/string_kind.rs +++ b/src/string_kind.rs @@ -3,7 +3,7 @@ use crate::common::*; #[derive(Debug, PartialEq, Clone, Copy, Ord, PartialOrd, Eq)] pub(crate) struct StringKind { delimiter: StringDelimiter, - indented: bool, + indented: bool, } #[derive(Debug, PartialEq, Clone, Copy, Ord, PartialOrd, Eq)] @@ -57,8 +57,9 @@ impl StringKind { pub(crate) fn unterminated_error_kind(self) -> CompileErrorKind<'static> { match self.delimiter { - StringDelimiter::QuoteDouble | StringDelimiter::QuoteSingle => - CompileErrorKind::UnterminatedString, + StringDelimiter::QuoteDouble | StringDelimiter::QuoteSingle => { + CompileErrorKind::UnterminatedString + } StringDelimiter::Backtick => CompileErrorKind::UnterminatedBacktick, } } diff --git a/src/string_literal.rs b/src/string_literal.rs index 115d3e2..83f7ddd 100644 --- a/src/string_literal.rs +++ b/src/string_literal.rs @@ -2,8 +2,8 @@ use crate::common::*; #[derive(PartialEq, Debug, Clone)] pub(crate) struct StringLiteral<'src> { - pub(crate) kind: StringKind, - pub(crate) raw: &'src str, + pub(crate) kind: StringKind, + pub(crate) raw: &'src str, pub(crate) cooked: String, } diff --git a/src/subcommand.rs b/src/subcommand.rs index b047a90..5acc326 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -7,11 +7,11 @@ pub(crate) enum Subcommand { Changelog, Choose { overrides: BTreeMap, - chooser: Option, + chooser: Option, }, Command { arguments: Vec, - binary: OsString, + binary: OsString, overrides: BTreeMap, }, Completions { @@ -21,7 +21,7 @@ pub(crate) enum Subcommand { Edit, Evaluate { overrides: BTreeMap, - variable: Option, + variable: Option, }, Format, Init, @@ -45,10 +45,10 @@ impl Subcommand { Changelog => { Self::changelog(); return Ok(()); - }, + } Completions { shell } => return Self::completions(&shell), Init => return Self::init(config), - _ => {}, + _ => {} } let search = Search::find(&config.search_config, &config.invocation_directory)?; @@ -70,8 +70,9 @@ impl Subcommand { } match self { - Choose { overrides, chooser } => - Self::choose(config, justfile, &search, overrides, chooser.as_deref())?, + Choose { overrides, chooser } => { + Self::choose(config, justfile, &search, overrides, chooser.as_deref())?; + } Command { overrides, .. } => justfile.run(config, &search, overrides, &[])?, Dump => Self::dump(ast), Evaluate { overrides, .. } => justfile.run(config, &search, overrides, &[])?, @@ -135,7 +136,7 @@ impl Subcommand { chooser, io_error, }); - }, + } }; for recipe in recipes { @@ -153,7 +154,7 @@ impl Subcommand { Ok(output) => output, Err(io_error) => { return Err(Error::ChooserRead { io_error, chooser }); - }, + } }; if !output.status.success() { @@ -200,23 +201,26 @@ impl Subcommand { let mut script = String::from_utf8(buffer).expect("Clap completion not UTF-8"); match shell { - Shell::Bash => + Shell::Bash => { for (needle, replacement) in completions::BASH_COMPLETION_REPLACEMENTS { replace(&mut script, needle, replacement)?; - }, + } + } Shell::Fish => { script.insert_str(0, completions::FISH_RECIPE_COMPLETIONS); - }, - Shell::PowerShell => + } + Shell::PowerShell => { for (needle, replacement) in completions::POWERSHELL_COMPLETION_REPLACEMENTS { replace(&mut script, needle, replacement)?; - }, + } + } - Shell::Zsh => + Shell::Zsh => { for (needle, replacement) in completions::ZSH_COMPLETION_REPLACEMENTS { replace(&mut script, needle, replacement)?; - }, - Shell::Elvish => {}, + } + } + Shell::Elvish => {} } println!("{}", script.trim()); @@ -363,7 +367,7 @@ impl Subcommand { _ => { let alias_doc = format!("alias for `{}`", recipe.name); print_doc(&alias_doc); - }, + } } println!(); } @@ -381,7 +385,7 @@ impl Subcommand { Ok(()) } else { Err(Error::UnknownRecipes { - recipes: vec![name.to_owned()], + recipes: vec![name.to_owned()], suggestion: justfile.suggest_recipe(name), }) } diff --git a/src/suggestion.rs b/src/suggestion.rs index cb5d9d6..41eeced 100644 --- a/src/suggestion.rs +++ b/src/suggestion.rs @@ -2,7 +2,7 @@ use crate::common::*; #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct Suggestion<'src> { - pub(crate) name: &'src str, + pub(crate) name: &'src str, pub(crate) target: Option<&'src str>, } diff --git a/src/summary.rs b/src/summary.rs index fbee456..66be847 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -36,7 +36,7 @@ pub fn summary(path: &Path) -> Result, io::Error> { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub struct Summary { pub assignments: BTreeMap, - pub recipes: BTreeMap, + pub recipes: BTreeMap, } impl Summary { @@ -51,7 +51,7 @@ impl Summary { } Summary { - recipes: justfile + recipes: justfile .recipes .into_iter() .map(|(name, recipe)| { @@ -72,13 +72,13 @@ impl Summary { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub struct Recipe { - pub aliases: Vec, + pub aliases: Vec, pub dependencies: Vec, - pub lines: Vec, - pub private: bool, - pub quiet: bool, - pub shebang: bool, - pub parameters: Vec, + pub lines: Vec, + pub private: bool, + pub quiet: bool, + pub shebang: bool, + pub parameters: Vec, } impl Recipe { @@ -101,16 +101,16 @@ impl Recipe { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub struct Parameter { - pub kind: ParameterKind, - pub name: String, + pub kind: ParameterKind, + pub name: String, pub default: Option, } impl Parameter { fn new(parameter: &full::Parameter) -> Parameter { Parameter { - kind: ParameterKind::new(parameter.kind), - name: parameter.name.lexeme().to_owned(), + kind: ParameterKind::new(parameter.kind), + name: parameter.name.lexeme().to_owned(), default: parameter.default.as_ref().map(Expression::new), } } @@ -167,14 +167,14 @@ impl Fragment { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub struct Assignment { - pub exported: bool, + pub exported: bool, pub expression: Expression, } impl Assignment { fn new(assignment: &full::Assignment) -> Assignment { Assignment { - exported: assignment.export, + exported: assignment.export, expression: Expression::new(&assignment.value), } } @@ -186,7 +186,7 @@ pub enum Expression { command: String, }, Call { - name: String, + name: String, arguments: Vec, }, Concatination { @@ -194,11 +194,11 @@ pub enum Expression { rhs: Box, }, Conditional { - lhs: Box, - rhs: Box, - then: Box, + lhs: Box, + rhs: Box, + then: Box, otherwise: Box, - inverted: bool, + inverted: bool, }, String { text: String, @@ -217,17 +217,17 @@ impl Expression { }, Call { thunk } => match thunk { full::Thunk::Nullary { name, .. } => Expression::Call { - name: name.lexeme().to_owned(), + name: name.lexeme().to_owned(), arguments: Vec::new(), }, full::Thunk::Unary { name, arg, .. } => Expression::Call { - name: name.lexeme().to_owned(), + name: name.lexeme().to_owned(), arguments: vec![Expression::new(arg)], }, full::Thunk::Binary { name, args: [a, b], .. } => Expression::Call { - name: name.lexeme().to_owned(), + name: name.lexeme().to_owned(), arguments: vec![Expression::new(a), Expression::new(b)], }, full::Thunk::Ternary { @@ -235,7 +235,7 @@ impl Expression { args: [a, b, c], .. } => Expression::Call { - name: name.lexeme().to_owned(), + name: name.lexeme().to_owned(), arguments: vec![Expression::new(a), Expression::new(b), Expression::new(c)], }, }, @@ -250,11 +250,11 @@ impl Expression { then, otherwise, } => Expression::Conditional { - lhs: Box::new(Expression::new(lhs)), - rhs: Box::new(Expression::new(rhs)), - then: Box::new(Expression::new(then)), + lhs: Box::new(Expression::new(lhs)), + rhs: Box::new(Expression::new(rhs)), + then: Box::new(Expression::new(then)), otherwise: Box::new(Expression::new(otherwise)), - inverted: *inverted, + inverted: *inverted, }, StringLiteral { string_literal } => Expression::String { text: string_literal.cooked.clone(), @@ -269,14 +269,14 @@ impl Expression { #[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Debug, Clone)] pub struct Dependency { - pub recipe: String, + pub recipe: String, pub arguments: Vec, } impl Dependency { fn new(dependency: &full::Dependency) -> Dependency { Dependency { - recipe: dependency.recipe.name().to_owned(), + recipe: dependency.recipe.name().to_owned(), arguments: dependency.arguments.iter().map(Expression::new).collect(), } } diff --git a/src/testing.rs b/src/testing.rs index d9e4ea4..caeaa1e 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -82,7 +82,7 @@ pub(crate) fn analysis_error( kind, }; assert_eq!(have, want); - }, + } } } diff --git a/src/thunk.rs b/src/thunk.rs index 3a039ca..9cff31f 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -4,27 +4,27 @@ use crate::common::*; #[derivative(Debug, Clone, PartialEq = "feature_allow_slow_enum")] pub(crate) enum Thunk<'src> { Nullary { - name: Name<'src>, + name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] function: fn(&FunctionContext) -> Result, }, Unary { - name: Name<'src>, + name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] function: fn(&FunctionContext, &str) -> Result, - arg: Box>, + arg: Box>, }, Binary { - name: Name<'src>, + name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] function: fn(&FunctionContext, &str, &str) -> Result, - args: [Box>; 2], + args: [Box>; 2], }, Ternary { - name: Name<'src>, + name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] function: fn(&FunctionContext, &str, &str, &str) -> Result, - args: [Box>; 3], + args: [Box>; 3], }, } @@ -52,7 +52,7 @@ impl<'src> Thunk<'src> { args: [a, b], name, }) - }, + } (Function::Ternary(function), 3) => { let c = Box::new(arguments.pop().unwrap()); let b = Box::new(arguments.pop().unwrap()); @@ -62,10 +62,10 @@ impl<'src> Thunk<'src> { args: [a, b, c], name, }) - }, + } _ => Err(name.error(CompileErrorKind::FunctionArgumentCountMismatch { function: name.lexeme(), - found: arguments.len(), + found: arguments.len(), expected: function.argc(), })), } diff --git a/src/token.rs b/src/token.rs index 15d0b07..62190bd 100644 --- a/src/token.rs +++ b/src/token.rs @@ -4,10 +4,10 @@ use crate::common::*; pub(crate) struct Token<'src> { pub(crate) offset: usize, pub(crate) length: usize, - pub(crate) line: usize, + pub(crate) line: usize, pub(crate) column: usize, - pub(crate) src: &'src str, - pub(crate) kind: TokenKind, + pub(crate) src: &'src str, + pub(crate) kind: TokenKind, } impl<'src> Token<'src> { @@ -65,15 +65,16 @@ impl<'src> ColorDisplay for Token<'src> { space_width.max(1), color.suffix() )?; - }, - None => + } + None => { if self.offset != self.src.len() { write!( f, "internal error: Error has invalid line number: {}", line_number )?; - }, + } + } } Ok(()) diff --git a/src/token_kind.rs b/src/token_kind.rs index d76c8f1..8dd45e9 100644 --- a/src/token_kind.rs +++ b/src/token_kind.rs @@ -37,37 +37,41 @@ pub(crate) enum TokenKind { impl Display for TokenKind { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { use TokenKind::*; - write!(f, "{}", match *self { - AmpersandAmpersand => "'&&'", - Asterisk => "'*'", - At => "'@'", - Backtick => "backtick", - BangEquals => "'!='", - BraceL => "'{'", - BraceR => "'}'", - BracketL => "'['", - BracketR => "']'", - Colon => "':'", - ColonEquals => "':='", - Comma => "','", - Comment => "comment", - Dedent => "dedent", - Dollar => "'$'", - Eof => "end of file", - Eol => "end of line", - Equals => "'='", - EqualsEquals => "'=='", - Identifier => "identifier", - Indent => "indent", - InterpolationEnd => "'}}'", - InterpolationStart => "'{{'", - ParenL => "'('", - ParenR => "')'", - Plus => "'+'", - StringToken => "string", - Text => "command text", - Unspecified => "unspecified", - Whitespace => "whitespace", - }) + write!( + f, + "{}", + match *self { + AmpersandAmpersand => "'&&'", + Asterisk => "'*'", + At => "'@'", + Backtick => "backtick", + BangEquals => "'!='", + BraceL => "'{'", + BraceR => "'}'", + BracketL => "'['", + BracketR => "']'", + Colon => "':'", + ColonEquals => "':='", + Comma => "','", + Comment => "comment", + Dedent => "dedent", + Dollar => "'$'", + Eof => "end of file", + Eol => "end of line", + Equals => "'='", + EqualsEquals => "'=='", + Identifier => "identifier", + Indent => "indent", + InterpolationEnd => "'}}'", + InterpolationStart => "'{{'", + ParenL => "'('", + ParenR => "')'", + Plus => "'+'", + StringToken => "string", + Text => "command text", + Unspecified => "unspecified", + Whitespace => "whitespace", + } + ) } } diff --git a/src/tree.rs b/src/tree.rs index cc45f2f..99f67aa 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -92,7 +92,7 @@ impl<'text> Tree<'text> { Tree::List(mut children) => { children.push(tree.into()); Tree::List(children) - }, + } Tree::Atom(text) => Tree::List(vec![Tree::Atom(text), tree.into()]), } } @@ -137,7 +137,7 @@ impl Display for Tree<'_> { } write!(f, ")") - }, + } Tree::Atom(text) => write!(f, "{}", text), } } diff --git a/src/unresolved_dependency.rs b/src/unresolved_dependency.rs index 47f0dea..47a9e9a 100644 --- a/src/unresolved_dependency.rs +++ b/src/unresolved_dependency.rs @@ -2,7 +2,7 @@ use crate::common::*; #[derive(PartialEq, Debug, Clone)] pub(crate) struct UnresolvedDependency<'src> { - pub(crate) recipe: Name<'src>, + pub(crate) recipe: Name<'src>, pub(crate) arguments: Vec>, } diff --git a/src/unresolved_recipe.rs b/src/unresolved_recipe.rs index f08b538..649d8f5 100644 --- a/src/unresolved_recipe.rs +++ b/src/unresolved_recipe.rs @@ -26,9 +26,9 @@ impl<'src> UnresolvedRecipe<'src> { .recipe .error(CompileErrorKind::DependencyArgumentCountMismatch { dependency: unresolved.recipe.lexeme(), - found: unresolved.arguments.len(), - min: resolved.min_arguments(), - max: resolved.max_arguments(), + found: unresolved.arguments.len(), + min: resolved.min_arguments(), + max: resolved.max_arguments(), }), ); } @@ -39,7 +39,7 @@ impl<'src> UnresolvedRecipe<'src> { .into_iter() .zip(resolved) .map(|(unresolved, resolved)| Dependency { - recipe: resolved, + recipe: resolved, arguments: unresolved.arguments, }) .collect(); diff --git a/src/variables.rs b/src/variables.rs index 586d928..87db132 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -31,17 +31,17 @@ impl<'expression, 'src> Iterator for Variables<'expression, 'src> { self.stack.push(then); self.stack.push(otherwise); self.next() - }, + } Some(Expression::Variable { name, .. }) => Some(name.token()), Some(Expression::Concatination { lhs, rhs }) => { self.stack.push(lhs); self.stack.push(rhs); self.next() - }, + } Some(Expression::Group { contents }) => { self.stack.push(contents); self.next() - }, + } } } } diff --git a/src/warning.rs b/src/warning.rs index d55860c..e94b228 100644 --- a/src/warning.rs +++ b/src/warning.rs @@ -41,7 +41,7 @@ adding the following line to your shell rc file: export JUST_SUPPRESS_DOTENV_LOAD_WARNING=1 See https://github.com/casey/just/issues/469 for more details.")?; - }, + } } write!(f, "{}", message.suffix())?;