From 0e334e3e6c71eca140d36c112dc46a668e2920d8 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Wed, 20 Mar 2024 10:57:14 +0100 Subject: [PATCH] chore: fix upcoming rust 1.77 clippy issues and chrono deprecations (#5850) --- src/context.rs | 8 ++++---- src/context_env.rs | 2 +- src/modules/aws.rs | 25 +++++++++---------------- src/test/mod.rs | 5 ++++- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/context.rs b/src/context.rs index 2b9994125..a24a98891 100644 --- a/src/context.rs +++ b/src/context.rs @@ -38,9 +38,9 @@ pub struct Context<'a> { /// The current working directory that starship is being called in. pub current_dir: PathBuf, - /// A logical directory path which should represent the same directory as current_dir, + /// A logical directory path which should represent the same directory as `current_dir`, /// though may appear different. - /// E.g. when navigating to a PSDrive in PowerShell, or a path without symlinks resolved. + /// E.g. when navigating to a `PSDrive` in `PowerShell`, or a path without symlinks resolved. pub logical_dir: PathBuf, /// A struct containing directory contents in a lookup-optimized format. @@ -61,10 +61,10 @@ pub struct Context<'a> { /// Width of terminal, or zero if width cannot be detected. pub width: usize, - /// A HashMap of environment variable mocks + /// A `HashMap` of environment variable mocks pub env: Env<'a>, - /// A HashMap of command mocks + /// A `HashMap` of command mocks #[cfg(test)] pub cmd: HashMap<&'a str, Option>, diff --git a/src/context_env.rs b/src/context_env.rs index 5e881951a..764baf378 100644 --- a/src/context_env.rs +++ b/src/context_env.rs @@ -6,7 +6,7 @@ use std::ffi::OsString; #[derive(Default)] pub struct Env<'a> { - /// A HashMap of environment variable mocks + /// A `HashMap` of environment variable mocks #[cfg(test)] pub env: HashMap<&'a str, String>, diff --git a/src/modules/aws.rs b/src/modules/aws.rs index fa455862f..ae5c35d71 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -684,15 +684,12 @@ credential_process = /opt/bin/awscreds-retriever #[test] fn expiration_date_set() { - use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc}; + use chrono::{DateTime, SecondsFormat, Utc}; let expiration_env_vars = ["AWS_SESSION_EXPIRATION", "AWS_CREDENTIAL_EXPIRATION"]; expiration_env_vars.iter().for_each(|env_var| { - let now_plus_half_hour: DateTime = DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() + 1800, 0) - .unwrap(), - Utc, - ); + let now_plus_half_hour: DateTime = + DateTime::from_timestamp(chrono::Local::now().timestamp() + 1800, 0).unwrap(); let actual = ModuleRenderer::new("aws") .env("AWS_PROFILE", "astronauts") @@ -727,12 +724,10 @@ credential_process = /opt/bin/awscreds-retriever let credentials_path = dir.path().join("credentials"); let mut file = File::create(&credentials_path)?; - use chrono::{DateTime, NaiveDateTime, Utc}; + use chrono::{DateTime, Utc}; - let now_plus_half_hour: DateTime = DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() + 1800, 0).unwrap(), - Utc, - ); + let now_plus_half_hour: DateTime = + DateTime::from_timestamp(chrono::Local::now().timestamp() + 1800, 0).unwrap(); let expiration_date = now_plus_half_hour.to_rfc3339_opts(chrono::SecondsFormat::Secs, true); @@ -800,12 +795,10 @@ aws_secret_access_key=dummy #[test] fn expiration_date_set_expired() { - use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc}; + use chrono::{DateTime, SecondsFormat, Utc}; - let now: DateTime = DateTime::from_naive_utc_and_offset( - NaiveDateTime::from_timestamp_opt(chrono::Local::now().timestamp() - 1800, 0).unwrap(), - Utc, - ); + let now: DateTime = + DateTime::from_timestamp(chrono::Local::now().timestamp() - 1800, 0).unwrap(); let symbol = "!!!"; diff --git a/src/test/mod.rs b/src/test/mod.rs index 9cbb749d7..3bb44607a 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -70,7 +70,9 @@ impl<'a> ModuleRenderer<'a> { T: Into, { self.context.current_dir = path.into(); - self.context.logical_dir = self.context.current_dir.clone(); + self.context + .logical_dir + .clone_from(&self.context.current_dir); self } @@ -184,6 +186,7 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result { fs::OpenOptions::new() .create(true) .write(true) + .truncate(false) .open(path.path().join(checkout_db))? .sync_all()?; Ok(path)