chore: clippy

This commit is contained in:
Lucas Nogueira
2025-08-28 17:57:26 -03:00
parent 60cf1eae5c
commit 9001559102
40 changed files with 170 additions and 218 deletions

View File

@@ -33,16 +33,10 @@ fn main() {
Ok(output) => {
let msg = String::from_utf8_lossy(&output.stdout).to_string();
if let Err(err) = std::fs::write(install_dir.join("commit"), msg) {
println!(
"cargo:warning=failed to write current commit message: {}",
err
)
println!("cargo:warning=failed to write current commit message: {err}")
}
}
Err(err) => println!(
"cargo:warning=failed to get current commit message: {}",
err
),
Err(err) => println!("cargo:warning=failed to get current commit message: {err}"),
}
// Copy templates

View File

@@ -90,7 +90,7 @@ mod test {
)]
fn test_adb_output_regex(input: &str, devices: Vec<&'static str>) {
let regex = regex_multi_line!(ADB_DEVICE_REGEX);
println!("{}", input);
println!("{input}");
let captures = regex
.captures_iter(input)
.map(|x| x.get(1).unwrap().as_str())

View File

@@ -151,8 +151,7 @@ impl Reportable for Error {
Self::ProjectDirAbsent { project_dir } => Report::action_request(
"Please run `cargo mobile init` and try again!",
format!(
"Android Studio project directory {:?} doesn't exist.",
project_dir
"Android Studio project directory {project_dir:?} doesn't exist."
),
),
Self::OpenFailed(err) => Report::error("Failed to open project in Android Studio", err),

View File

@@ -145,20 +145,15 @@ impl Display for ProjectDirInvalid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NormalizationFailed { project_dir, cause } => {
write!(f, "{:?} couldn't be normalized: {}", project_dir, cause)
write!(f, "{project_dir:?} couldn't be normalized: {cause}")
}
Self::OutsideOfAppRoot {
project_dir,
root_dir,
} => write!(
f,
"{:?} is outside of the app root {:?}",
project_dir, root_dir,
),
} => write!(f, "{project_dir:?} is outside of the app root {root_dir:?}",),
Self::ContainsSpaces { project_dir } => write!(
f,
"{:?} contains spaces, which the NDK is remarkably intolerant of",
project_dir
"{project_dir:?} contains spaces, which the NDK is remarkably intolerant of"
),
}
}

View File

@@ -33,17 +33,16 @@ impl Reportable for RemoveBrokenLinksError {
fn report(&self) -> Report {
match self {
Self::ReadDir { dir, source } => Report::error(
format!("Failed to list contents of jniLibs directory {:?}", dir),
format!("Failed to list contents of jniLibs directory {dir:?}"),
source,
),
Self::Entry { dir, source } => Report::error(
format!("Failed to get entry in jniLibs directory {:?}", dir),
source,
),
Self::Remove { path, source } => Report::error(
format!("Failed to remove broken symlink {:?}", path),
format!("Failed to get entry in jniLibs directory {dir:?}"),
source,
),
Self::Remove { path, source } => {
Report::error(format!("Failed to remove broken symlink {path:?}"), source)
}
}
}
}

View File

@@ -61,14 +61,14 @@ impl Reportable for Error {
Report::error("Android template processing failed", err)
}
Self::DirectoryCreationFailed { path, cause } => Report::error(
format!("Failed to create Android assets directory at {:?}", path),
format!("Failed to create Android assets directory at {path:?}"),
cause,
),
Self::DirectoryReadFailed { path, cause } => {
Report::error(format!("Failed to read directory at {:?}", path), cause)
Report::error(format!("Failed to read directory at {path:?}"), cause)
}
Self::DirectoryRemoveFailed { path, cause } => Report::error(
format!("Failed to remove directory directory at {:?}", path),
format!("Failed to remove directory directory at {path:?}"),
cause,
),
Self::AssetDirSymlinkFailed(err) => {
@@ -77,12 +77,11 @@ impl Reportable for Error {
Self::DotCargoGenFailed(err) => {
Report::error("Failed to generate Android cargo config", err)
}
Self::FileCopyFailed { src, dest, cause } => Report::error(
format!("Failed to copy file at {:?} to {:?}", src, dest),
cause,
),
Self::FileCopyFailed { src, dest, cause } => {
Report::error(format!("Failed to copy file at {src:?} to {dest:?}"), cause)
}
Self::AssetSourceInvalid(src) => Report::error(
format!("Asset source at {:?} invalid", src),
format!("Asset source at {src:?} invalid"),
"Asset sources must be either a directory or a file",
),
}

View File

@@ -32,7 +32,7 @@ impl Display for Revision {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.triple)?;
if let Some(beta) = self.beta {
write!(f, "-beta{}", beta)?;
write!(f, "-beta{beta}")?;
}
Ok(())
}

View File

