From 09af9bb5e5be90169488dfbc03c7f16c380f9133 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 16 Sep 2021 17:51:45 +0300 Subject: [PATCH] Change MSRV to 1.46.0 (#968) --- Cargo.lock | 2 -- Cargo.toml | 1 - README.adoc | 4 ++++ rust-toolchain | 2 +- src/config.rs | 5 +---- src/lexer.rs | 13 +++---------- src/lib.rs | 31 +------------------------------ src/load_dotenv.rs | 3 +-- src/parser.rs | 4 ++-- src/positional.rs | 16 +++++++--------- src/recipe.rs | 7 ++----- src/scope.rs | 4 +--- src/search.rs | 8 ++++---- src/setting.rs | 6 +++--- src/shebang.rs | 4 ++-- src/subcommand.rs | 5 +++-- src/table.rs | 7 ++----- src/thunk.rs | 15 +++++++-------- 18 files changed, 44 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7f2d4c..4ade430 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - [[package]] name = "aho-corasick" version = "0.7.18" diff --git a/Cargo.toml b/Cargo.toml index 762030e..a4f4f75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ edition = "2018" autotests = false categories = ["command-line-utilities", "development-tools"] keywords = ["command-line", "task", "runner", "development", "utility"] -resolver = "2" [workspace] members = [".", "bin/ref-type"] diff --git a/README.adoc b/README.adoc index 9f82406..2649759 100644 --- a/README.adoc +++ b/README.adoc @@ -1661,6 +1661,10 @@ https://github.com/casey/janus[Janus] is a tool that collects and analyzes justf Before merging a particularly large or gruesome change, Janus should be run to make sure that nothing breaks. Don't worry about running Janus yourself, Casey will happily run it for you on changes that need it. +=== Minimum Supported Rust Version + +The minimum supported Rust version, or MSRV, can be found in link:rust-toolchain[]. + == Frequently Asked Questions === What are the idiosyncrasies of Make that Just avoids? diff --git a/rust-toolchain b/rust-toolchain index 154cb93..0a3db35 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.52.1 +1.46.0 diff --git a/src/config.rs b/src/config.rs index 43d84e0..eee784e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -466,10 +466,7 @@ impl Config { overrides, } } else if let Some(values) = matches.values_of_os(cmd::COMMAND) { - let mut arguments = values - .into_iter() - .map(OsStr::to_owned) - .collect::>(); + let mut arguments = values.map(OsStr::to_owned).collect::>(); Subcommand::Command { binary: arguments.remove(0), arguments, diff --git a/src/lexer.rs b/src/lexer.rs index fee5411..8890429 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -257,12 +257,7 @@ impl<'src> Lexer<'src> { /// True if `text` could be an identifier pub(crate) fn is_identifier(text: &str) -> bool { - if !text - .chars() - .next() - .map(Self::is_identifier_start) - .unwrap_or(false) - { + if !text.chars().next().map_or(false, Self::is_identifier_start) { return false; } @@ -496,11 +491,9 @@ impl<'src> Lexer<'src> { '}' => self.lex_delimiter(BraceR), '+' => self.lex_single(Plus), '#' => self.lex_comment(), - ' ' => self.lex_whitespace(), + ' ' | '\t' => self.lex_whitespace(), '`' | '"' | '\'' => self.lex_string(), - '\n' => self.lex_eol(), - '\r' => self.lex_eol(), - '\t' => self.lex_whitespace(), + '\n' | '\r' => self.lex_eol(), _ if Self::is_identifier_start(start) => self.lex_identifier(), _ => { self.advance()?; diff --git a/src/lib.rs b/src/lib.rs index 448146c..e0c656c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,43 +1,14 @@ -#![deny(clippy::all, clippy::pedantic, clippy::restriction)] +#![deny(clippy::all, clippy::pedantic)] #![allow( - clippy::blanket_clippy_restriction_lints, - clippy::comparison_chain, - clippy::create_dir, - clippy::default_numeric_fallback, - clippy::else_if_without_else, clippy::enum_glob_use, - clippy::exhaustive_enums, - clippy::exhaustive_structs, - clippy::expect_used, - clippy::filter_map, clippy::if_not_else, - clippy::implicit_return, - clippy::indexing_slicing, - clippy::integer_arithmetic, - clippy::let_underscore_must_use, - clippy::map_unwrap_or, - clippy::match_same_arms, - clippy::missing_docs_in_private_items, clippy::missing_errors_doc, - clippy::missing_inline_in_public_items, clippy::needless_lifetimes, clippy::needless_pass_by_value, clippy::non_ascii_literal, - clippy::option_if_let_else, - clippy::panic, - clippy::panic_in_result_fn, - clippy::pattern_type_mismatch, - clippy::print_stdout, clippy::shadow_unrelated, - clippy::string_add, clippy::struct_excessive_bools, clippy::too_many_lines, - clippy::unnecessary_wraps, - clippy::unreachable, - clippy::unwrap_in_result, - clippy::unwrap_used, - clippy::use_debug, - clippy::wildcard_enum_match_arm, clippy::wildcard_imports )] diff --git a/src/load_dotenv.rs b/src/load_dotenv.rs index c944926..31187e7 100644 --- a/src/load_dotenv.rs +++ b/src/load_dotenv.rs @@ -48,8 +48,7 @@ fn load_from_file( && config.dotenv_filename.is_none() && config.dotenv_path.is_none() && !std::env::var_os("JUST_SUPPRESS_DOTENV_LOAD_WARNING") - .map(|val| val.as_os_str().to_str() == Some("1")) - .unwrap_or(false) + .map_or(false, |val| val.as_os_str().to_str() == Some("1")) { eprintln!( "{}", diff --git a/src/parser.rs b/src/parser.rs index c6e0224..68242ba 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -637,7 +637,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { Ok(Recipe { parameters: positional.into_iter().chain(variadic).collect(), private: name.lexeme().starts_with('_'), - shebang: body.first().map(Line::is_shebang).unwrap_or(false), + shebang: body.first().map_or(false, Line::is_shebang), priors, body, dependencies, @@ -700,7 +700,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { } } - while lines.last().map(Line::is_empty).unwrap_or(false) { + while lines.last().map_or(false, Line::is_empty) { lines.pop(); } diff --git a/src/positional.rs b/src/positional.rs index c9a7a53..0c9d83c 100644 --- a/src/positional.rs +++ b/src/positional.rs @@ -75,17 +75,15 @@ impl Positional { /// Parse an override from a value of the form `NAME=.*`. fn override_from_value(value: &str) -> Option<(String, String)> { - if let Some(equals) = value.find('=') { - let (identifier, equals_value) = value.split_at(equals); + let equals = value.find('=')?; - // exclude `=` from value - let value = &equals_value[1..]; + let (identifier, equals_value) = value.split_at(equals); - if Lexer::is_identifier(identifier) { - Some((identifier.to_owned(), value.to_owned())) - } else { - None - } + // exclude `=` from value + let value = &equals_value[1..]; + + if Lexer::is_identifier(identifier) { + Some((identifier.to_owned(), value.to_owned())) } else { None } diff --git a/src/recipe.rs b/src/recipe.rs index d909915..e8c2f90 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -212,11 +212,8 @@ impl<'src, D> Recipe<'src, D> { } let mut evaluated = String::new(); let mut continued = false; - let quiet_command = lines.peek().map(|line| line.is_quiet()).unwrap_or(false); - let infallable_command = lines - .peek() - .map(|line| line.is_infallable()) - .unwrap_or(false); + let quiet_command = lines.peek().map_or(false, |line| line.is_quiet()); + let infallable_command = lines.peek().map_or(false, |line| line.is_infallable()); loop { if lines.peek().is_none() { break; diff --git a/src/scope.rs b/src/scope.rs index 9bf6a8f..08d8223 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -36,10 +36,8 @@ impl<'src, 'run> Scope<'src, 'run> { pub(crate) fn value(&self, name: &str) -> Option<&str> { if let Some(binding) = self.bindings.get(name) { Some(binding.value.as_ref()) - } else if let Some(parent) = self.parent { - parent.value(name) } else { - None + self.parent?.value(name) } } diff --git a/src/search.rs b/src/search.rs index 899c489..fc654ba 100644 --- a/src/search.rs +++ b/src/search.rs @@ -134,10 +134,10 @@ impl Search { } } - if candidates.len() == 1 { - return Ok(candidates.into_iter().next().unwrap()); - } else if candidates.len() > 1 { - return Err(SearchError::MultipleCandidates { candidates }); + match candidates.len() { + 0 => {} + 1 => return Ok(candidates.into_iter().next().unwrap()), + _ => return Err(SearchError::MultipleCandidates { candidates }), } } diff --git a/src/setting.rs b/src/setting.rs index 22e9266..08fe80c 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -17,9 +17,9 @@ pub(crate) struct Shell<'src> { impl<'src> Display for Setting<'src> { fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { match self { - Setting::DotenvLoad(value) => write!(f, "{}", value), - Setting::Export(value) => write!(f, "{}", value), - Setting::PositionalArguments(value) => write!(f, "{}", value), + Setting::DotenvLoad(value) | Setting::Export(value) | Setting::PositionalArguments(value) => { + write!(f, "{}", value) + } Setting::Shell(shell) => write!(f, "{}", shell), } } diff --git a/src/shebang.rs b/src/shebang.rs index e98647c..c3a05c4 100644 --- a/src/shebang.rs +++ b/src/shebang.rs @@ -33,8 +33,8 @@ impl<'line> Shebang<'line> { fn interpreter_filename(&self) -> &str { self .interpreter - .rsplit_once(|c| matches!(c, '/' | '\\')) - .map(|(_path, filename)| filename) + .split(|c| matches!(c, '/' | '\\')) + .last() .unwrap_or(self.interpreter) } diff --git a/src/subcommand.rs b/src/subcommand.rs index 5acc326..b6e81e3 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -73,9 +73,10 @@ impl Subcommand { Choose { overrides, chooser } => { Self::choose(config, justfile, &search, overrides, chooser.as_deref())?; } - Command { overrides, .. } => justfile.run(config, &search, overrides, &[])?, + Command { overrides, .. } | Evaluate { overrides, .. } => { + justfile.run(config, &search, overrides, &[])? + } Dump => Self::dump(ast), - Evaluate { overrides, .. } => justfile.run(config, &search, overrides, &[])?, Format => Self::format(config, ast, &search)?, List => Self::list(config, justfile), Run { diff --git a/src/table.rs b/src/table.rs index a336f66..31c1242 100644 --- a/src/table.rs +++ b/src/table.rs @@ -43,11 +43,8 @@ impl<'key, V: Keyed<'key>> Table<'key, V> { } pub(crate) fn pop(&mut self) -> Option { - if let Some(key) = self.map.keys().next().copied() { - self.map.remove(key) - } else { - None - } + let key = self.map.keys().next().copied()?; + self.map.remove(key) } pub(crate) fn remove(&mut self, key: &str) -> Option { diff --git a/src/thunk.rs b/src/thunk.rs index 9cff31f..b711f99 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -33,8 +33,11 @@ impl<'src> Thunk<'src> { name: Name<'src>, mut arguments: Vec>, ) -> CompileResult<'src, Thunk<'src>> { - if let Some(function) = crate::function::TABLE.get(&name.lexeme()) { - match (function, arguments.len()) { + crate::function::TABLE.get(&name.lexeme()).map_or( + Err(name.error(CompileErrorKind::UnknownFunction { + function: name.lexeme(), + })), + |function| match (function, arguments.len()) { (Function::Nullary(function), 0) => Ok(Thunk::Nullary { function: *function, name, @@ -68,12 +71,8 @@ impl<'src> Thunk<'src> { found: arguments.len(), expected: function.argc(), })), - } - } else { - Err(name.error(CompileErrorKind::UnknownFunction { - function: name.lexeme(), - })) - } + }, + ) } }