Skip to content

Commit

Permalink
Run cargo clippy --fix in the sway repo (FuelLabs#3903)
Browse files Browse the repository at this point in the history
Co-authored-by: Sophie <[email protected]>
  • Loading branch information
nfurfaro and sdankel authored Jan 26, 2023
1 parent dd95780 commit ed1bc39
Show file tree
Hide file tree
Showing 90 changed files with 400 additions and 427 deletions.
10 changes: 5 additions & 5 deletions forc-pkg/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn pkg_name_disambiguated<'a>(name: &'a str, source: &'a str, disambiguate: bool
}

fn pkg_unique_string(name: &str, source: &str) -> String {
format!("{} {}", name, source)
format!("{name} {source}")
}

fn pkg_dep_line(
Expand All @@ -282,7 +282,7 @@ fn pkg_dep_line(
// Prefix the dependency name if it differs from the package name.
let pkg_string = match dep_name {
None => pkg_string.into_owned(),
Some(dep_name) => format!("({}) {}", dep_name, pkg_string),
Some(dep_name) => format!("({dep_name}) {pkg_string}"),
};
// Append the salt if dep_kind is DepKind::Contract.
match dep_kind {
Expand All @@ -291,7 +291,7 @@ fn pkg_dep_line(
if *salt == fuel_tx::Salt::zeroed() {
pkg_string
} else {
format!("{} ({})", pkg_string, salt)
format!("{pkg_string} ({salt})")
}
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ where
for pkg in removed {
if !member_names.contains(&pkg.name) {
let name = name_or_git_unique_string(pkg);
println_red(&format!(" Removing {}", name));
println_red(&format!(" Removing {name}"));
}
}
}
Expand All @@ -362,7 +362,7 @@ where
for pkg in removed {
if !member_names.contains(&pkg.name) {
let name = name_or_git_unique_string(pkg);
println_green(&format!(" Adding {}", name));
println_green(&format!(" Adding {name}"));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl PackageManifest {
.map_err(|e| anyhow!("failed to read manifest at {:?}: {}", path, e))?;
let toml_de = &mut toml::de::Deserializer::new(&manifest_str);
let mut manifest: Self = serde_ignored::deserialize(toml_de, |path| {
let warning = format!(" WARNING! unused manifest key: {}", path);
let warning = format!(" WARNING! unused manifest key: {path}");
warnings.push(warning);
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
Expand Down Expand Up @@ -810,7 +810,7 @@ impl WorkspaceManifest {
.map_err(|e| anyhow!("failed to read manifest at {:?}: {}", path, e))?;
let toml_de = &mut toml::de::Deserializer::new(&manifest_str);
let manifest: Self = serde_ignored::deserialize(toml_de, |path| {
let warning = format!(" WARNING! unused manifest key: {}", path);
let warning = format!(" WARNING! unused manifest key: {path}");
warnings.push(warning);
})
.map_err(|e| anyhow!("failed to parse manifest: {}.", e))?;
Expand Down Expand Up @@ -850,7 +850,7 @@ impl WorkspaceManifest {
let duplicate_paths = pkg_name_to_paths
.get(pkg_name)
.expect("missing duplicate paths");
format!("{}: {:#?}", pkg_name, duplicate_paths)
format!("{pkg_name}: {duplicate_paths:#?}")
})
.collect::<Vec<_>>();

Expand Down
52 changes: 23 additions & 29 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl BuiltPackage {

self.write_bytecode(&bin_path)?;

let json_abi_program_stem = format!("{}-abi", pkg_name);
let json_abi_program_stem = format!("{pkg_name}-abi");
let json_abi_program_path = output_dir
.join(json_abi_program_stem)
.with_extension("json");
Expand Down Expand Up @@ -471,7 +471,7 @@ impl BuiltPackage {
match self.tree_type {
TreeType::Contract => {
// For contracts, emit a JSON file with all the initialized storage slots.
let json_storage_slots_stem = format!("{}-storage_slots", pkg_name);
let json_storage_slots_stem = format!("{pkg_name}-storage_slots");
let json_storage_slots_path = output_dir
.join(json_storage_slots_stem)
.with_extension("json");
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl GitReference {
pub fn resolve(&self, repo: &git2::Repository) -> Result<git2::Oid> {
// Find the commit associated with this tag.
fn resolve_tag(repo: &git2::Repository, tag: &str) -> Result<git2::Oid> {
let refname = format!("refs/remotes/{}/tags/{}", DEFAULT_REMOTE_NAME, tag);
let refname = format!("refs/remotes/{DEFAULT_REMOTE_NAME}/tags/{tag}");
let id = repo.refname_to_id(&refname)?;
let obj = repo.find_object(id, None)?;
let obj = obj.peel(git2::ObjectType::Commit)?;
Expand All @@ -1077,10 +1077,10 @@ impl GitReference {

// Resolve to the target for the given branch.
fn resolve_branch(repo: &git2::Repository, branch: &str) -> Result<git2::Oid> {
let name = format!("{}/{}", DEFAULT_REMOTE_NAME, branch);
let name = format!("{DEFAULT_REMOTE_NAME}/{branch}");
let b = repo
.find_branch(&name, git2::BranchType::Remote)
.with_context(|| format!("failed to find branch `{}`", branch))?;
.with_context(|| format!("failed to find branch `{branch}`"))?;
b.get()
.target()
.ok_or_else(|| anyhow::format_err!("branch `{}` did not have a target", branch))
Expand All @@ -1089,7 +1089,7 @@ impl GitReference {
// Use the HEAD commit when default branch is specified.
fn resolve_default_branch(repo: &git2::Repository) -> Result<git2::Oid> {
let head_id =
repo.refname_to_id(&format!("refs/remotes/{}/HEAD", DEFAULT_REMOTE_NAME))?;
repo.refname_to_id(&format!("refs/remotes/{DEFAULT_REMOTE_NAME}/HEAD"))?;
let head = repo.find_object(head_id, None)?;
Ok(head.peel(git2::ObjectType::Commit)?.id())
}
Expand All @@ -1105,7 +1105,7 @@ impl GitReference {

match self {
GitReference::Tag(s) => {
resolve_tag(repo, s).with_context(|| format!("failed to find tag `{}`", s))
resolve_tag(repo, s).with_context(|| format!("failed to find tag `{s}`"))
}
GitReference::Branch(s) => resolve_branch(repo, s),
GitReference::DefaultBranch => resolve_default_branch(repo),
Expand Down Expand Up @@ -1184,8 +1184,8 @@ impl fmt::Display for SourceGitPinned {
impl fmt::Display for GitReference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
GitReference::Branch(ref s) => write!(f, "branch={}", s),
GitReference::Tag(ref s) => write!(f, "tag={}", s),
GitReference::Branch(ref s) => write!(f, "branch={s}"),
GitReference::Tag(ref s) => write!(f, "tag={s}"),
GitReference::Rev(ref _s) => write!(f, "rev"),
GitReference::DefaultBranch => write!(f, "default-branch"),
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ fn fetch_deps(
/// The name to use for a package's git repository under the user's forc directory.
fn git_repo_dir_name(name: &str, repo: &Url) -> String {
let repo_url_hash = hash_url(repo);
format!("{}-{:x}", name, repo_url_hash)
format!("{name}-{repo_url_hash:x}")
}

fn hash_url(url: &Url) -> u64 {
Expand Down Expand Up @@ -1702,32 +1702,29 @@ fn git_ref_to_refspecs(reference: &GitReference) -> (Vec<String>, bool) {
match reference {
GitReference::Branch(s) => {
refspecs.push(format!(
"+refs/heads/{1}:refs/remotes/{0}/{1}",
DEFAULT_REMOTE_NAME, s
"+refs/heads/{s}:refs/remotes/{DEFAULT_REMOTE_NAME}/{s}"
));
}
GitReference::Tag(s) => {
refspecs.push(format!(
"+refs/tags/{1}:refs/remotes/{0}/tags/{1}",
DEFAULT_REMOTE_NAME, s
"+refs/tags/{s}:refs/remotes/{DEFAULT_REMOTE_NAME}/tags/{s}"
));
}
GitReference::Rev(s) => {
if s.starts_with("refs/") {
refspecs.push(format!("+{0}:{0}", s));
refspecs.push(format!("+{s}:{s}"));
} else {
// We can't fetch the commit directly, so we fetch all branches and tags in order
// to find it.
refspecs.push(format!(
"+refs/heads/*:refs/remotes/{}/*",
DEFAULT_REMOTE_NAME
"+refs/heads/*:refs/remotes/{DEFAULT_REMOTE_NAME}/*"
));
refspecs.push(format!("+HEAD:refs/remotes/{}/HEAD", DEFAULT_REMOTE_NAME));
refspecs.push(format!("+HEAD:refs/remotes/{DEFAULT_REMOTE_NAME}/HEAD"));
tags = true;
}
}
GitReference::DefaultBranch => {
refspecs.push(format!("+HEAD:refs/remotes/{}/HEAD", DEFAULT_REMOTE_NAME));
refspecs.push(format!("+HEAD:refs/remotes/{DEFAULT_REMOTE_NAME}/HEAD"));
}
}
(refspecs, tags)
Expand Down Expand Up @@ -1785,7 +1782,7 @@ pub fn pin_git(fetch_id: u64, name: &str, source: SourceGit) -> Result<SourceGit
.reference
.resolve(&repo)
.with_context(|| "failed to resolve reference".to_string())?;
Ok(format!("{}", commit_id))
Ok(format!("{commit_id}"))
})?;
Ok(SourceGitPinned {
source,
Expand Down Expand Up @@ -1943,8 +1940,8 @@ fn fd_lock_path(path: &Path) -> PathBuf {
path.hash(&mut hasher);
let hash = hasher.finish();
let file_name = match path.file_stem().and_then(|s| s.to_str()) {
None => format!("{:X}", hash),
Some(stem) => format!("{:X}-{}", hash, stem),
None => format!("{hash:X}"),
Some(stem) => format!("{hash:X}-{stem}"),
};

user_forc_directory()
Expand Down Expand Up @@ -3293,10 +3290,10 @@ pub fn manifest_file_missing(dir: &Path) -> anyhow::Error {
pub fn parsing_failed(project_name: &str, errors: Vec<CompileError>) -> anyhow::Error {
let error = errors
.iter()
.map(|e| format!("{}", e))
.map(|e| format!("{e}"))
.collect::<Vec<String>>()
.join("\n");
let message = format!("Parsing {} failed: \n{}", project_name, error);
let message = format!("Parsing {project_name} failed: \n{error}");
Error::msg(message)
}

Expand All @@ -3306,15 +3303,12 @@ pub fn wrong_program_type(
expected_types: Vec<TreeType>,
parse_type: TreeType,
) -> anyhow::Error {
let message = format!(
"{} is not a '{:?}' it is a '{:?}'",
project_name, expected_types, parse_type
);
let message = format!("{project_name} is not a '{expected_types:?}' it is a '{parse_type:?}'");
Error::msg(message)
}

/// Format an error message if a given URL fails to produce a working node.
pub fn fuel_core_not_running(node_url: &str) -> anyhow::Error {
let message = format!("could not get a response from node at the URL {}. Start a node with `fuel-core`. See https://github.com/FuelLabs/fuel-core#running for more information", node_url);
let message = format!("could not get a response from node at the URL {node_url}. Start a node with `fuel-core`. See https://github.com/FuelLabs/fuel-core#running for more information");
Error::msg(message)
}
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/ops/tx_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn prompt_address() -> Result<Bech32Address> {
}

fn prompt_signature(tx_id: fuel_tx::Bytes32) -> Result<Signature> {
println!("Transaction id to sign: {}", tx_id);
println!("Transaction id to sign: {tx_id}");
print!("Please provide the signature:");
std::io::stdout().flush()?;
let mut buf = String::new();
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-doc/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl ModuleInfo {
let prefix = self.to_path_literal_prefix(location);
match prefix.is_empty() {
true => item_name.to_owned(),
false => format!("{}::{}", prefix, item_name),
false => format!("{prefix}::{item_name}"),
}
}
/// Create a path literal prefix from the module prefixes.
Expand Down
16 changes: 8 additions & 8 deletions forc-plugins/forc-doc/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Renderable for ItemBody {
span(class="in-band") {
// TODO: pass the decl ty info or match
// for uppercase naming like: "Enum"
: format!("{} ", friendly_name);
: format!("{friendly_name} ");
// TODO: add qualified path anchors
a(class=&decl_ty, href=IDENTITY) {
: item_name.as_str();
Expand Down Expand Up @@ -555,7 +555,7 @@ fn context_section<'title, S: Renderable + 'static>(
box_html! {
h2(id=&lct, class=format!("{} small-section-header", &lct)) {
: title.as_str();
a(class="anchor", href=format!("{}{}", IDENTITY, lct));
a(class="anchor", href=format!("{IDENTITY}{lct}"));
}
@ for item in list {
// TODO: Check for visibility of the field itself
Expand All @@ -568,7 +568,7 @@ impl Renderable for TyStructField {
let struct_field_id = format!("structfield.{}", self.name.as_str());
box_html! {
span(id=&struct_field_id, class="structfield small-section-header") {
a(class="anchor field", href=format!("{}{}", IDENTITY, struct_field_id));
a(class="anchor field", href=format!("{IDENTITY}{struct_field_id}"));
code {
: format!("{}: ", self.name.as_str());
// TODO: Add links to types based on visibility
Expand All @@ -588,7 +588,7 @@ impl Renderable for TyStorageField {
let storage_field_id = format!("storagefield.{}", self.name.as_str());
box_html! {
span(id=&storage_field_id, class="storagefield small-section-header") {
a(class="anchor field", href=format!("{}{}", IDENTITY, storage_field_id));
a(class="anchor field", href=format!("{IDENTITY}{storage_field_id}"));
code {
: format!("{}: ", self.name.as_str());
// TODO: Add links to types based on visibility
Expand All @@ -608,7 +608,7 @@ impl Renderable for TyEnumVariant {
let enum_variant_id = format!("variant.{}", self.name.as_str());
box_html! {
h3(id=&enum_variant_id, class="variant small-section-header") {
a(class="anchor field", href=format!("{}{}", IDENTITY, enum_variant_id));
a(class="anchor field", href=format!("{IDENTITY}{enum_variant_id}"));
code {
: format!("{}: ", self.name.as_str());
: self.type_span.as_str();
Expand Down Expand Up @@ -660,7 +660,7 @@ impl Renderable for TyTraitFn {
div(id=&method_id, class="method has-srclink") {
h4(class="code-header") {
: "fn ";
a(class="fnname", href=format!("{}{}", IDENTITY, method_id)) {
a(class="fnname", href=format!("{IDENTITY}{method_id}")) {
: self.name.as_str();
}
: "(";
Expand Down Expand Up @@ -1111,7 +1111,7 @@ impl Renderable for Sidebar {
let (logo_path_to_parent, path_to_parent_or_self) = match &self.style {
DocStyle::AllDoc | DocStyle::Item => (self.href_path.clone(), self.href_path.clone()),
DocStyle::ProjectIndex => (IDENTITY.to_owned(), IDENTITY.to_owned()),
DocStyle::ModuleIndex => (format!("../{}", INDEX_FILENAME), IDENTITY.to_owned()),
DocStyle::ModuleIndex => (format!("../{INDEX_FILENAME}"), IDENTITY.to_owned()),
};
// Unfortunately, match arms that return a closure, even if they are the same
// type, are incompatible. The work around is to return a String instead,
Expand All @@ -1128,7 +1128,7 @@ impl Renderable for Sidebar {
div(class="block") {
ul {
li(class="version") {
: format!("Version {}", version);
: format!("Version {version}");
}
li {
a(id="all-types", href=ALL_DOC_FILENAME) {
Expand Down
8 changes: 4 additions & 4 deletions forc-plugins/forc-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ fn display_file_diff(file_content: &str, formatted_content: &str) -> Result<()>
DiffOp::Insert(new) => {
count_of_updates += 1;
for n in new {
println_green(&format!("+{}", n));
println_green(&format!("+{n}"));
}
}
DiffOp::Remove(old) => {
count_of_updates += 1;
for o in old {
println_red(&format!("-{}", o));
println_red(&format!("-{o}"));
}
}
DiffOp::Replace(old, new) => {
count_of_updates += 1;
for o in old {
println_red(&format!("-{}", o));
println_red(&format!("-{o}"));
}
for n in new {
println_green(&format!("+{}", n));
println_green(&format!("+{n}"));
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions forc-plugins/forc-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,8 @@ fn test_parse_mint_coin() {
let asset_id = fuel_tx::AssetId::default();
let cmd = format!(
r#"
forc-tx mint --tx-ptr {:X} output coin --to {address} --amount 100 --asset-id {asset_id}
"#,
tx_ptr
forc-tx mint --tx-ptr {tx_ptr:X} output coin --to {address} --amount 100 --asset-id {asset_id}
"#
);
dbg!(Command::try_parse_from_args(cmd.split_whitespace().map(|s| s.to_string())).unwrap());
}
Expand Down Expand Up @@ -677,7 +676,7 @@ fn test_parse_create_inputs_outputs() {
--owner {address}
--amount 100
--asset-id {asset_id}
--tx-ptr {:X}
--tx-ptr {tx_ptr:X}
--witness-ix 0
--maturity 0
--predicate ./my-predicate/out/debug/my-predicate.bin
Expand All @@ -687,7 +686,7 @@ fn test_parse_create_inputs_outputs() {
--output-ix 1
--balance-root {balance_root}
--state-root {state_root}
--tx-ptr {:X}
--tx-ptr {tx_ptr:X}
--contract-id {contract_id}
input message
--msg-id {msg_id}
Expand Down Expand Up @@ -721,8 +720,7 @@ fn test_parse_create_inputs_outputs() {
output contract-created
--contract-id {contract_id}
--state-root {state_root}
"#,
tx_ptr, tx_ptr
"#
);
dbg!(Command::try_parse_from_args(args.split_whitespace().map(|s| s.to_string())).unwrap());
}
Loading

0 comments on commit ed1bc39

Please sign in to comment.