@@ -188,7 +188,7 @@ impl Reportable for Error {
Self::Unsupported => Report::error("iOS is marked as unsupported in your Cargo.toml metadata", "If your project should support Android, modify your Cargo.toml, then run `cargo mobile init` and try again."),
Self::ProjectDirAbsent { project_dir } => Report::action_request(
"Please run `cargo mobile init` and try again!",
format!("Xcode project directory {:?} doesn't exist.", project_dir),
format!("Xcode project directory {project_dir:?} doesn't exist."),
),
Self::OpenFailed(err) => Report::error("Failed to open project in Xcode", err),
Self::CheckFailed(err) => err.report(),
@@ -201,19 +201,19 @@ impl Reportable for Error {
Self::CargoEnvFailed(err) => Report::error("Failed to load cargo env profile", err),
Self::SdkRootInvalid { sdk_root } => Report::error(
"SDK root provided by Xcode was invalid",
format!("{:?} doesn't exist or isn't a directory", sdk_root),
format!("{sdk_root:?} doesn't exist or isn't a directory"),
),
Self::IncludeDirInvalid { include_dir } => Report::error(
"Include dir was invalid",
format!("{:?} doesn't exist or isn't a directory", include_dir),
format!("{include_dir:?} doesn't exist or isn't a directory"),
),
Self::MacosSdkRootInvalid { macos_sdk_root } => Report::error(
"macOS SDK root was invalid",
format!("{:?} doesn't exist or isn't a directory", macos_sdk_root),
format!("{macos_sdk_root:?} doesn't exist or isn't a directory"),
),
Self::ArchInvalid { arch } => Report::error(
"Arch specified by Xcode was invalid",
format!("{:?} isn't a known arch", arch),
format!("{arch:?} isn't a known arch"),
),
Self::CompileLibFailed(err) => err.report(),
Self::PodCommandFailed(err) => Report::error("pod command failed", err),
@@ -484,9 +484,9 @@ impl Exec for Input {
"x86_64" => ("x86_64_apple_ios", "x86_64-apple-ios"),
_ => return Err(Error::ArchInvalid { arch }),
};
let cflags = format!("CFLAGS_{}", triple);
let cxxflags = format!("CFLAGS_{}", triple);
let objc_include_path = format!("OBJC_INCLUDE_PATH_{}", triple);
let cflags = format!("CFLAGS_{triple}");
let cxxflags = format!("CFLAGS_{triple}");
let objc_include_path = format!("OBJC_INCLUDE_PATH_{triple}");
let mut target_env = host_env.clone();
target_env.insert(cflags.as_ref(), isysroot.as_ref());
target_env.insert(cxxflags.as_ref(), isysroot.as_ref());
@@ -532,7 +532,7 @@ impl Exec for Input {
}
// Copy static lib .a to Xcode Project
if rust_triple.starts_with(&"aarch64-apple-ios") {
if rust_triple.starts_with("aarch64-apple-ios") {
std::fs::create_dir_all(format!(
"Sources/{rust_triple}/{}",
profile.as_str()

View File

@@ -194,16 +194,14 @@ impl Display for ProjectDirInvalid {
match self {
Self::NormalizationFailed { project_dir, cause } => write!(
f,
"Xcode project dir {:?} couldn't be normalized: {}",
project_dir, cause
"Xcode project dir {project_dir:?} couldn't be normalized: {cause}"
),
Self::OutsideOfAppRoot {
project_dir,
root_dir,
} => write!(
f,
"Xcode project dir {:?} is outside of the app root dir {:?}",
project_dir, root_dir,
"Xcode project dir {project_dir:?} is outside of the app root dir {root_dir:?}",
),
}
}
@@ -388,7 +386,7 @@ impl Config {
}
pub fn ipa_path(&self) -> Result<PathBuf, (PathBuf, PathBuf)> {
let path = |tail: &str| self.export_dir().join(format!("{}.ipa", tail));
let path = |tail: &str| self.export_dir().join(format!("{tail}.ipa"));
let old = path(&self.scheme());
// It seems like the format changed recently?
let new = path(self.app.stylized_name());

View File

@@ -15,7 +15,7 @@ impl Display for DetectError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DeveloperTeamLookupFailed(err) => {
write!(f, "Failed to find Apple developer teams: {}", err)
write!(f, "Failed to find Apple developer teams: {err}")
}
}
}
@@ -31,10 +31,10 @@ impl Display for PromptError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DeveloperTeamLookupFailed(err) => {
write!(f, "Failed to find Apple developer teams: {}", err)
write!(f, "Failed to find Apple developer teams: {err}")
}
Self::DeveloperTeamPromptFailed(err) => {
write!(f, "Failed to prompt for Apple developer team: {}", err)
write!(f, "Failed to prompt for Apple developer team: {err}")
}
}
}
@@ -50,7 +50,7 @@ fn value_to_string(value: &PlistValue) -> String {
.map(value_to_string)
.collect::<Vec<_>>()
.join(",");
format!("[{}]", string)
format!("[{string}]")
}
PlistValue::Dictionary(dict) => dictionary_to_string(dict),
}
@@ -67,7 +67,7 @@ fn dictionary_to_string(dict: &PlistDictionary) -> String {
.map(|pair| pair_to_string(&pair.0.key, &pair.0.value))
.collect::<Vec<_>>()
.join(",");
format!("{{{}}}", joint)
format!("{{{joint}}}")
}
#[derive(Clone, Debug, Deserialize)]

View File

@@ -97,7 +97,7 @@ impl GemCache {
let command = if self.contains(package)? {
"gem update"
} else {
println!("`sudo` is required to install {} using gem", package);
println!("`sudo` is required to install {package} using gem");
"sudo gem install"
};
duct::cmd(command, [package])

View File

@@ -30,27 +30,25 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoHomeDir(err) => write!(f, "{}", err),
Self::XcodeSelectFailed(err) => write!(f, "Failed to get path to Xcode.app: {}", err),
Self::StatusFailed(err) => write!(f, "{}", err),
Self::UpdateFailed(err) => write!(f, "{}", err),
Self::UuidLookupFailed(err) => write!(f, "Failed to lookup Xcode UUID: {}", err),
Self::NoHomeDir(err) => write!(f, "{err}"),
Self::XcodeSelectFailed(err) => write!(f, "Failed to get path to Xcode.app: {err}"),
Self::StatusFailed(err) => write!(f, "{err}"),
Self::UpdateFailed(err) => write!(f, "{err}"),
Self::UuidLookupFailed(err) => write!(f, "Failed to lookup Xcode UUID: {err}"),
Self::PlistReadFailed { path, cause } => {
write!(f, "Failed to read plist at {:?}: {}", path, cause)
write!(f, "Failed to read plist at {path:?}: {cause}")
}
Self::PluginsDirCreationFailed { path, cause } => write!(
f,
"Failed to create Xcode plugins directory {:?}: {}",
path, cause
"Failed to create Xcode plugins directory {path:?}: {cause}"
),
Self::PluginCopyFailed(err) => write!(f, "Failed to copy Xcode plugin: {}", err),
Self::PluginCopyFailed(err) => write!(f, "Failed to copy Xcode plugin: {err}"),
Self::SpecDirCreationFailed { path, cause } => write!(
f,
"Failed to create Xcode language spec directory {:?}: {}",
path, cause
"Failed to create Xcode language spec directory {path:?}: {cause}"
),
Self::SpecCopyFailed(err) => write!(f, "Failed to copy language spec: {}", err),
Self::MetaCopyFailed(err) => write!(f, "Failed to copy language metadata: {}", err),
Self::SpecCopyFailed(err) => write!(f, "Failed to copy language spec: {err}"),
Self::MetaCopyFailed(err) => write!(f, "Failed to copy language metadata: {err}"),
}
}
}

