Skip to content

Commit 9fe73cf

Browse files
committed
clippy fixes
1 parent c6edc32 commit 9fe73cf

9 files changed

Lines changed: 31 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/increment/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn withdraw_rewards(
147147
pub fn reply(deps: DepsMut<ArchwayQuery>, env: Env, msg: Reply) -> StdResult<Response> {
148148
match msg.id {
149149
STAKE_WITHDRAWN_REWARDS => stake_contract_rewards(deps, env, msg),
150-
id => Err(StdError::not_found(format!("Unknown reply id: {}", id))),
150+
id => Err(StdError::not_found(format!("Unknown reply id: {id}"))),
151151
}
152152
}
153153

proto-build/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ publish = false
1313
syn = { version = "2.0", features = ["full", "extra-traits"] }
1414
quote = "1.0.36"
1515
proc-macro2 = "1.0"
16-
error-chain = "0.12.4"
16+
thiserror = { workspace = true }
1717
glob = "0.3.1"
1818
regex = "1.9.3"

proto-build/src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use thiserror::Error;
2+
3+
pub type Result<T> = std::result::Result<T, Error>;
4+
5+
#[derive(Error, Debug)]
6+
pub enum Error {
7+
#[error("{0}")]
8+
Io(#[from] std::io::Error),
9+
#[error("{0}")]
10+
Glob(#[from] glob::GlobError),
11+
#[error("{0}")]
12+
Pattern(#[from] glob::PatternError),
13+
#[error("{0}")]
14+
Utf8Error(#[from] std::str::Utf8Error),
15+
}

proto-build/src/main.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
mod commands;
22
mod consts;
3+
mod error;
34
mod parser;
45
mod utils;
56

7+
pub use error::Result;
8+
use std::path::Path;
69
use std::path::PathBuf;
7-
use std::{io, path::Path};
810

911
use crate::commands::apply_patches::apply_patches;
1012
use crate::commands::cleanup::cleanup;
@@ -16,16 +18,6 @@ use crate::commands::update_submodules::update_submodules;
1618
use crate::consts::{OUT_DIR, PROTO_DIR};
1719
use crate::parser::generate_advanced_struct;
1820
use crate::utils::run::run_cargo;
19-
use error_chain::error_chain;
20-
21-
error_chain! {
22-
foreign_links {
23-
IoError(io::Error);
24-
Glob(glob::GlobError);
25-
Pattern(glob::PatternError);
26-
Utf8Error(std::str::Utf8Error);
27-
}
28-
}
2921

3022
fn workspace_root() -> PathBuf {
3123
let output = run_cargo(["locate-project", "--workspace", "--message-format=plain"]).unwrap();

proto-build/src/parser/commands/load_and_patch_any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn load_and_patch_any(out_dir: &Path) -> BTreeMap<String, (File, BTreeMap<St
5656
ast.items.pop();
5757
}
5858

59-
let file_name = src.to_str().unwrap().split('/').last().unwrap();
59+
let file_name = src.to_str().unwrap().split('/').next_back().unwrap();
6060
project_tokens.insert(file_name.to_string(), (ast, structs));
6161
}
6262

proto-build/src/parser/commands/save.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@ use std::path::Path;
77
use syn::File;
88

99
pub fn save(out_dir: &Path, files: &BTreeMap<String, (File, BTreeMap<String, usize>)>) {
10+
let file_regex = Regex::new(r"(\.[[:alnum:]]+\.)rs").unwrap();
11+
let patch_regex = Regex::new(r"(\.)").unwrap();
12+
1013
for (file, (data, _)) in files.iter() {
1114
// Patch the mod file
12-
let file_regex = Regex::new(r"(\.[[:alnum:]]+\.)rs").unwrap();
1315
let new_file = file_regex.replace(file, "${1}abstract.rs").to_string();
1416

1517
patch_file(
1618
&out_dir.join("mod.rs"),
1719
&[(
18-
&format!(
19-
r"include!\(.{}.\);",
20-
Regex::new(r"(\.)").unwrap().replace(file, r"\.")
21-
),
20+
&format!(r"include!\(.{}.\);", patch_regex.replace(file, r"\.")),
2221
&format!(
2322
"\
2423
#[cfg(not(feature = \"abstract-any\"))]\n\
25-
include!(\"{}\");\n\
24+
include!(\"{file}\");\n\
2625
#[cfg(feature = \"abstract-any\")]\n\
27-
include!(\"{}\");\
28-
",
29-
file, new_file
26+
include!(\"{new_file}\");\
27+
"
3028
),
3129
)],
3230
)

proto-build/src/utils/patch_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn patch_file(path: &Path, replacements: &[(&str, &str)]) -> io::Result<()>
77

88
for &(regex, replacement) in replacements {
99
contents = Regex::new(regex)
10-
.unwrap_or_else(|_| panic!("invalid regex: {}", regex))
10+
.unwrap_or_else(|_| panic!("invalid regex: {regex}"))
1111
.replace_all(&contents, replacement)
1212
.to_string();
1313
}

proto-build/src/utils/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn run_buf_export(
1515
proto: &str,
1616
export_dir: &Path,
1717
) -> crate::Result<String> {
18-
println!("Exporting {}...", proto);
18+
println!("Exporting {proto}...");
1919
let proto_path = submodules_dir.join(proto).join("proto");
2020
run_cmd(
2121
"buf",

0 commit comments

Comments
 (0)