diff --git a/Cargo.toml b/Cargo.toml index 914fc54acf985..713d65441300f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ members = [ turborepo-libraries = ["path:crates/turborepo-*"] turborepo = ["path:crates/turborepo*"] +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(debug_assert)'] } + [workspace.lints.clippy] too_many_arguments = "allow" diff --git a/crates/turborepo-api-client/src/lib.rs b/crates/turborepo-api-client/src/lib.rs index 996f605dbc64a..db61b70878594 100644 --- a/crates/turborepo-api-client/src/lib.rs +++ b/crates/turborepo-api-client/src/lib.rs @@ -137,7 +137,7 @@ impl std::fmt::Debug for APIAuth { pub fn is_linked(api_auth: &Option) -> bool { api_auth .as_ref() - .map_or(false, |api_auth| api_auth.is_linked()) + .is_some_and(|api_auth| api_auth.is_linked()) } impl Client for APIClient { diff --git a/crates/turborepo-auth/src/auth/sso.rs b/crates/turborepo-auth/src/auth/sso.rs index 2332be67126ea..4b8fca98ead9e 100644 --- a/crates/turborepo-auth/src/auth/sso.rs +++ b/crates/turborepo-auth/src/auth/sso.rs @@ -24,7 +24,7 @@ fn make_token_name() -> Result { /// Perform an SSO login flow. If an existing token is present, and the token /// has access to the provided `sso_team`, we do not overwrite it and instead /// log that we found an existing token. -pub async fn sso_login<'a, T: Client + TokenClient + CacheClient>( +pub async fn sso_login( options: &LoginOptions<'_, T>, ) -> Result { let LoginOptions { diff --git a/crates/turborepo-auth/src/lib.rs b/crates/turborepo-auth/src/lib.rs index 72b34dd423e1e..4fbb99ab25b46 100644 --- a/crates/turborepo-auth/src/lib.rs +++ b/crates/turborepo-auth/src/lib.rs @@ -176,10 +176,10 @@ impl Token { /// Checks if the token has access to the cache. This is a separate check /// from `is_active` because it's possible for a token to be active but not /// have access to the cache. - pub async fn has_cache_access<'a, T: CacheClient>( + pub async fn has_cache_access( &self, client: &T, - team_info: Option>, + team_info: Option>, ) -> Result { let (team_id, team_slug) = match team_info { Some(TeamInfo { id, slug }) => (Some(id), Some(slug)), diff --git a/crates/turborepo-cache/src/http.rs b/crates/turborepo-cache/src/http.rs index ecd522646e278..8e0da47f1b116 100644 --- a/crates/turborepo-cache/src/http.rs +++ b/crates/turborepo-cache/src/http.rs @@ -44,7 +44,7 @@ impl HTTPCache { let signer_verifier = if opts .remote_cache_opts .as_ref() - .map_or(false, |remote_cache_opts| remote_cache_opts.signature) + .is_some_and(|remote_cache_opts| remote_cache_opts.signature) { Some(ArtifactSignatureAuthenticator { team_id: api_auth diff --git a/crates/turborepo-ci/src/lib.rs b/crates/turborepo-ci/src/lib.rs index 6c3be7aaf3a1e..7ee7e9bb28ef4 100644 --- a/crates/turborepo-ci/src/lib.rs +++ b/crates/turborepo-ci/src/lib.rs @@ -92,7 +92,7 @@ impl Vendor { } pub fn is(name: &str) -> bool { - Self::infer().map_or(false, |v| v.name == name) + Self::infer().is_some_and(|v| v.name == name) } pub fn get_constant() -> Option<&'static str> { diff --git a/crates/turborepo-lib/src/boundaries.rs b/crates/turborepo-lib/src/boundaries.rs index c4b012962a732..149fb2de600f7 100644 --- a/crates/turborepo-lib/src/boundaries.rs +++ b/crates/turborepo-lib/src/boundaries.rs @@ -322,31 +322,31 @@ impl Run { package_name: &PackageNode, ) -> bool { internal_dependencies.contains(&package_name) - || unresolved_external_dependencies.map_or(false, |external_dependencies| { + || unresolved_external_dependencies.is_some_and(|external_dependencies| { external_dependencies.contains_key(package_name.as_package_name().as_str()) }) || package_json .dependencies .as_ref() - .map_or(false, |dependencies| { + .is_some_and(|dependencies| { dependencies.contains_key(package_name.as_package_name().as_str()) }) || package_json .dev_dependencies .as_ref() - .map_or(false, |dev_dependencies| { + .is_some_and(|dev_dependencies| { dev_dependencies.contains_key(package_name.as_package_name().as_str()) }) || package_json .peer_dependencies .as_ref() - .map_or(false, |peer_dependencies| { + .is_some_and(|peer_dependencies| { peer_dependencies.contains_key(package_name.as_package_name().as_str()) }) || package_json .optional_dependencies .as_ref() - .map_or(false, |optional_dependencies| { + .is_some_and(|optional_dependencies| { optional_dependencies.contains_key(package_name.as_package_name().as_str()) }) } diff --git a/crates/turborepo-lib/src/commands/link.rs b/crates/turborepo-lib/src/commands/link.rs index 9dec26b2fe4e9..a3dd38eb89823 100644 --- a/crates/turborepo-lib/src/commands/link.rs +++ b/crates/turborepo-lib/src/commands/link.rs @@ -543,7 +543,7 @@ fn add_turbo_to_gitignore(base: &CommandBase) -> Result<(), io::Error> { } else { let gitignore = File::open(&gitignore_path)?; let mut lines = io::BufReader::new(gitignore).lines(); - let has_turbo = lines.any(|line| line.map_or(false, |line| line.trim() == ".turbo")); + let has_turbo = lines.any(|line| line.is_ok_and(|line| line.trim() == ".turbo")); if !has_turbo { let mut gitignore = OpenOptions::new() .read(true) diff --git a/crates/turborepo-lib/src/engine/mod.rs b/crates/turborepo-lib/src/engine/mod.rs index 8440025b13cc2..3817b60ab6e30 100644 --- a/crates/turborepo-lib/src/engine/mod.rs +++ b/crates/turborepo-lib/src/engine/mod.rs @@ -116,7 +116,7 @@ impl Engine { let has_location = self .task_locations .get(&task_id) - .map_or(false, |existing| existing.range.is_some()); + .is_some_and(|existing| existing.range.is_some()); if !has_location { self.task_locations.insert(task_id, location); @@ -196,7 +196,7 @@ impl Engine { .any(|idx| { node_distances .get(&(**idx, node_idx)) - .map_or(false, |dist| *dist != i32::MAX) + .is_some_and(|dist| *dist != i32::MAX) }) .then_some(node.clone()) }, @@ -490,12 +490,12 @@ impl Engine { .scripts .get(task_id.task()) // handle legacy behaviour from go where an empty string may appear - .map_or(false, |script| !script.is_empty()); + .is_some_and(|script| !script.is_empty()); let task_is_persistent = self .task_definitions .get(task_id) - .map_or(false, |task_def| task_def.persistent); + .is_some_and(|task_def| task_def.persistent); Ok(task_is_persistent && package_has_task) }) diff --git a/crates/turborepo-lib/src/framework.rs b/crates/turborepo-lib/src/framework.rs index 385d651e54d40..59d22c51586d8 100644 --- a/crates/turborepo-lib/src/framework.rs +++ b/crates/turborepo-lib/src/framework.rs @@ -61,11 +61,11 @@ impl Matcher { Strategy::All => self .dependencies .iter() - .all(|dep| deps.map_or(false, |deps| deps.contains_key(dep))), + .all(|dep| deps.is_some_and(|deps| deps.contains_key(dep))), Strategy::Some => self .dependencies .iter() - .any(|dep| deps.map_or(false, |deps| deps.contains_key(dep))), + .any(|dep| deps.is_some_and(|deps| deps.contains_key(dep))), } } } diff --git a/crates/turborepo-lib/src/gitignore.rs b/crates/turborepo-lib/src/gitignore.rs index 067b76182b3b0..b6bbcf17ee09a 100644 --- a/crates/turborepo-lib/src/gitignore.rs +++ b/crates/turborepo-lib/src/gitignore.rs @@ -11,7 +11,7 @@ const TURBO_GITIGNORE_ENTRY: &str = ".turbo"; const GITIGNORE_FILE: &str = ".gitignore"; fn has_turbo_gitignore_entry(mut lines: io::Lines>) -> bool { - lines.any(|line| line.map_or(false, |line| line.trim() == TURBO_GITIGNORE_ENTRY)) + lines.any(|line| line.is_ok_and(|line| line.trim() == TURBO_GITIGNORE_ENTRY)) } fn get_ignore_string() -> String { diff --git a/crates/turborepo-lib/src/package_changes_watcher.rs b/crates/turborepo-lib/src/package_changes_watcher.rs index 2cb9857a18767..680bcefe00478 100644 --- a/crates/turborepo-lib/src/package_changes_watcher.rs +++ b/crates/turborepo-lib/src/package_changes_watcher.rs @@ -380,7 +380,7 @@ impl Subscriber { let has_root_tasks = repo_state .root_turbo_json .as_ref() - .map_or(false, |turbo| turbo.has_root_tasks()); + .is_some_and(|turbo| turbo.has_root_tasks()); if !has_root_tasks { filtered_pkgs.remove(&root_pkg); } diff --git a/crates/turborepo-lib/src/query/mod.rs b/crates/turborepo-lib/src/query/mod.rs index c8157249c88ff..fc25100560b78 100644 --- a/crates/turborepo-lib/src/query/mod.rs +++ b/crates/turborepo-lib/src/query/mod.rs @@ -602,7 +602,7 @@ impl RepositoryQuery { .pkg_dep_graph() .packages() .map(|(name, _)| Package::new(self.run.clone(), name.clone())) - .filter(|pkg| pkg.as_ref().map_or(false, |pkg| filter.check(pkg))) + .filter(|pkg| pkg.as_ref().is_ok_and(|pkg| filter.check(pkg))) .collect::, _>>()?; packages.sort_by(|a, b| a.get_name().cmp(b.get_name())); diff --git a/crates/turborepo-lib/src/rewrite_json.rs b/crates/turborepo-lib/src/rewrite_json.rs index 6687909ab12ca..1229951654019 100644 --- a/crates/turborepo-lib/src/rewrite_json.rs +++ b/crates/turborepo-lib/src/rewrite_json.rs @@ -280,7 +280,7 @@ fn find_all_paths<'a>( let should_rewrite = if match_case_sensitive { target_path[0] == current_property_name } else { - target_path[0].to_ascii_lowercase() == current_property_name.to_ascii_lowercase() + target_path[0].eq_ignore_ascii_case(current_property_name) }; if should_rewrite { diff --git a/crates/turborepo-lib/src/run/summary/mod.rs b/crates/turborepo-lib/src/run/summary/mod.rs index 75962ae272bb5..9386226ef990d 100644 --- a/crates/turborepo-lib/src/run/summary/mod.rs +++ b/crates/turborepo-lib/src/run/summary/mod.rs @@ -787,7 +787,7 @@ impl<'a> RunSummary<'a> { task.shared .execution .as_ref() - .map_or(false, |e| e.is_failure()) + .is_some_and(|e| e.is_failure()) }) .collect() } diff --git a/crates/turborepo-lib/src/run/summary/spaces.rs b/crates/turborepo-lib/src/run/summary/spaces.rs index 3616fc5da1aab..559ed7ecfb742 100644 --- a/crates/turborepo-lib/src/run/summary/spaces.rs +++ b/crates/turborepo-lib/src/run/summary/spaces.rs @@ -146,7 +146,7 @@ impl SpacesClient { ) -> Option { // If space_id is empty, we don't build a client let space_id = space_id?; - let is_linked = api_auth.as_ref().map_or(false, |auth| auth.is_linked()); + let is_linked = api_auth.as_ref().is_some_and(|auth| auth.is_linked()); if !is_linked { // TODO: Add back spaces warning with new UI return None; @@ -328,13 +328,13 @@ fn trim_logs(logs: &[u8], limit: usize) -> String { // Go JSON encoding automatically did a lossy conversion for us when // encoding Golang strings into JSON. let lossy_logs = String::from_utf8_lossy(logs); - if lossy_logs.as_bytes().len() <= limit { + if lossy_logs.len() <= limit { lossy_logs.into_owned() } else { // We try to trim down the logs so that it is valid utf8 // We attempt to parse it at every byte starting from the limit until we get a // valid utf8 which means we aren't cutting in the middle of a cluster. - for start_index in (lossy_logs.as_bytes().len() - limit)..lossy_logs.as_bytes().len() { + for start_index in (lossy_logs.len() - limit)..lossy_logs.len() { let log_bytes = &lossy_logs.as_bytes()[start_index..]; if let Ok(log_str) = std::str::from_utf8(log_bytes) { return log_str.to_string(); diff --git a/crates/turborepo-lib/src/task_graph/visitor/command.rs b/crates/turborepo-lib/src/task_graph/visitor/command.rs index 9ba3bd5bf69d8..8bda6e929acbb 100644 --- a/crates/turborepo-lib/src/task_graph/visitor/command.rs +++ b/crates/turborepo-lib/src/task_graph/visitor/command.rs @@ -133,7 +133,7 @@ impl<'a> CommandProvider for PackageGraphCommandProvider<'a> { // task via an env var if self .mfe_configs - .map_or(false, |mfe_configs| mfe_configs.task_has_mfe_proxy(task_id)) + .is_some_and(|mfe_configs| mfe_configs.task_has_mfe_proxy(task_id)) { cmd.env("TURBO_TASK_HAS_MFE_PROXY", "true"); } diff --git a/crates/turborepo-lib/src/turbo_json/mod.rs b/crates/turborepo-lib/src/turbo_json/mod.rs index 51c827a2032d3..5600847d18fca 100644 --- a/crates/turborepo-lib/src/turbo_json/mod.rs +++ b/crates/turborepo-lib/src/turbo_json/mod.rs @@ -263,8 +263,8 @@ impl RawTaskDefinition { pub fn merge(&mut self, other: RawTaskDefinition) { set_field!(self, other, outputs); - let other_has_range = other.cache.as_ref().map_or(false, |c| c.range.is_some()); - let self_does_not_have_range = self.cache.as_ref().map_or(false, |c| c.range.is_none()); + let other_has_range = other.cache.as_ref().is_some_and(|c| c.range.is_some()); + let self_does_not_have_range = self.cache.as_ref().is_some_and(|c| c.range.is_none()); if other.cache.is_some() // If other has range info and we're missing it, carry it over diff --git a/crates/turborepo-lockfiles/src/yarn1/ser.rs b/crates/turborepo-lockfiles/src/yarn1/ser.rs index 377ffa67d9128..a88d58a4f0aa6 100644 --- a/crates/turborepo-lockfiles/src/yarn1/ser.rs +++ b/crates/turborepo-lockfiles/src/yarn1/ser.rs @@ -49,7 +49,7 @@ impl fmt::Display for Yarn1Lockfile { let mut added_keys: HashSet<&str> = HashSet::with_capacity(self.inner.len()); for (key, entry) in self.inner.iter() { let seen_key = seen_keys.get(key.as_str()); - let seen_pattern = seen_key.map_or(false, |key| added_keys.contains(key.as_str())); + let seen_pattern = seen_key.is_some_and(|key| added_keys.contains(key.as_str())); if seen_pattern { continue; } @@ -243,7 +243,7 @@ fn should_wrap_key(s: &str) -> bool { s.starts_with("true") || s.starts_with("false") || // Wrap if it doesn't start with a-zA-Z - s.chars().next().map_or(false, |c| !c.is_ascii_alphabetic()) || + s.chars().next().is_some_and(|c| !c.is_ascii_alphabetic()) || // Wrap if it contains any unwanted chars s.chars().any(|c| matches!( c, diff --git a/crates/turborepo-repository/src/package_graph/builder.rs b/crates/turborepo-repository/src/package_graph/builder.rs index d3ed7bf35c053..486ec934929cd 100644 --- a/crates/turborepo-repository/src/package_graph/builder.rs +++ b/crates/turborepo-repository/src/package_graph/builder.rs @@ -119,7 +119,7 @@ impl<'a, P> PackageGraphBuilder<'a, P> { } } -impl<'a, T> PackageGraphBuilder<'a, T> +impl PackageGraphBuilder<'_, T> where T: PackageDiscoveryBuilder, T::Output: Send + Sync, @@ -469,7 +469,7 @@ impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedWorkspaces, T> { } } -impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedLockfile, T> { +impl BuildState<'_, ResolvedLockfile, T> { fn all_external_dependencies(&self) -> Result>, Error> { self.workspaces .values() diff --git a/crates/turborepo-repository/src/package_graph/dep_splitter.rs b/crates/turborepo-repository/src/package_graph/dep_splitter.rs index 03ae1aba7f70c..5148dff8f56ca 100644 --- a/crates/turborepo-repository/src/package_graph/dep_splitter.rs +++ b/crates/turborepo-repository/src/package_graph/dep_splitter.rs @@ -143,7 +143,7 @@ impl<'a> DependencyVersion<'a> { // behavior before this additional logic was added. // TODO: extend this to support the `enableTransparentWorkspaces` yarn option - self.protocol.map_or(false, |p| p != "npm") + self.protocol.is_some_and(|p| p != "npm") } fn matches_workspace_package( diff --git a/crates/turborepo-ui/src/tui/app.rs b/crates/turborepo-ui/src/tui/app.rs index 9332fb5ed2e87..6ce582120167d 100644 --- a/crates/turborepo-ui/src/tui/app.rs +++ b/crates/turborepo-ui/src/tui/app.rs @@ -681,8 +681,8 @@ async fn run_app_inner( /// Blocking poll for events, will only return None if app handle has been /// dropped -async fn poll<'a>( - input_options: InputOptions<'a>, +async fn poll( + input_options: InputOptions<'_>, receiver: &mut AppReceiver, crossterm_rx: &mut mpsc::Receiver, ) -> Option { diff --git a/crates/turborepo-ui/src/tui/debouncer.rs b/crates/turborepo-ui/src/tui/debouncer.rs index 955fd77e28b18..23ceb7ecee570 100644 --- a/crates/turborepo-ui/src/tui/debouncer.rs +++ b/crates/turborepo-ui/src/tui/debouncer.rs @@ -23,7 +23,7 @@ impl Debouncer { pub fn query(&mut self) -> Option { if self .start - .map_or(false, |start| start.elapsed() >= self.duration) + .is_some_and(|start| start.elapsed() >= self.duration) { self.start = None; self.value.take() diff --git a/crates/turborepo-ui/src/tui/term_output.rs b/crates/turborepo-ui/src/tui/term_output.rs index 42966f1456a3b..be5d1d6c00d3e 100644 --- a/crates/turborepo-ui/src/tui/term_output.rs +++ b/crates/turborepo-ui/src/tui/term_output.rs @@ -129,7 +129,7 @@ impl TerminalOutput { self.parser .screen() .selected_text() - .map_or(false, |s| !s.is_empty()) + .is_some_and(|s| !s.is_empty()) } pub fn handle_mouse(&mut self, event: crossterm::event::MouseEvent) -> Result<(), Error> { diff --git a/crates/turborepo-ui/src/wui/query.rs b/crates/turborepo-ui/src/wui/query.rs index 51b4a6053db3f..9a2ebfef63c70 100644 --- a/crates/turborepo-ui/src/wui/query.rs +++ b/crates/turborepo-ui/src/wui/query.rs @@ -17,7 +17,7 @@ struct CurrentRun<'a> { } #[Object] -impl<'a> CurrentRun<'a> { +impl CurrentRun<'_> { async fn tasks(&self) -> Vec { self.state .lock() diff --git a/crates/turborepo-vt100/src/screen.rs b/crates/turborepo-vt100/src/screen.rs index a7ed3f8efc23e..29ecb76cd022e 100644 --- a/crates/turborepo-vt100/src/screen.rs +++ b/crates/turborepo-vt100/src/screen.rs @@ -698,7 +698,7 @@ impl Screen { pub fn row_wrapped(&self, row: u16) -> bool { self.grid() .visible_row(row) - .map_or(false, crate::row::Row::wrapped) + .is_some_and(crate::row::Row::wrapped) } /// Returns the terminal's window title. diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 780177141c9aa..9800beb9da529 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-10-11" +channel = "nightly-2024-11-22" components = ["rustfmt", "clippy"] profile = "minimal"