View File

@@ -50,7 +50,7 @@ impl Reportable for RunError {
Self::ExportFailed(err) => err.report(),
Self::IpaMissing { old, new } => Report::error(
"IPA appears to be missing",
format!("Not found at either {:?} or {:?}", old, new),
format!("Not found at either {old:?} or {new:?}"),
),
Self::UnzipFailed(err) => Report::error("Failed to unzip archive", err),
Self::DeployFailed(err) => Report::error("Failed to deploy app", err),

View File

@@ -27,7 +27,7 @@ pub struct AuthCredentials {
pub fn rust_version_check(wrapper: &TextWrapper) -> Result<(), util::RustVersionError> {
util::RustVersion::check().map(|version| if !version.valid() {
Report::action_request(
format!("iOS linking is broken on Rust versions later than 1.45.2 (d3fb005a3 2020-07-31) and earlier than 1.49.0-nightly (ffa2e7ae8 2020-10-24), but you're on {}!", version),
format!("iOS linking is broken on Rust versions later than 1.45.2 (d3fb005a3 2020-07-31) and earlier than 1.49.0-nightly (ffa2e7ae8 2020-10-24), but you're on {version}!"),
"This is fixed in Rust 1.49.0 and later:\n`rustup update stable && rustup default stable`",
).print(wrapper);
})

View File

@@ -50,7 +50,7 @@ impl Reportable for Error {
Report::error("Asset dir couldn't be symlinked into Xcode project", err)
}
Self::DirectoryCreationFailed { path, cause } => Report::error(
format!("Failed to create iOS assets directory at {:?}", path),
format!("Failed to create iOS assets directory at {path:?}"),
cause,
),
Self::XcodegenFailed(err) => Report::error("Failed to run `xcodegen`", err),

View File

@@ -351,7 +351,7 @@ impl Bicycle {
if let Prefix::Disk(_) = prefix.kind() {
return p
.to_str()
.map(|s| format!("\\\\?\\{}", s))
.map(|s| format!("\\\\?\\{s}"))
.map(PathBuf::from)
.unwrap_or_else(|| p);
}

View File

@@ -119,10 +119,10 @@ impl Reportable for Error {
match self {
Self::InitFailed(err) => err.report(),
Self::DirCreationFailed { path, source } => {
Report::error(format!("Failed to create directory {:?}", path), source)
Report::error(format!("Failed to create directory {path:?}"), source)
}
Self::DirChangeFailed { path, source } => Report::error(
format!("Failed to change current directory {:?}", path),
format!("Failed to change current directory {path:?}"),
source,
),
Self::OpenFailed(err) => {

View File

@@ -83,24 +83,21 @@ impl fmt::Display for IdentifierError {
list_display(
&bad_chars
.iter()
.map(|c| format!("'{}'", c))
.map(|c| format!("'{c}'"))
.collect::<Vec<_>>()
),
),
Self::ReservedPackageName { package_name } => write!(
f,
"\"{}\" is a reserved package name in this project and can't be used as a top-level identifier.",
package_name
"\"{package_name}\" is a reserved package name in this project and can't be used as a top-level identifier."
),
Self::ReservedKeyword { keyword } => write!(
f,
"\"{}\" is a reserved keyword in java/kotlin and can't be used. For more info, please visit https://kotlinlang.org/docs/reference/keyword-reference.html and https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html",
keyword
"\"{keyword}\" is a reserved keyword in java/kotlin and can't be used. For more info, please visit https://kotlinlang.org/docs/reference/keyword-reference.html and https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html"
),
Self::StartsWithDigit { label } => write!(
f,
"\"{}\" label starts with a digit, which is not allowed in java/kotlin packages.",
label
"\"{label}\" label starts with a digit, which is not allowed in java/kotlin packages."
),
Self::StartsOrEndsWithADot => write!(f, "Identifier can't start or end with a dot."),
Self::EmptyLabel => write!(f, "Labels can't be empty."),

View File

@@ -41,36 +41,32 @@ impl Display for Invalid {
Self::Empty => write!(f, "The app name can't be empty.")?,
Self::NotAscii { app_name, .. } => write!(
f,
"\"{}\" isn't valid ASCII.",
app_name,
"\"{app_name}\" isn't valid ASCII.",
)?,
Self::StartsWithDigit { app_name, .. } => write!(f, "\"{}\" starts with a digit.", app_name)?,
Self::StartsWithDigit { app_name, .. } => write!(f, "\"{app_name}\" starts with a digit.")?,
Self::ReservedKeyword { app_name } => write!(
f,
"\"{}\" is a reserved keyword: https://doc.rust-lang.org/reference/keywords.html",
app_name,
"\"{app_name}\" is a reserved keyword: https://doc.rust-lang.org/reference/keywords.html",
)?,
Self::ReservedWindows { app_name } => write!(
f,
"\"{}\" is a reserved name on Windows.",
app_name,
"\"{app_name}\" is a reserved name on Windows.",
)?,
Self::ReservedArtifacts { app_name } => write!(
f,
"\"{}\" is reserved by Cargo.",
app_name,
"\"{app_name}\" is reserved by Cargo.",
)?,
Self::NotAlphanumericOrUnderscore { app_name, naughty_chars, .. } => write!(
f,
"\"{}\" contains {}, but only lowercase letters, numbers, and underscores are allowed.",
app_name,
util::list_display(
&naughty_chars.iter().map(|c| format!("'{}'", c)).collect::<Vec<_>>()
&naughty_chars.iter().map(|c| format!("'{c}'")).collect::<Vec<_>>()
),
)?,
}
if let Some(suggested) = self.suggested() {
write!(f, " \"{}\" would work, if you'd like!", suggested)?;
write!(f, " \"{suggested}\" would work, if you'd like!")?;
}
Ok(())
}
@@ -139,7 +135,7 @@ fn transliterate_initial_number(s: &str) -> String {
..english_numbers::Formatting::none()
},
);
normalize_case(&format!("{}-{}", transliterated, tail))
normalize_case(&format!("{transliterated}-{tail}"))
}
fn char_allowed(c: char) -> bool {

View File

@@ -219,7 +219,7 @@ impl App {
.split('.')
.map(|s| {
if crate::reserved_names::KOTLIN_ONLY_KEYWORDS.contains(&s) {
format!("`{}`", s)
format!("`{s}`")
} else {
s.to_string()
}

View File

@@ -41,36 +41,32 @@ impl Display for Invalid {
Self::Empty => write!(f, "The app name can't be empty.")?,
Self::NotAscii { app_name, .. } => write!(
f,
"\"{}\" isn't valid ASCII.",
app_name,
"\"{app_name}\" isn't valid ASCII.",
)?,
Self::StartsWithDigit { app_name, .. } => write!(f, "\"{}\" starts with a digit.", app_name)?,
Self::StartsWithDigit { app_name, .. } => write!(f, "\"{app_name}\" starts with a digit.")?,
Self::ReservedKeyword { app_name } => write!(
f,
"\"{}\" is a reserved keyword: https://doc.rust-lang.org/reference/keywords.html",
app_name,
"\"{app_name}\" is a reserved keyword: https://doc.rust-lang.org/reference/keywords.html",
)?,
Self::ReservedWindows { app_name } => write!(
f,
"\"{}\" is a reserved name on Windows.",
app_name,
"\"{app_name}\" is a reserved name on Windows.",
)?,
Self::ReservedArtifacts { app_name } => write!(
f,
"\"{}\" is reserved by Cargo.",
app_name,
"\"{app_name}\" is reserved by Cargo.",
)?,
Self::NotAlphanumericHyphenOrUnderscore { app_name, naughty_chars, .. } => write!(
f,
"\"{}\" contains {}, but only lowercase letters, numbers, hyphens, and underscores are allowed.",
app_name,
util::list_display(
&naughty_chars.iter().map(|c| format!("'{}'", c)).collect::<Vec<_>>()
&naughty_chars.iter().map(|c| format!("'{c}'")).collect::<Vec<_>>()
),
)?,
}
if let Some(suggested) = self.suggested() {
write!(f, " \"{}\" would work, if you'd like!", suggested)?;
write!(f, " \"{suggested}\" would work, if you'd like!")?;
}
Ok(())
}
@@ -139,7 +135,7 @@ fn transliterate_initial_number(s: &str) -> String {
..english_numbers::Formatting::none()
},
);
normalize_case(&format!("{}-{}", transliterated, tail))
normalize_case(&format!("{transliterated}-{tail}"))
}
fn char_allowed(c: char) -> bool {

View File

@@ -62,15 +62,14 @@ impl Display for DefaultsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CurrentDirFailed(err) => {
write!(f, "Failed to get current working directory: {}", err)
write!(f, "Failed to get current working directory: {err}")
}
Self::CurrentDirHasNoName(cwd) => {
write!(f, "Current working directory has no name: {:?}", cwd)
write!(f, "Current working directory has no name: {cwd:?}")
}
Self::CurrentDirInvalidUtf8(cwd) => write!(
f,
"Current working directory contained invalid UTF-8: {:?}",
cwd
"Current working directory contained invalid UTF-8: {cwd:?}"
),
}
}
@@ -118,7 +117,7 @@ pub enum DetectError {
impl Display for DetectError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DefaultsFailed(err) => write!(f, "Failed to detect default values: {}", err),
Self::DefaultsFailed(err) => write!(f, "Failed to detect default values: {err}"),
Self::NameNotDetected => write!(f, "No app name was detected."),
}
}
@@ -137,17 +136,17 @@ pub enum PromptError {
impl Display for PromptError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DefaultsFailed(err) => write!(f, "Failed to detect default values: {}", err),
Self::NamePromptFailed(err) => write!(f, "Failed to prompt for name: {}", err),
Self::DefaultsFailed(err) => write!(f, "Failed to detect default values: {err}"),
Self::NamePromptFailed(err) => write!(f, "Failed to prompt for name: {err}"),
Self::StylizedNamePromptFailed(err) => {
write!(f, "Failed to prompt for stylized name: {}", err)
write!(f, "Failed to prompt for stylized name: {err}")
}
Self::IdentifierPromptFailed(err) => {
write!(f, "Failed to prompt for identifier: {}", err)
write!(f, "Failed to prompt for identifier: {err}")
}
Self::ListTemplatePacksFailed(err) => write!(f, "{}", err),
Self::ListTemplatePacksFailed(err) => write!(f, "{err}"),
Self::TemplatePackPromptFailed(err) => {
write!(f, "Failed to prompt for template pack: {}", err)
write!(f, "Failed to prompt for template pack: {err}")
}
}
}
@@ -227,7 +226,7 @@ impl Raw {
Err(err) => {
println!(
"{}",
wrapper.fill(&format!("Sorry! {}", err)).bright_magenta()
wrapper.fill(&format!("Sorry! {err}")).bright_magenta()
)
}
}

View File

@@ -24,7 +24,7 @@ pub struct PromptError<T: Display> {
impl<T: Display> Display for PromptError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.cause {
PromptErrorCause::DetectionFailed(err) => write!(f, "{}", err),
PromptErrorCause::DetectionFailed(err) => write!(f, "{err}"),
PromptErrorCause::PromptFailed(err) => {
write!(f, "Failed to prompt for {} device: {}", self.name, err)
}

View File

@@ -13,7 +13,7 @@ pub fn check(env: &Env) -> Result<Section, Unrecoverable> {
sdk_version,
util::contract_home(android_env.android_home())?,
)),
Err(err) => Err(format!("Failed to get SDK version: {}", err)),
Err(err) => Err(format!("Failed to get SDK version: {err}")),
})
.with_item(match android_env.ndk.version() {
Ok(ndk_version) => Ok(format!(
@@ -21,7 +21,7 @@ pub fn check(env: &Env) -> Result<Section, Unrecoverable> {
ndk_version,
util::contract_home(android_env.ndk.home())?,
)),
Err(err) => Err(format!("Failed to get NDK version: {}", err)),
Err(err) => Err(format!("Failed to get NDK version: {err}")),
}),
Err(err) => section.with_failure(err),
})

