Skip to content

Commit

Permalink
style: format sources with the 2024 Style Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Feb 20, 2025
1 parent e41930d commit 39526f9
Show file tree
Hide file tree
Showing 54 changed files with 306 additions and 204 deletions.
4 changes: 2 additions & 2 deletions download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ pub mod reqwest_be {
use std::sync::LazyLock;
use std::time::Duration;

use anyhow::{anyhow, Context, Result};
use reqwest::{header, Client, ClientBuilder, Proxy, Response};
use anyhow::{Context, Result, anyhow};
use reqwest::{Client, ClientBuilder, Proxy, Response, header};
#[cfg(feature = "reqwest-rustls-tls")]
use rustls::crypto::aws_lc_rs;
#[cfg(feature = "reqwest-rustls-tls")]
Expand Down
2 changes: 1 addition & 1 deletion download/tests/download-curl-resume.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature = "curl-backend")]

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
use std::sync::atomic::{AtomicBool, Ordering};

use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion download/tests/download-reqwest-resume.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))]

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
use std::sync::atomic::{AtomicBool, Ordering};

use url::Url;

Expand Down
2 changes: 1 addition & 1 deletion download/tests/read-proxy-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::env::{remove_var, set_var};
use std::error::Error;
use std::net::TcpListener;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::LazyLock;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;

Expand Down
4 changes: 2 additions & 2 deletions download/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::fs;
use std::io;
use std::net::SocketAddr;
use std::path::Path;
use std::sync::mpsc::{channel, Sender};
use std::sync::mpsc::{Sender, channel};
use std::thread;

use http_body_util::Full;
use hyper::Request;
use hyper::body::Bytes;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::Request;
use tempfile::TempDir;

