Skip to content

Commit

Permalink
cargo clippy --fix -- -Dclippy::uninlined_format_args (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac authored Nov 8, 2024
1 parent 7e58bd2 commit 1493037
Show file tree
Hide file tree
Showing 87 changed files with 311 additions and 381 deletions.
2 changes: 1 addition & 1 deletion src/analyze/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn print_buffer(buffer: &Buffer, title: impl fmt::Display) {
let width = out.lines().map(table::str_width).max().unwrap_or(80);

table::print_title(title, width);
println!("{}", out);
println!("{out}");
println!();
}

Expand Down
4 changes: 2 additions & 2 deletions src/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn interactive(prompt: &mut repl::State, query: &str) -> anyhow::Resul
{
Ok(input) => input,
Err(e) => {
eprintln!("{:#}", e);
eprintln!("{e:#}");
prompt.last_error = Some(e);
return Err(QueryError)?;
}
Expand All @@ -55,7 +55,7 @@ pub async fn interactive(prompt: &mut repl::State, query: &str) -> anyhow::Resul
.unwrap_or(false)
{
let json: serde_json::Value = serde_json::from_str(&data).unwrap();
println!("JSON: {}", json);
println!("JSON: {json}");
}
let jd = &mut serde_json::Deserializer::from_str(&data);
let output = serde_path_to_error::deserialize(jd).context("parsing explain output")?;
Expand Down
2 changes: 1 addition & 1 deletion src/analyze/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl fmt::Display for PropValue {
write!(f, "ms")?;
}
Expr(val) => {
write!(f, "{:?}", val)?;
write!(f, "{val:?}")?;
}
Index(val) => {
val.fmt(f)?;
Expand Down
10 changes: 5 additions & 5 deletions src/analyze/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn render(title: Option<impl fmt::Display>, table: &[Vec<Box<dyn Contents +
line_buf.push_str(line);
}
}
println!("{}", line_buf);
println!("{line_buf}");
line_buf.truncate(0);
}
}
Expand Down Expand Up @@ -219,14 +219,14 @@ impl fmt::Display for BufRender<'_> {
impl<T: fmt::Display> Contents for T {
fn width_bounds(&self) -> (usize, usize) {
let mut cnt = Counter::new();
write!(&mut cnt, "{}", self).expect("can write into counter");
write!(&mut cnt, "{self}").expect("can write into counter");
(cnt.width, cnt.width)
}
fn height(&self, _width: usize) -> usize {
1
}
fn render(&self, _width: usize, _height: usize, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
write!(f, "{self}")
}
}

Expand Down Expand Up @@ -311,7 +311,7 @@ pub fn str_width(s: &str) -> usize {

pub fn display_width(v: impl fmt::Display) -> usize {
let mut cnt = Counter::new();
write!(&mut cnt, "{}", v).expect("can write into counter");
write!(&mut cnt, "{v}").expect("can write into counter");
cnt.width
}

Expand Down Expand Up @@ -400,7 +400,7 @@ impl Printer for TextPrinter<'_, '_> {
counter: Counter::new(),
width: self.width,
};
write!(&mut wrapper, "{}", word)?;
write!(&mut wrapper, "{word}")?;
if wrapper.counter.width > 0 {
self.fmt.write_char('\n')?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analyze/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ impl table::Contents for ShapeNode<'_> {
self.marker.render_head(f)?;
write!(f, "{}", self.context)?;
if let Some(attr) = self.attribute {
write!(f, ".{}", attr)?;
write!(f, ".{attr}")?;
}
self.marker.render_tail(height, f)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/branch/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ impl Context {
let Some(path) = &project_dir else {
return Ok(None);
};
Ok(Some(crate::portable::config::read(&path)?))
Ok(Some(crate::portable::config::read(path)?))
}
}
2 changes: 1 addition & 1 deletion src/branch/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub async fn create_branch(
eprintln!("WARNING: when --empty is used, --copy-data will be ignored");
}

format!("create empty branch {}", new_branch)
format!("create empty branch {new_branch}")
} else {
let kind = if copy_data { "data" } else { "schema" };

Expand Down
2 changes: 1 addition & 1 deletion src/branch/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub async fn main(
let current_branch = context.get_current_branch(connection).await?;

if options.plain {
println!("{}", current_branch);
println!("{current_branch}");
} else {
eprintln!("The current branch is '{}'", current_branch.green());
}
Expand Down
2 changes: 1 addition & 1 deletion src/branch/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn main(
if current_branch == branch {
println!("{} - Current", branch.green());
} else {
println!("{}", branch);
println!("{branch}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/branch/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async fn rebase(
}

// drop source branch
eprintln!("\nReplacing '{}' with rebased version...", current_branch);
eprintln!("\nReplacing '{current_branch}' with rebased version...");
let (status, _warnings) = target_connection
.execute(
&format!(
Expand Down
15 changes: 7 additions & 8 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn ensure_line(path: &PathBuf, line: &str) -> anyhow::Result<()> {
.append(true)
.open(path)
.context("cannot open file for appending (writing)")?;
file.write(format!("{}\n", line).as_bytes())
file.write(format!("{line}\n").as_bytes())
.context("cannot append to file")?;
Ok(())
}
Expand Down Expand Up @@ -362,7 +362,7 @@ pub fn main(options: &CliInstall) -> anyhow::Result<()> {
{
// This is needed so user can read the message if console
// was open just for this process
eprintln!("edgedb error: {:#}", e);
eprintln!("edgedb error: {e:#}");
eprintln!("Press the Enter key to continue");
read_choice()?;
exit(1);
Expand Down Expand Up @@ -516,12 +516,11 @@ fn _main(options: &CliInstall) -> anyhow::Result<()> {
fs::create_dir_all(&settings.installation_path)
.with_context(|| format!("failed to create {:?}", settings.installation_path))?;
if exe_path.parent() == path.parent() {
fs::rename(&exe_path, &path).with_context(|| format!("failed to rename {:?}", exe_path))?;
fs::rename(&exe_path, &path).with_context(|| format!("failed to rename {exe_path:?}"))?;
} else {
fs::remove_file(&tmp_path).ok();
fs::copy(&exe_path, &tmp_path)
.with_context(|| format!("failed to write {:?}", tmp_path))?;
fs::rename(&tmp_path, &path).with_context(|| format!("failed to rename {:?}", tmp_path))?;
fs::copy(&exe_path, &tmp_path).with_context(|| format!("failed to write {tmp_path:?}"))?;
fs::rename(&tmp_path, &path).with_context(|| format!("failed to rename {tmp_path:?}"))?;
}
write_completions_home()?;

Expand Down Expand Up @@ -551,10 +550,10 @@ fn _main(options: &CliInstall) -> anyhow::Result<()> {
);
for path in &settings.rc_files {
ensure_line(path, &line)
.with_context(|| format!("failed to update profile file {:?}", path))?;
.with_context(|| format!("failed to update profile file {path:?}"))?;
}
if let Some(dir) = settings.env_file.parent() {
fs::create_dir_all(dir).with_context(|| format!("failed to create {:?}", dir))?;
fs::create_dir_all(dir).with_context(|| format!("failed to create {dir:?}"))?;
}
fs::write(&settings.env_file, line + "\n")
.with_context(|| format!("failed to write env file {:?}", settings.env_file))?;
Expand Down
22 changes: 9 additions & 13 deletions src/cli/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ fn move_file(src: &Path, dest: &Path, dry_run: bool) -> anyhow::Result<()> {
return Ok(());
}
let mut q = question::Choice::new(format!(
"Attempting to move {:?} -> {:?}, but \
destination file exists. Do you want to overwrite?",
src, dest
"Attempting to move {src:?} -> {dest:?}, but \
destination file exists. Do you want to overwrite?"
));
q.option(Yes, &["y"], "overwrite the destination file");
q.option(Skip, &["s"], "skip, keep destination file, remove source");
Expand Down Expand Up @@ -114,9 +113,8 @@ fn move_dir(src: &Path, dest: &Path, dry_run: bool) -> anyhow::Result<()> {
return Ok(());
}
let mut q = question::Choice::new(format!(
"Attempting to move {:?} -> {:?}, but \
destination directory exists. Do you want to overwrite?",
src, dest
"Attempting to move {src:?} -> {dest:?}, but \
destination directory exists. Do you want to overwrite?"
));
q.option(Yes, &["y"], "overwrite the destination dir");
q.option(Skip, &["s"], "skip, keep destination dir, remove source");
Expand Down Expand Up @@ -244,9 +242,9 @@ fn update_path(base: &Path, new_bin_path: &Path) -> anyhow::Result<()> {
let cfg_dir = config_dir()?;
let env_file = cfg_dir.join("env");

fs::create_dir_all(&cfg_dir).with_context(|| format!("failed to create {:?}", cfg_dir))?;
fs::create_dir_all(&cfg_dir).with_context(|| format!("failed to create {cfg_dir:?}"))?;
fs::write(&env_file, new_line + "\n")
.with_context(|| format!("failed to write env file {:?}", env_file))?;
.with_context(|| format!("failed to write env file {env_file:?}"))?;

if modified && no_dir_in_path(new_bin_dir) {
print::success(concatcp!(
Expand Down Expand Up @@ -351,16 +349,14 @@ pub fn migrate(base: &Path, dry_run: bool) -> anyhow::Result<()> {
if !dry_run && dir_is_non_empty(base)? {
eprintln!(
"\
Directory {:?} is no longer used by {BRANDING} tools and must be \
Directory {base:?} is no longer used by {BRANDING} tools and must be \
removed to finish migration, but some files or directories \
remain after all known files have moved. \
The files may have been left by a third party tool. \
",
base
"
);
let q = question::Confirm::new(format!(
"Do you want to remove all files and directories within {:?}?",
base,
"Do you want to remove all files and directories within {base:?}?",
));
if !q.ask()? {
print::error("Canceled by user.");
Expand Down
2 changes: 1 addition & 1 deletion src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn _main(options: &CliUpgrade, path: PathBuf) -> anyhow::Result<()> {
let down_dir = path
.parent()
.context("download path missing directory component")?;
fs::create_dir_all(down_dir).with_context(|| format!("failed to create {:?}", down_dir))?;
fs::create_dir_all(down_dir).with_context(|| format!("failed to create {down_dir:?}"))?;

let down_path = path.with_extension("download");
let tmp_path = tmp_file_path(&path);
Expand Down
7 changes: 3 additions & 4 deletions src/cloud/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub async fn _do_login(client: &mut CloudClient) -> anyhow::Result<()> {
}
let deadline = Instant::now() + AUTHENTICATION_WAIT_TIME;
while Instant::now() < deadline {
match client.get(format!("auth/sessions/{}", id)).await {
match client.get(format!("auth/sessions/{id}")).await {
Ok(UserSession {
id: _,
auth_url: _,
Expand Down Expand Up @@ -126,7 +126,7 @@ pub async fn _do_login(client: &mut CloudClient) -> anyhow::Result<()> {
));
return Ok(());
}
Err(e) => print::warn(format!("Request failed: {:?}\nRetrying...", e)),
Err(e) => print::warn(format!("Request failed: {e:?}\nRetrying...")),
_ => {}
}
sleep(AUTHENTICATION_POLL_INTERVAL).await;
Expand Down Expand Up @@ -213,8 +213,7 @@ pub fn logout(c: &options::Logout, options: &CloudOptions) -> anyhow::Result<()>
removed = true;
fs::remove_file(cloud_creds.join(item.file_name()))?;
print::success(format!(
"You are now logged out from {BRANDING_CLOUD} profile {:?}.",
profile
"You are now logged out from {BRANDING_CLOUD} profile {profile:?}."
));
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/backups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn list_cloud_instance_backups(
name: &str,
json: bool,
) -> anyhow::Result<()> {
let url = format!("orgs/{}/instances/{}/backups", org_slug, name);
let url = format!("orgs/{org_slug}/instances/{name}/backups");
let backups: Vec<Backup> = client.get(url).await?;

if json {
Expand Down
6 changes: 3 additions & 3 deletions src/cloud/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl CloudClient {
.context("malformed secret key: missing `iss` claim")?;

let mut headers = header::HeaderMap::new();
let auth_str = format!("Bearer {}", secret_key);
let auth_str = format!("Bearer {secret_key}");
let mut auth_value = header::HeaderValue::from_str(&auth_str)?;
auth_value.set_sensitive(true);
headers.insert(header::AUTHORIZATION, auth_value.clone());
Expand Down Expand Up @@ -323,7 +323,7 @@ y4u6fdOVhgIhAJ4pJLfdoWQsHPUOcnVG5fBgdSnoCJhGQyuGyp+NDu1q
log::debug!("Response body: {}", full);
ErrorResponse {
code,
status: format!("error decoding response body: {:#}", e),
status: format!("error decoding response body: {e:#}"),
error: Some(full),
}
})))
Expand Down Expand Up @@ -399,7 +399,7 @@ y4u6fdOVhgIhAJ4pJLfdoWQsHPUOcnVG5fBgdSnoCJhGQyuGyp+NDu1q
impl fmt::Display for ErrorResponse {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(error) = &self.error {
write!(f, "{}", error)
write!(f, "{error}")
} else {
write!(f, "HTTP error: [{:?}] {}", self.code, self.status)
}
Expand Down
12 changes: 6 additions & 6 deletions src/cloud/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub enum CloudTier {

impl fmt::Display for CloudTier {
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ pub async fn find_cloud_instance_by_name(
client: &CloudClient,
) -> anyhow::Result<Option<CloudInstance>> {
client
.get(format!("orgs/{}/instances/{}", org, inst))
.get(format!("orgs/{org}/instances/{inst}"))
.await
.map(Some)
.or_else(|e| match e.downcast_ref::<ErrorResponse>() {
Expand All @@ -254,7 +254,7 @@ pub async fn find_cloud_instance_by_name(

#[tokio::main(flavor = "current_thread")]
pub async fn get_org(org: &str, client: &CloudClient) -> anyhow::Result<Org> {
client.get(format!("orgs/{}", org)).await
client.get(format!("orgs/{org}")).await
}

pub(crate) async fn wait_for_operation(
Expand All @@ -275,7 +275,7 @@ pub(crate) async fn wait_for_operation(
(OperationStatus::Failed, Some(subsequent_id)) => {
original_error = original_error.or(Some(operation.message));

url = format!("operations/{}", subsequent_id);
url = format!("operations/{subsequent_id}");
operation = client.get(&url).await?;
}
(OperationStatus::Failed, None) => {
Expand Down Expand Up @@ -381,7 +381,7 @@ pub async fn restart_cloud_instance(
client.ensure_authenticated()?;
let operation: CloudOperation = client
.post(
format!("orgs/{}/instances/{}/restart", org, name),
format!("orgs/{org}/instances/{name}/restart"),
&CloudInstanceRestart {},
)
.await?;
Expand All @@ -398,7 +398,7 @@ pub async fn destroy_cloud_instance(
let client = CloudClient::new(options)?;
client.ensure_authenticated()?;
let operation: CloudOperation = client
.delete(format!("orgs/{}/instances/{}", org, name))
.delete(format!("orgs/{org}/instances/{name}"))
.await?;
wait_for_operation(operation, &client).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/secret_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub async fn _do_create(c: &options::CreateSecretKey, client: &CloudClient) -> a
.secret_key
.context("no valid secret key returned from server")?;
if c.non_interactive {
print!("{}", sk);
print!("{sk}");
} else {
echo!(
"\nYour new ",
Expand Down
Loading

0 comments on commit 1493037

Please sign in to comment.