View File

@@ -10,24 +10,20 @@ fn validate_developer_dir() -> Result<String, String> {
static FORBIDDEN: &str = "/Library/Developer/CommandLineTools";
static SUGGESTED: &str = "/Applications/Xcode.app/Contents/Developer";
let xcode_developer_dir = xcode_plugin::xcode_developer_dir()
.map_err(|err| format!("Failed to get active Xcode developer dir: {}", err))?;
.map_err(|err| format!("Failed to get active Xcode developer dir: {err}"))?;
let xcode_developer_dir = {
if xcode_developer_dir == Path::new(FORBIDDEN) {
println!(
"Your active toolchain appears to be the Apple command-line tools: {:?}",
xcode_developer_dir
"Your active toolchain appears to be the Apple command-line tools: {xcode_developer_dir:?}"
);
println!("Changing your active toolchain to Xcode may be necessary for everything to work correctly.");
let answer = loop {
if let Some(answer) = prompt::yes_no(
format!("Would you like us to change it to {:?} for you?", SUGGESTED),
format!("Would you like us to change it to {SUGGESTED:?} for you?"),
Some(true),
)
.map_err(|err| {
format!(
"Failed to prompt for changing the Xcode developer dir: {}",
err
)
format!("Failed to prompt for changing the Xcode developer dir: {err}")
})? {
break answer;
}
@@ -36,7 +32,7 @@ fn validate_developer_dir() -> Result<String, String> {
duct::cmd("xcode-select", ["-s", SUGGESTED])
.dup_stdio()
.run()
.map_err(|err| format!("Failed to update Xcode developer dir: {}", err))?;
.map_err(|err| format!("Failed to update Xcode developer dir: {err}"))?;
Path::new(SUGGESTED)
} else {
&xcode_developer_dir
@@ -45,7 +41,7 @@ fn validate_developer_dir() -> Result<String, String> {
&xcode_developer_dir
}
};
Ok(format!("Active developer dir: {:?}", xcode_developer_dir))
Ok(format!("Active developer dir: {xcode_developer_dir:?}"))
}
fn validate_xcode_plugin(xcode_version: (u32, u32), section: Section) -> Section {
@@ -73,8 +69,7 @@ fn validate_xcode_plugin(xcode_version: (u32, u32), section: Section) -> Section
Item::warning("xcode-rust-plugin is outdated")
}),
Err(err) => section.with_failure(format!(
"Failed to check xcode-rust-plugin installation status: {}",
err
"Failed to check xcode-rust-plugin installation status: {err}"
)),
}
.with_item(match ctx.check_uuid() {
@@ -92,13 +87,10 @@ fn validate_xcode_plugin(xcode_version: (u32, u32), section: Section) -> Section
}
}
Err(err) => Item::failure(format!(
"Failed to check xcode-rust-plugin UUID status: {}",
err
"Failed to check xcode-rust-plugin UUID status: {err}"
)),
}),
Err(err) => {
section.with_failure(format!("Failed to get xcode-rust-plugin context: {}", err))
}
Err(err) => section.with_failure(format!("Failed to get xcode-rust-plugin context: {err}")),
}
}
@@ -108,8 +100,8 @@ pub fn check() -> Section {
.with_item(
xcode_version
.as_ref()
.map(|(major, minor)| format!("Xcode v{}.{}", major, minor))
.map_err(|err| format!("Failed to check Xcode version: {}", err)),
.map(|(major, minor)| format!("Xcode v{major}.{minor}"))
.map_err(|err| format!("Failed to check Xcode version: {err}")),
)
.with_item(validate_developer_dir())
.with_item(
@@ -117,14 +109,14 @@ pub fn check() -> Section {
.stderr_capture()
.read()
.map(|version| format!("ios-deploy v{}", version.trim()))
.map_err(|err| format!("Failed to check ios-deploy version: {}", err)),
.map_err(|err| format!("Failed to check ios-deploy version: {err}")),
)
.with_item(
duct::cmd("xcodegen", ["--version"])
.stderr_capture()
.read()
.map(|version| version.trim().replace("Version: ", "XcodeGen v"))
.map_err(|err| format!("Failed to check ios-deploy version: {}", err)),
.map_err(|err| format!("Failed to check ios-deploy version: {err}")),
);
let section = if let Ok(version) = xcode_version {
validate_xcode_plugin(version, section)
@@ -139,6 +131,6 @@ pub fn check() -> Section {
format!("Development team: {} ({})", team.name, team.id)
}))
}
Err(err) => section.with_failure(format!("Failed to find development teams: {}", err)),
Err(err) => section.with_failure(format!("Failed to find development teams: {err}")),
}
}

