Skip to content

Commit 745d02c

Browse files
wuwbobo2021Dirbaio
authored andcommitted
Fix clippy warnings; fix class local reference leaks
1 parent 06c0a37 commit 745d02c

File tree

20 files changed

+63
-50
lines changed

20 files changed

+63
-50
lines changed

java-spaghetti-gen/src/config/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn expand_vars(string: String) -> String {
167167
if let Ok(replacement) = std::env::var(segment) {
168168
buf.push_str(&replacement[..]);
169169
} else {
170-
println!("cargo:rerun-if-env-changed={}", segment);
170+
println!("cargo:rerun-if-env-changed={segment}");
171171
buf.push('%');
172172
buf.push_str(segment);
173173
buf.push('%');

java-spaghetti-gen/src/emit_rust/class_proxy.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::emit_rust::fields::emit_rust_type;
1313
use crate::parser_util::Id;
1414

1515
impl Class {
16+
#[allow(clippy::vec_init_then_push)]
1617
pub(crate) fn write_proxy(&self, context: &Context, methods: &[Method]) -> anyhow::Result<TokenStream> {
1718
let mut emit_reject_reasons = Vec::new();
1819

@@ -204,7 +205,7 @@ fn mangle_native_method(path: &str, name: &str, args: &[FieldDescriptor]) -> Str
204205
let mut res = String::new();
205206
res.push_str("Java_");
206207
res.push_str(&mangle_native(path));
207-
res.push_str("_");
208+
res.push('_');
208209
res.push_str(&mangle_native(name));
209210
res.push_str("__");
210211
for d in args {
@@ -219,7 +220,7 @@ fn mangle_native(s: &str) -> String {
219220
for c in s.chars() {
220221
match c {
221222
'0'..='9' | 'a'..='z' | 'A'..='Z' => res.push(c),
222-
'/' => res.push_str("_"),
223+
'/' => res.push('_'),
223224
'_' => res.push_str("_1"),
224225
';' => res.push_str("_2"),
225226
'[' => res.push_str("_3"),

java-spaghetti-gen/src/emit_rust/classes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ impl Class {
114114
};
115115

116116
let docs = match KnownDocsUrl::from_class(context, self.java.path()) {
117-
Some(url) => format!("{} {} {}", visibility, keyword, url),
118-
None => format!("{} {} {}", visibility, keyword, self.java.path().as_str()),
117+
Some(url) => format!("{visibility} {keyword} {url}"),
118+
None => format!("{visibility} {keyword} {}", self.java.path().as_str()),
119119
};
120120

121121
let rust_name = format_ident!("{}", &self.rust.struct_name);
@@ -235,7 +235,7 @@ impl Class {
235235

236236
out.extend(quote!(impl #rust_name { #contents }));
237237

238-
if context.proxy_included(&self.java.path().as_str()) {
238+
if context.proxy_included(self.java.path().as_str()) {
239239
out.extend(self.write_proxy(context, &methods)?);
240240
}
241241

java-spaghetti-gen/src/emit_rust/fields.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a> Field<'a> {
120120
match self.rust_names.as_ref().map_err(|e| anyhow!("bad mangling: {e}"))? {
121121
FieldMangling::ConstValue(constant, value) => {
122122
let constant = format_ident!("{}", constant);
123-
let value = emit_constant(&value, descriptor);
123+
let value = emit_constant(value, descriptor);
124124
let ty = if descriptor.dimensions == 0
125125
&& let FieldType::Object(cls) = &descriptor.field_type
126126
&& Id::from(cls).is_string_class()
@@ -208,14 +208,14 @@ pub fn emit_constant(constant: &LiteralConstant<'_>, descriptor: &FieldDescripto
208208
let value = *value as i16;
209209
quote!(#value)
210210
}
211-
_ => panic!("invalid constant for char {:?}", constant),
211+
_ => panic!("invalid constant for char {constant:?}"),
212212
};
213213
}
214214
if descriptor.field_type == FieldType::Boolean && descriptor.dimensions == 0 {
215215
return match constant {
216216
LiteralConstant::Integer(0) => quote!(false),
217217
LiteralConstant::Integer(1) => quote!(true),
218-
_ => panic!("invalid constant for boolean {:?}", constant),
218+
_ => panic!("invalid constant for boolean {constant:?}"),
219219
};
220220
}
221221

java-spaghetti-gen/src/emit_rust/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> Method<'a> {
147147

148148
let docs = match KnownDocsUrl::from_method(context, self) {
149149
Some(url) => format!("{url}"),
150-
None => format!("{}", self.java.name()),
150+
None => self.java.name().to_string(),
151151
};
152152

153153
let throwable = context.throwable_rust_path(mod_);

java-spaghetti-gen/src/emit_rust/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a> Context<'a> {
5252
pub fn java_to_rust_path(&self, java_class: parser_util::Id, mod_: &str) -> Result<TokenStream, Box<dyn Error>> {
5353
let m = Class::mod_for(self, java_class)?;
5454
let s = Class::name_for(self, java_class)?;
55-
let fqn = format!("{}::{}", m, s);
55+
let fqn = format!("{m}::{s}");
5656

5757
// Calculate relative path from B to A.
5858
let b: Vec<&str> = mod_.split("::").collect();

java-spaghetti-gen/src/emit_rust/modules.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ impl Module {
2121
for (name, module) in self.modules.iter() {
2222
writeln!(out)?;
2323

24-
writeln!(out, "pub mod {} {{", name)?;
24+
writeln!(out, "pub mod {name} {{")?;
2525
module.write(context, out)?;
2626
writeln!(out, "}}")?;
2727
}
2828

2929
for (_, class) in self.classes.iter() {
3030
let res = class.write(context)?;
31-
out.write(dumb_format(res).as_bytes())?;
31+
out.write_all(dumb_format(res).as_bytes())?;
3232
}
3333

3434
Ok(())
@@ -61,7 +61,7 @@ struct DumbFormatter {
6161

6262
impl DumbFormatter {
6363
fn newline(&mut self) {
64-
self.f.push_str("\n");
64+
self.f.push('\n');
6565
for _ in 0..self.indent {
6666
self.f.push_str(" ");
6767
}
@@ -71,7 +71,7 @@ impl DumbFormatter {
7171

7272
fn pre_write(&mut self) {
7373
if self.space && !self.after_newline {
74-
self.f.push_str(" ");
74+
self.f.push(' ');
7575
}
7676
self.space = false;
7777
self.after_newline = false;

java-spaghetti-gen/src/run/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Core generation logic
22
3+
// XXX: rename this submodule
4+
#[allow(clippy::module_inception)]
35
mod run;
46

57
pub use run::run;

java-spaghetti-gen/src/run/run.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ fn gather_file(context: &mut emit_rust::Context, path: &Path) -> Result<(), Box<
7676
unknown => {
7777
Err(io::Error::new(
7878
io::ErrorKind::InvalidInput,
79-
format!(
80-
"Input files must have a '.class' or '.jar' extension, not a '.{}' extension",
81-
unknown
82-
),
79+
format!("Input files must have a '.class' or '.jar' extension, not a '.{unknown}' extension",),
8380
))?;
8481
}
8582
}

java-spaghetti-gen/src/util/progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Progress {
1919

2020
pub fn force_update(&mut self, msg: &str) {
2121
self.can_next_log = Instant::now() + self.debounce;
22-
println!("{}", msg);
22+
println!("{msg}");
2323
}
2424

2525
pub fn update(&mut self, msg: &str) {

0 commit comments

Comments
 (0)