pub fn tmp_dir() -> TempDir {
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style_edition = "2024"
6 changes: 3 additions & 3 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

use std::process::ExitCode;

use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use cfg_if::cfg_if;
// Public macros require availability of the internal symbols
use rs_tracing::{
close_trace_file, close_trace_file_internal, open_trace_file, trace_to_file_internal,
};
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use rustup::cli::common;
use rustup::cli::proxy_mode;
Expand Down Expand Up @@ -145,7 +145,7 @@ fn do_recursion_guard(process: &Process) -> Result<()> {
#[cfg(windows)]
pub fn pre_rustup_main_init() {
use windows_sys::Win32::System::LibraryLoader::{
SetDefaultDllDirectories, LOAD_LIBRARY_SEARCH_SYSTEM32,
LOAD_LIBRARY_SEARCH_SYSTEM32, SetDefaultDllDirectories,
};
// Default to loading delay loaded DLLs from the system directory.
// For DLLs loaded at load time, this relies on the `delayload` linker flag.
Expand Down
12 changes: 7 additions & 5 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock, Mutex};
use std::{cmp, env};

use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use git_testament::{git_testament, render_testament};
use tracing::{debug, error, info, trace, warn};
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use super::self_update;
use crate::{
cli::download_tracker::DownloadTracker,
config::Cfg,
dist::{
manifest::ComponentStatus, notifications as dist_notifications, TargetTriple, ToolchainDesc,
TargetTriple, ToolchainDesc, manifest::ComponentStatus, notifications as dist_notifications,
},
errors::RustupError,
install::UpdateStatus,
notifications::Notification,
process::{terminalsource, Process},
process::{Process, terminalsource},
toolchain::{DistributableToolchain, LocalToolchainName, Toolchain, ToolchainName},
utils::{self, notifications as util_notifications, notify::NotificationLevel},
};
Expand Down Expand Up @@ -654,7 +654,9 @@ pub(crate) fn warn_if_host_is_emulated(process: &Process) {
"Rustup is not running natively. It's running under emulation of {}.",
TargetTriple::from_host_or_build(process)
);
warn!("For best compatibility and performance you should reinstall rustup for your native CPU.");
warn!(
"For best compatibility and performance you should reinstall rustup for your native CPU."
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::time::{Duration, Instant};

use crate::dist::Notification as In;
use crate::notifications::Notification;
use crate::process::{terminalsource, Process};
use crate::utils::units::{Size, Unit, UnitMode};
use crate::process::{Process, terminalsource};
use crate::utils::Notification as Un;
use crate::utils::units::{Size, Unit, UnitMode};

/// Keep track of this many past download amounts
const DOWNLOAD_TRACK_COUNT: usize = 5;
Expand Down
3 changes: 1 addition & 2 deletions src/cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
$ rustup completions zsh cargo > ~/.zfunc/_cargo";

pub(crate) static OFFICIAL_TOOLCHAIN_ARG_HELP: &str =
"Toolchain name, such as 'stable', 'nightly', \
pub(crate) static OFFICIAL_TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
or '1.8.0'. For more information see `rustup \
help toolchain`";
pub(crate) static RESOLVABLE_LOCAL_TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
Expand Down
11 changes: 6 additions & 5 deletions src/cli/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ use std::{fmt, io::Write};
#[cfg(feature = "otel")]
use opentelemetry_sdk::trace::Tracer;
use termcolor::{Color, ColorSpec, WriteColor};
use tracing::{level_filters::LevelFilter, Event, Subscriber};
use tracing::{Event, Subscriber, level_filters::LevelFilter};
use tracing_subscriber::{
EnvFilter, Layer, Registry,
fmt::{
format::{self, FormatEvent, FormatFields},
FmtContext,
format::{self, FormatEvent, FormatFields},
},
layer::SubscriberExt,
registry::LookupSpan,
reload, EnvFilter, Layer, Registry,
reload,
};

use crate::{process::Process, utils::notify::NotificationLevel};
Expand Down Expand Up @@ -152,12 +153,12 @@ where
fn telemetry_default_tracer() -> Tracer {
use std::time::Duration;

use opentelemetry::{global, trace::TracerProvider as _, KeyValue};
use opentelemetry::{KeyValue, global, trace::TracerProvider as _};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{
Resource,
runtime::Tokio,
trace::{Sampler, TracerProvider},
Resource,
};

let exporter = opentelemetry_otlp::SpanExporter::builder()
Expand Down
126 changes: 94 additions & 32 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ use std::path::{Path, PathBuf};
use std::process::ExitStatus;
use std::str::FromStr;

use anyhow::{anyhow, Context, Error, Result};
use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, ValueEnum};
use anyhow::{Context, Error, Result, anyhow};
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue};
use clap_complete::Shell;
use itertools::Itertools;
use tracing::{info, trace, warn};
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use crate::{
cli::{
common::{self, update_console_filter, PackageUpdate},
common::{self, PackageUpdate, update_console_filter},
errors::CLIError,
help::*,
self_update::{self, check_rustup_update, SelfUpdateMode},
self_update::{self, SelfUpdateMode, check_rustup_update},
topical_doc,
},
command,
config::{ActiveReason, Cfg},
dist::{
manifest::{Component, ComponentStatus},
PartialToolchainDesc, Profile, TargetTriple,
manifest::{Component, ComponentStatus},
},
errors::RustupError,
install::{InstallMethod, UpdateStatus},
process::{
terminalsource::{self, ColorableTerminal},
Process,
terminalsource::{self, ColorableTerminal},
},
toolchain::{
CustomToolchainName, DistributableToolchain, LocalToolchainName,
Expand All @@ -41,8 +41,7 @@ use crate::{
utils::{self, ExitCode},
};

const TOOLCHAIN_OVERRIDE_ERROR: &str =
"To override the toolchain using the 'rustup +toolchain' syntax, \
const TOOLCHAIN_OVERRIDE_ERROR: &str = "To override the toolchain using the 'rustup +toolchain' syntax, \
make sure to prefix the toolchain override with a '+'";

fn handle_epipe(res: Result<utils::ExitCode>) -> Result<utils::ExitCode> {
Expand Down Expand Up @@ -90,12 +89,17 @@ struct Rustup {
}

fn plus_toolchain_value_parser(s: &str) -> clap::error::Result<ResolvableToolchainName> {
use clap::{error::ErrorKind, Error};
use clap::{Error, error::ErrorKind};
if let Some(stripped) = s.strip_prefix('+') {
ResolvableToolchainName::try_from(stripped)
.map_err(|e| Error::raw(ErrorKind::InvalidValue, e))
} else {
Err(Error::raw(ErrorKind::InvalidSubcommand, format!("\"{s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}")))
Err(Error::raw(
ErrorKind::InvalidSubcommand,
format!(
"\"{s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}"
),
))
}
}

Expand Down Expand Up @@ -1191,7 +1195,9 @@ async fn target_remove(
let target = TargetTriple::new(target);
let default_target = cfg.get_default_host_triple()?;
if target == default_target {
warn!("removing the default host target; proc-macros and build scripts might no longer build");
warn!(
"removing the default host target; proc-macros and build scripts might no longer build"
);
}
// Whether we have at most 1 component target that is not `None` (wildcard).
let has_at_most_one_target = distributable
Expand Down Expand Up @@ -1316,13 +1322,17 @@ fn toolchain_remove(cfg: &mut Cfg<'_>, opts: UninstallOpts) -> Result<utils::Exi
.as_ref()
.is_some_and(|n| n == &toolchain_name)
{
warn!("removing the active toolchain; a toolchain override will be required for running Rust tools");
warn!(
"removing the active toolchain; a toolchain override will be required for running Rust tools"
);
}
if default_toolchain
.as_ref()
.is_some_and(|n| n == &toolchain_name)
{
warn!("removing the default toolchain; proc-macros and build scripts might no longer build");
warn!(
"removing the default toolchain; proc-macros and build scripts might no longer build"
);
}

Toolchain::ensure_removed(cfg, (&toolchain_name).into())?;
Expand Down Expand Up @@ -1433,28 +1443,77 @@ macro_rules! docs_data {
docs_data![
// flags can be used to open specific documents, e.g. `rustup doc --nomicon`
// tuple elements: document name used as flag, help message, document index path
(alloc, "The Rust core allocation and collections library", "alloc/index.html"),
(book, "The Rust Programming Language book", "book/index.html"),
(
alloc,
"The Rust core allocation and collections library",
"alloc/index.html"
),
(
book,
"The Rust Programming Language book",
"book/index.html"
),
(cargo, "The Cargo Book", "cargo/index.html"),
(clippy, "The Clippy Documentation", "clippy/index.html"),
(core, "The Rust Core Library", "core/index.html"),
(edition_guide, "The Rust Edition Guide", "edition-guide/index.html"),
(embedded_book, "The Embedded Rust Book", "embedded-book/index.html"),
(error_codes, "The Rust Error Codes Index", "error_codes/index.html"),

(nomicon, "The Dark Arts of Advanced and Unsafe Rust Programming", "nomicon/index.html"),

(
edition_guide,
"The Rust Edition Guide",
"edition-guide/index.html"
),
(
embedded_book,
"The Embedded Rust Book",
"embedded-book/index.html"
),
(
error_codes,
"The Rust Error Codes Index",
"error_codes/index.html"
),
(
nomicon,
"The Dark Arts of Advanced and Unsafe Rust Programming",
"nomicon/index.html"
),
#[arg(long = "proc_macro")]
(proc_macro, "A support library for macro authors when defining new macros", "proc_macro/index.html"),

(
proc_macro,
"A support library for macro authors when defining new macros",
"proc_macro/index.html"
),
(reference, "The Rust Reference", "reference/index.html"),
(rust_by_example, "A collection of runnable examples that illustrate various Rust concepts and standard libraries", "rust-by-example/index.html"),
(rustc, "The compiler for the Rust programming language", "rustc/index.html"),
(rustdoc, "Documentation generator for Rust projects", "rustdoc/index.html"),
(
rust_by_example,
"A collection of runnable examples that illustrate various Rust concepts and standard libraries",
"rust-by-example/index.html"
),
(
rustc,
"The compiler for the Rust programming language",
"rustc/index.html"
),
(
rustdoc,
"Documentation generator for Rust projects",
"rustdoc/index.html"
),
(std, "Standard library API documentation", "std/index.html"),
(style_guide, "The Rust Style Guide", "style-guide/index.html"),
(test, "Support code for rustc's built in unit-test and micro-benchmarking framework", "test/index.html"),
(unstable_book, "The Unstable Book", "unstable-book/index.html"),
(
style_guide,
"The Rust Style Guide",
"style-guide/index.html"
),
(
test,
"Support code for rustc's built in unit-test and micro-benchmarking framework",
"test/index.html"
),
(
unstable_book,
"The Unstable Book",
"unstable-book/index.html"
),
];

impl DocPage {
Expand Down Expand Up @@ -1594,7 +1653,10 @@ fn set_auto_self_update(
.as_ref()
.and_then(|a| a.to_str())
.ok_or(CLIError::NoExeName)?;
warn!("{} is built with the no-self-update feature: setting auto-self-update will not have any effect.",arg0);
warn!(
"{} is built with the no-self-update feature: setting auto-self-update will not have any effect.",
arg0
);
}
cfg.set_auto_self_update(auto_self_update_mode)?;
Ok(utils::ExitCode(0))
Expand Down Expand Up @@ -1655,7 +1717,7 @@ fn output_completion_script(
"{} does not currently support completions for {}",
command,
shell
))
));
}
};

Expand Down
Loading

0 comments on commit 39526f9

Please sign in to comment.