View File

@@ -8,7 +8,7 @@ use crate::{
fn check_os() -> Result<String, String> {
os::Info::check()
.map(|info| format!("{} v{}", info.name, info.version))
.map_err(|err| format!("Failed to get OS info: {}", err))
.map_err(|err| format!("Failed to get OS info: {err}"))
}
fn check_rust() -> Result<String, String> {
@@ -17,18 +17,17 @@ fn check_rust() -> Result<String, String> {
.and_then(|version| {
version
.valid()
.then(|| format!("rustc v{}", version))
.then(|| format!("rustc v{version}"))
.ok_or_else(|| {
format!(
"iOS linking is broken on rustc v{}; please update to 1.49.0 or later",
version
"iOS linking is broken on rustc v{version}; please update to 1.49.0 or later"
)
})
})
}
pub fn check() -> Result<Section, Unrecoverable> {
let section = Section::new(format!("cargo-mobile {}", VERSION_SHORT));
let section = Section::new(format!("cargo-mobile {VERSION_SHORT}"));
Ok(match util::install_dir() {
Ok(install_dir) => section
.with_item(util::installed_commit_msg().map(|msg| {
@@ -42,8 +41,7 @@ pub fn check() -> Result<Section, Unrecoverable> {
))
} else {
Err(format!(
"The cargo-mobile2 installation directory is missing! Checked at {:?}",
install_dir,
"The cargo-mobile2 installation directory is missing! Checked at {install_dir:?}",
))
}),
Err(err) => section.with_failure(err),

View File

@@ -11,14 +11,14 @@ pub fn check(env: &Env) -> Section {
let section = {
match crate::apple::device::list_devices(env) {
Ok(list) => section.with_victories(list),
Err(err) => section.with_failure(format!("Failed to get iOS device list: {}", err)),
Err(err) => section.with_failure(format!("Failed to get iOS device list: {err}")),
}
};
let section = if let Ok(android_env) = android::env::Env::from_env(env.clone()) {
match adb::device_list(&android_env) {
Ok(list) => section.with_victories(list),
Err(err) => section.with_failure(format!("Failed to get Android device list: {}", err)),
Err(err) => section.with_failure(format!("Failed to get Android device list: {err}")),
}
} else {
section

View File

@@ -71,10 +71,10 @@ impl Reportable for Error {
fn report(&self) -> Report {
match self {
Self::ConfigLoadOrGenFailed(err) => err.report(),
Self::DotFirstInitWriteFailed { path, cause } => Report::error(format!("Failed to write first init dot file {:?}", path), cause),
Self::DotFirstInitWriteFailed { path, cause } => Report::error(format!("Failed to write first init dot file {path:?}"), cause),
Self::FilterConfigureFailed(err) => Report::error("Failed to configure template filter", err),
Self::ProjectInitFailed(err) => err.report(),
Self::AssetDirCreationFailed { asset_dir, cause } => Report::error(format!("Failed to create asset dir {:?}", asset_dir), cause),
Self::AssetDirCreationFailed { asset_dir, cause } => Report::error(format!("Failed to create asset dir {asset_dir:?}"), cause),
Self::CodeCommandPresentFailed(err) => Report::error("Failed to check for presence of `code` command", err),
Self::LldbExtensionInstallFailed(err) => Report::error("Failed to install CodeLLDB extension", err),
Self::DotCargoLoadFailed(err) => err.report(),
@@ -85,7 +85,7 @@ impl Reportable for Error {
#[cfg(target_os = "macos")]
Self::AppleInitFailed(err) => err.report(),
Self::DotCargoWriteFailed(err) => err.report(),
Self::DotFirstInitDeleteFailed { path, cause } => Report::action_request(format!("Failed to delete first init dot file {:?}; the project generated successfully, but `cargo mobile init` will have unexpected results unless you manually delete this file!", path), cause),
Self::DotFirstInitDeleteFailed { path, cause } => Report::action_request(format!("Failed to delete first init dot file {path:?}; the project generated successfully, but `cargo mobile init` will have unexpected results unless you manually delete this file!"), cause),
Self::OpenInEditorFailed(err) => Report::error("Failed to open project in editor (your project generated successfully though, so no worries!)", err),
}
}

View File

@@ -27,8 +27,7 @@ impl Reportable for Error {
Self::TemplatePackResolve(err) => Report::error("Failed to resolve template pack", err),
Self::Processing { src, dest, cause } => Report::error(
format!(
"Base project template processing from src {:?} to dest {:?} failed",
src, dest,
"Base project template processing from src {src:?} to dest {dest:?} failed",
),
cause,
),

View File

@@ -19,8 +19,7 @@ impl Display for FilterError {
match self {
Self::ReadDirFailed { path, cause } => write!(
f,
"App root directory {:?} couldn't be checked for emptiness: {}",
path, cause
"App root directory {path:?} couldn't be checked for emptiness: {cause}"
),
}
}

View File

@@ -60,7 +60,7 @@ fn quote_and_join(
out: &mut dyn Output,
) -> HelperResult {
out.write(
&get_str_array(helper, |s| format!("{:?}", s))
&get_str_array(helper, |s| format!("{s:?}"))
.ok_or_else(|| {
RenderErrorReason::Other("`quote-and-join` helper wasn't given an array".into())
})?
@@ -134,7 +134,7 @@ fn escape_kotlin_keyword(
.split('.')
.map(|s| {
if KOTLIN_ONLY_KEYWORDS.contains(&s) {
format!("`{}`", s)
format!("`{s}`")
} else {
s.to_string()
}

View File

@@ -62,7 +62,7 @@ impl Pack {
let path = {
let dir = dir.as_ref();
let name = name.as_ref();
let toml_path = dir.join(format!("{}.toml", name));
let toml_path = dir.join(format!("{name}.toml"));
let path = dir.join(name);
check_path(name, &toml_path)
.or_else(|| check_path(name, &path))
@@ -137,12 +137,12 @@ pub enum ListError {
impl Display for ListError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoHomeDir(err) => write!(f, "{}", err),
Self::NoHomeDir(err) => write!(f, "{err}"),
Self::DirReadFailed { dir, cause } => {
write!(f, "Failed to read directory {:?}: {}", dir, cause)
write!(f, "Failed to read directory {dir:?}: {cause}")
}
Self::DirEntryReadFailed { dir, cause } => {
write!(f, "Failed to read entry in directory {:?}: {}", dir, cause)
write!(f, "Failed to read entry in directory {dir:?}: {cause}")
}
}
}

View File

@@ -32,21 +32,19 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoHomeDir(err) => write!(f, "{}", err),
Self::NoHomeDir(err) => write!(f, "{err}"),
Self::StatusFailed(err) => {
write!(f, "Failed to check status of `cargo-mobile2` repo: {}", err)
write!(f, "Failed to check status of `cargo-mobile2` repo: {err}")
}
Self::MarkerCreateFailed { path, cause } => {
write!(f, "Failed to create marker file at {:?}: {}", path, cause)
write!(f, "Failed to create marker file at {path:?}: {cause}")
}
Self::UpdateFailed(err) => write!(f, "Failed to update `cargo-mobile2` repo: {err}"),
Self::InstallFailed(err) => {
write!(f, "Failed to install new version of `cargo-mobile2`: {err}")
}
Self::UpdateFailed(err) => write!(f, "Failed to update `cargo-mobile2` repo: {}", err),
Self::InstallFailed(err) => write!(
f,
"Failed to install new version of `cargo-mobile2`: {}",
err
),
Self::MarkerDeleteFailed { path, cause } => {
write!(f, "Failed to delete marker file at {:?}: {}", path, cause)
write!(f, "Failed to delete marker file at {path:?}: {cause}")
}
}
}
@@ -105,7 +103,7 @@ pub fn update(wrapper: &TextWrapper) -> Result<(), Error> {
let details = util::unwrap_either(
repo.latest_subject()
.map(util::format_commit_msg)
.map_err(|err| format!("But we failed to get the latest commit message: {}", err)),
.map_err(|err| format!("But we failed to get the latest commit message: {err}")),
);
Report::victory(msg, details).print(wrapper);
Ok(())

View File

@@ -75,8 +75,8 @@ impl Report {
pub fn new(label: Label, msg: impl Display, details: impl Display) -> Self {
Self {
label,
msg: format!("{}", msg),
details: format!("{}", details),
msg: format!("{msg}"),
details: format!("{details}"),
}
}
@@ -122,9 +122,9 @@ impl Report {
pub fn print(&self, wrapper: &TextWrapper) {
let s = self.format(wrapper);
if matches!(self.label, Label::Error) {
eprint!("{}", s)
eprint!("{s}")
} else {
print!("{}", s)
print!("{s}")
}
}
}
@@ -158,7 +158,7 @@ mod interface {
pub static SETTINGS: &[AppSettings] = &[AppSettings::SubcommandRequiredElseHelp];
pub fn bin_name(name: &str) -> String {
format!("cargo {}", name)
format!("cargo {name}")
}
pub static VERSION_LONG: Lazy<String> = Lazy::new(|| match util::installed_commit_msg() {

View File

@@ -22,19 +22,19 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoHomeDir(err) => write!(f, "{}", err),
Self::FetchFailed(err) => write!(f, "Failed to fetch repo: {}", err),
Self::RevParseLocalFailed(err) => write!(f, "Failed to get checkout revision: {}", err),
Self::NoHomeDir(err) => write!(f, "{err}"),
Self::FetchFailed(err) => write!(f, "Failed to fetch repo: {err}"),
Self::RevParseLocalFailed(err) => write!(f, "Failed to get checkout revision: {err}"),
Self::RevParseRemoteFailed(err) => {
write!(f, "Failed to get upstream revision: {}", err)
write!(f, "Failed to get upstream revision: {err}")
}
Self::LogFailed(err) => write!(f, "Failed to get commit log: {}", err),
Self::LogFailed(err) => write!(f, "Failed to get commit log: {err}"),
Self::ParentDirCreationFailed { path, cause } => {
write!(f, "Failed to create parent directory {:?}: {}", path, cause)
write!(f, "Failed to create parent directory {path:?}: {cause}")
}
Self::CloneFailed(err) => write!(f, "Failed to clone repo: {}", err),
Self::ResetFailed(err) => write!(f, "Failed to reset repo: {}", err),
Self::CleanFailed(err) => write!(f, "Failed to clean repo: {}", err),
Self::CloneFailed(err) => write!(f, "Failed to clone repo: {err}"),
Self::ResetFailed(err) => write!(f, "Failed to reset repo: {err}"),
Self::CleanFailed(err) => write!(f, "Failed to clean repo: {err}"),
}
}
}

View File

@@ -113,7 +113,7 @@ impl Submodule {
fn in_index(&self, git: Git<'_>, name: &str) -> io::Result<bool> {
git.modules().map(|modules| {
modules
.filter(|modules| modules.contains(&format!("[submodule {:?}]", name)))
.filter(|modules| modules.contains(&format!("[submodule {name:?}]")))
.is_some()
})
}
@@ -121,7 +121,7 @@ impl Submodule {
fn initialized(&self, git: Git<'_>, name: &str) -> io::Result<bool> {
git.config().map(|config| {
config
.filter(|config| config.contains(&format!("[submodule {:?}]", name)))
.filter(|config| config.contains(&format!("[submodule {name:?}]")))
.is_some()
})
}

View File

@@ -68,8 +68,8 @@ impl Display for ErrorCause {
Self::MissingFileName => {
write!(f, "Neither the source nor target contained a file name.",)
}
Self::CommandFailed(err) => write!(f, "`ln` command failed: {}", err),
Self::IOError(err) => write!(f, "IO error: {}", err),
Self::CommandFailed(err) => write!(f, "`ln` command failed: {err}"),
Self::IOError(err) => write!(f, "IO error: {err}"),
Self::SymlinkNotAllowed => {
write!(
f,

View File

@@ -37,9 +37,9 @@ pub fn list_display(list: &[impl Display]) -> String {
for (idx, item) in list.iter().enumerate() {
let formatted = if idx + 1 == list.len() {
// this is the last item
format!("and {}", item)
format!("and {item}")
} else {
format!("{}, ", item)
format!("{item}, ")
};
display.push_str(&formatted);
}
@@ -385,7 +385,7 @@ impl Display for RustVersion {
if let Some(flavor) = &self.flavor {
write!(f, "-{}", flavor.flavor)?;
if let Some(candidate) = &flavor.candidate {
write!(f, ".{}", candidate)?;
write!(f, ".{candidate}")?;
}
}
if let Some(details) = &self.details {
@@ -465,7 +465,7 @@ impl RustVersion {
}
pub fn prepend_to_path(path: impl Display, base_path: impl Display) -> String {
format!("{}:{}", path, base_path)
format!("{path}:{base_path}")
}
pub fn command_present(name: &str) -> Result<bool, std::io::Error> {
@@ -483,11 +483,11 @@ pub enum PipeError {
impl Display for PipeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TxCommandFailed(err) => write!(f, "Failed to run sending command: {}", err),
Self::RxCommandFailed(err) => write!(f, "Failed to run receiving command: {}", err),
Self::PipeFailed(err) => write!(f, "Failed to pipe output: {}", err),
Self::TxCommandFailed(err) => write!(f, "Failed to run sending command: {err}"),
Self::RxCommandFailed(err) => write!(f, "Failed to run receiving command: {err}"),
Self::PipeFailed(err) => write!(f, "Failed to pipe output: {err}"),
Self::WaitFailed(err) => {
write!(f, "Failed to wait for receiving command to exit: {}", err)
write!(f, "Failed to wait for receiving command to exit: {err}")
}
}
}
@@ -577,7 +577,7 @@ pub fn installed_commit_msg() -> Result<Option<String>, InstalledCommitMsgError>
}
pub fn format_commit_msg(msg: String) -> String {
format!("Contains commits up to {:?}", msg)
format!("Contains commits up to {msg:?}")
}
pub fn unwrap_either<T>(result: Result<T, T>) -> T {
@@ -650,8 +650,8 @@ impl<T: Debug> Serialize for OneOrMany<T> {
S: Serializer,
{
let serialized_str = match self {
Self::One(one) => format!("{:?}", one),
Self::Many(vec) => format!("{:?}", vec),
Self::One(one) => format!("{one:?}"),
Self::Many(vec) => format!("{vec:?}"),
};
serializer.serialize_str(&serialized_str)
}

View File

@@ -178,16 +178,12 @@ pub enum NormalizationError {
impl Display for NormalizationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CanonicalizationFailed { path, cause } => write!(
f,
"Failed to canonicalize existing path {:?}: {}",
path, cause
),
Self::PathAbsFailed { path, cause } => write!(
f,
"Failed to normalize non-existent path {:?}: {}",
path, cause
),
Self::CanonicalizationFailed { path, cause } => {
write!(f, "Failed to canonicalize existing path {path:?}: {cause}")
}
Self::PathAbsFailed { path, cause } => {
write!(f, "Failed to normalize non-existent path {path:?}: {cause}")
}
}
}
}

View File

@@ -6,7 +6,7 @@ use std::{
pub fn minimal(msg: impl Display) -> io::Result<String> {
let mut input = String::new();
print!("{}: ", msg);
print!("{msg}: ");
io::stdout().flush()?;
io::stdin().read_line(&mut input)?;
@@ -22,7 +22,7 @@ pub fn default(
let msg = if let Some(default_color) = default_color {
format!("{} ({})", msg, default.color(default_color).bold())
} else {
format!("{} ({})", msg, default)
format!("{msg} ({default})")
};
minimal(msg)
} else {
@@ -44,7 +44,7 @@ pub fn yes_no(msg: impl Display, default: Option<bool>) -> io::Result<Option<boo
Some(false) => "[y/N]",
None => "[y/n]",
};
minimal(format!("{} {}", msg, y_n)).map(|response| {
minimal(format!("{msg} {y_n}")).map(|response| {
if response.eq_ignore_ascii_case("y") {
Some(true)
} else if response.eq_ignore_ascii_case("n") {
@@ -75,7 +75,7 @@ pub fn list(
alternative: Option<&str>,
msg: impl Display,
) -> io::Result<usize> {
println!("{}:", header);
println!("{header}:");
let choice_count = choices.len();
list_display_only(choices, choice_count);
if let Some(alternative) = alternative {