diff --git a/lib/src/repo_path.rs b/lib/src/repo_path.rs index 9249112ce..d32bd822e 100644 --- a/lib/src/repo_path.rs +++ b/lib/src/repo_path.rs @@ -98,7 +98,7 @@ impl RepoPath { Component::Normal(a) => Ok(RepoPathComponent::from(a.to_str().unwrap())), _ => Err(FsPathParseError::InputNotInRepo(input.to_string())), }) - .collect::, _>>()?; + .try_collect()?; Ok(RepoPath::from_components(components)) } diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 439a4b428..12245cab4 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -800,10 +800,10 @@ fn parse_function_expression( // Resolve arguments in the current scope, and pass them in to the alias // expansion scope. let arguments_span = arguments_pair.as_span(); - let args = arguments_pair + let args: Vec<_> = arguments_pair .into_inner() .map(|arg| parse_expression_rule(arg.into_inner(), state)) - .collect::, RevsetParseError>>()?; + .try_collect()?; if params.len() == args.len() { let locals = params.iter().map(|s| s.as_str()).zip(args).collect(); state.with_alias_expanding(id, &locals, primary_span, |state| { @@ -934,9 +934,9 @@ fn parse_builtin_function( "file" => { if let Some(ctx) = state.workspace_ctx { let arguments_span = arguments_pair.as_span(); - let paths = arguments_pair + let paths: Vec<_> = arguments_pair .into_inner() - .map(|arg| { + .map(|arg| -> Result<_, RevsetParseError> { let span = arg.as_span(); let needle = parse_function_argument_to_string(name, arg, state)?; let path = RepoPath::parse_fs_path(ctx.cwd, ctx.workspace_root, &needle) @@ -948,7 +948,7 @@ fn parse_builtin_function( })?; Ok(path) }) - .collect::, RevsetParseError>>()?; + .try_collect()?; if paths.is_empty() { Err(RevsetParseError::with_span( RevsetParseErrorKind::InvalidFunctionArguments { diff --git a/src/cli_util.rs b/src/cli_util.rs index aa6e83447..04440aa01 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -563,10 +563,10 @@ impl WorkspaceCommandHelper { Ok(Box::new(EverythingMatcher)) } else { // TODO: Add support for globs and other formats - let paths = values + let paths: Vec<_> = values .iter() .map(|v| self.parse_file_path(v)) - .collect::, _>>()?; + .try_collect()?; Ok(Box::new(PrefixMatcher::new(&paths))) } } @@ -617,7 +617,7 @@ impl WorkspaceCommandHelper { ))), (Some(commit0), Some(commit1)) => { let mut iter = [commit0, commit1].into_iter().chain(iter); - let commits = iter.by_ref().take(5).collect::, _>>()?; + let commits: Vec<_> = iter.by_ref().take(5).try_collect()?; let elided = iter.next().is_some(); let hint = format!( "The revset resolved to these revisions:\n{commits}{ellipsis}", diff --git a/src/commands.rs b/src/commands.rs index 09ad43ef2..911114084 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -27,7 +27,7 @@ use chrono::{FixedOffset, LocalResult, TimeZone, Utc}; use clap::builder::NonEmptyStringValueParser; use clap::{ArgAction, ArgGroup, ArgMatches, CommandFactory, FromArgMatches, Subcommand}; use itertools::Itertools; -use jujutsu_lib::backend::{BackendError, CommitId, Timestamp, TreeValue}; +use jujutsu_lib::backend::{CommitId, Timestamp, TreeValue}; use jujutsu_lib::commit::Commit; use jujutsu_lib::commit_builder::CommitBuilder; use jujutsu_lib::dag_walk::topo_order_reverse; @@ -2702,18 +2702,18 @@ fn rebase_revision( .parents() .ancestors(), ); - let new_child_parents: Result, BackendError> = workspace_command + let new_child_parents: Vec = workspace_command .evaluate_revset(&new_child_parents_expression) .unwrap() .iter() .commits(store) - .collect(); + .try_collect()?; rebase_commit( ui.settings(), tx.mut_repo(), &child_commit, - &new_child_parents?, + &new_child_parents, ); num_rebased_descendants += 1; } @@ -3472,16 +3472,16 @@ fn cmd_sparse(ui: &mut Ui, command: &CommandHelper, args: &SparseArgs) -> Result } } else { let mut workspace_command = command.workspace_helper(ui)?; - let paths_to_add = args + let paths_to_add: Vec<_> = args .add .iter() .map(|v| workspace_command.parse_file_path(v)) - .collect::, _>>()?; - let paths_to_remove = args + .try_collect()?; + let paths_to_remove: Vec<_> = args .remove .iter() .map(|v| workspace_command.parse_file_path(v)) - .collect::, _>>()?; + .try_collect()?; let (mut locked_wc, _wc_commit) = workspace_command.start_working_copy_mutation()?; let mut new_patterns = HashSet::new(); if args.reset { diff --git a/src/diff_edit.rs b/src/diff_edit.rs index 5b85052a8..059f588d6 100644 --- a/src/diff_edit.rs +++ b/src/diff_edit.rs @@ -212,9 +212,9 @@ pub fn run_mergetool( // The default case below should never actually trigger, but we support it just in case // resolving the root path ever makes sense. .unwrap_or_default(); - let paths: Result, ConflictResolveError> = files + let paths: HashMap<&str, _> = files .iter() - .map(|(role, contents)| { + .map(|(role, contents)| -> Result<_, ConflictResolveError> { let path = temp_dir.path().join(format!("{role}{suffix}")); std::fs::write(&path, contents).map_err(ExternalToolError::SetUpDirError)?; if *role != "output" { @@ -223,8 +223,7 @@ pub fn run_mergetool( } Ok((*role, path)) }) - .collect(); - let paths = paths?; + .try_collect()?; let args = interpolate_mergetool_filename_patterns(&editor.merge_args, &paths); let args_str = args