Skip to content

Commit

Permalink
chore: upgrade to Rust 1.84.0 (#9766)
Browse files Browse the repository at this point in the history
### Description

- map_or -> is_some_and in case of bool operations
- add `[workspace.lints.rust]` to ignore `cfg(debug_assertion)` warning

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
ognevny authored Jan 24, 2025
1 parent bca3f44 commit b066773
Show file tree
Hide file tree
Showing 27 changed files with 44 additions and 41 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl std::fmt::Debug for APIAuth {
pub fn is_linked(api_auth: &Option<APIAuth>) -> 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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-auth/src/auth/sso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn make_token_name() -> Result<String, Error> {
/// 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<T: Client + TokenClient + CacheClient>(
options: &LoginOptions<'_, T>,
) -> Result<Token, Error> {
let LoginOptions {
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: CacheClient>(
&self,
client: &T,
team_info: Option<TeamInfo<'a>>,
team_info: Option<TeamInfo<'_>>,
) -> Result<bool, Error> {
let (team_id, team_slug) = match team_info {
Some(TeamInfo { id, slug }) => (Some(id), Some(slug)),
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-cache/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
10 changes: 5 additions & 5 deletions crates/turborepo-lib/src/boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions crates/turborepo-lib/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Engine<Building> {
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);
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Engine<Built> {
.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())
},
Expand Down Expand Up @@ -490,12 +490,12 @@ impl Engine<Built> {
.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)
})
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/gitignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TURBO_GITIGNORE_ENTRY: &str = ".turbo";
const GITIGNORE_FILE: &str = ".gitignore";

fn has_turbo_gitignore_entry(mut lines: io::Lines<io::BufReader<File>>) -> 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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/package_changes_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Array<_>, _>>()?;
packages.sort_by(|a, b| a.get_name().cmp(b.get_name()));

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/rewrite_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-lib/src/run/summary/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl SpacesClient {
) -> Option<Self> {
// 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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/task_graph/visitor/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lockfiles/src/yarn1/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-repository/src/package_graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a, P> PackageGraphBuilder<'a, P> {
}
}

impl<'a, T> PackageGraphBuilder<'a, T>
impl<T> PackageGraphBuilder<'_, T>
where
T: PackageDiscoveryBuilder,
T::Output: Send + Sync,
Expand Down Expand Up @@ -469,7 +469,7 @@ impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedWorkspaces, T> {
}
}

impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedLockfile, T> {
impl<T: PackageDiscovery> BuildState<'_, ResolvedLockfile, T> {
fn all_external_dependencies(&self) -> Result<HashMap<String, HashMap<String, String>>, Error> {
self.workspaces
.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ async fn run_app_inner<B: Backend + std::io::Write>(

/// 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<crossterm::event::Event>,
) -> Option<Event> {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ui/src/tui/debouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<T> Debouncer<T> {
pub fn query(&mut self) -> Option<T> {
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()
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ui/src/tui/term_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<W> TerminalOutput<W> {
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> {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-ui/src/wui/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CurrentRun<'a> {
}

#[Object]
impl<'a> CurrentRun<'a> {
impl CurrentRun<'_> {
async fn tasks(&self) -> Vec<RunTask> {
self.state
.lock()
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-vt100/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-10-11"
channel = "nightly-2024-11-22"
components = ["rustfmt", "clippy"]
profile = "minimal"

0 comments on commit b066773

Please sign in to comment.