Skip to content

Commit e6afecb

Browse files
authored
chore(clippy): Fix clippy warnings. (#228)
1 parent 0b27dc3 commit e6afecb

File tree

9 files changed

+31
-37
lines changed

9 files changed

+31
-37
lines changed

build.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait PHPProvider<'a>: Sized {
3131
/// Writes the bindings to a file.
3232
fn write_bindings(&self, bindings: String, writer: &mut impl Write) -> Result<()> {
3333
for line in bindings.lines() {
34-
writeln!(writer, "{}", line)?;
34+
writeln!(writer, "{line}")?;
3535
}
3636
Ok(())
3737
}
@@ -126,7 +126,7 @@ impl PHPInfo {
126126
}
127127

128128
fn get_key(&self, key: &str) -> Option<&str> {
129-
let split = format!("{} => ", key);
129+
let split = format!("{key} => ");
130130
for line in self.0.lines() {
131131
let components: Vec<_> = line.split(&split).collect();
132132
if components.len() > 1 {
@@ -160,11 +160,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
160160
.iter()
161161
.map(|inc| format!("-I{}", inc.to_string_lossy())),
162162
)
163-
.clang_args(
164-
defines
165-
.iter()
166-
.map(|(var, val)| format!("-D{}={}", var, val)),
167-
)
163+
.clang_args(defines.iter().map(|(var, val)| format!("-D{var}={val}")))
168164
.rustfmt_bindings(true)
169165
.no_copy("_zval_struct")
170166
.no_copy("_zend_string")
@@ -237,7 +233,7 @@ fn main() -> Result<()> {
237233
println!("cargo:rerun-if-changed={}", path.to_string_lossy());
238234
}
239235
for env_var in ["PHP", "PHP_CONFIG", "PATH"] {
240-
println!("cargo:rerun-if-env-changed={}", env_var);
236+
println!("cargo:rerun-if-env-changed={env_var}");
241237
}
242238

243239
println!("cargo:rerun-if-changed=build.rs");

crates/cli/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use dialoguer::{Confirm, Select};
1010

1111
use std::{
1212
fs::OpenOptions,
13-
io::{BufRead, BufReader, Seek, SeekFrom, Write},
13+
io::{BufRead, BufReader, Seek, Write},
1414
path::PathBuf,
1515
process::{Command, Stdio},
1616
};
@@ -207,7 +207,7 @@ impl Install {
207207
.open(php_ini)
208208
.with_context(|| "Failed to open `php.ini`")?;
209209

210-
let mut ext_line = format!("extension={}", ext_name);
210+
let mut ext_line = format!("extension={ext_name}");
211211

212212
let mut new_lines = vec![];
213213
for line in BufReader::new(&file).lines() {
@@ -225,7 +225,7 @@ impl Install {
225225
}
226226

227227
new_lines.push(ext_line);
228-
file.seek(SeekFrom::Start(0))?;
228+
file.rewind()?;
229229
file.set_len(0)?;
230230
file.write(new_lines.join("\n").as_bytes())
231231
.with_context(|| "Failed to update `php.ini`")?;
@@ -255,9 +255,8 @@ fn get_ext_dir() -> AResult<PathBuf> {
255255
ext_dir
256256
);
257257
} else {
258-
std::fs::create_dir(&ext_dir).with_context(|| {
259-
format!("Failed to create extension directory at {:?}", ext_dir)
260-
})?;
258+
std::fs::create_dir(&ext_dir)
259+
.with_context(|| format!("Failed to create extension directory at {ext_dir:?}"))?;
261260
}
262261
}
263262
Ok(ext_dir)
@@ -341,7 +340,7 @@ impl Remove {
341340
}
342341
}
343342

344-
file.seek(SeekFrom::Start(0))?;
343+
file.rewind()?;
345344
file.set_len(0)?;
346345
file.write(new_lines.join("\n").as_bytes())
347346
.with_context(|| "Failed to update `php.ini`")?;
@@ -389,7 +388,7 @@ impl Stubs {
389388
.with_context(|| "Failed to generate stubs.")?;
390389

391390
if self.stdout {
392-
print!("{}", stubs);
391+
print!("{stubs}");
393392
} else {
394393
let out_path = if let Some(out_path) = &self.out {
395394
Cow::Borrowed(out_path)

crates/macros/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn parser(args: AttributeArgs, input: ItemFn) -> Result<(TokenStream, Functi
5252
..
5353
} = &sig;
5454

55-
let internal_ident = Ident::new(&format!("_internal_php_{}", ident), Span::call_site());
55+
let internal_ident = Ident::new(&format!("_internal_php_{ident}"), Span::call_site());
5656
let args = build_args(inputs, &attr_args.defaults)?;
5757
let optional = find_optional_parameter(args.iter(), attr_args.optional);
5858
let arg_definitions = build_arg_definitions(&args);

crates/macros/src/method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn parser(
136136
} else {
137137
quote! { return; }
138138
};
139-
let internal_ident = Ident::new(&format!("_internal_php_{}", ident), Span::call_site());
139+
let internal_ident = Ident::new(&format!("_internal_php_{ident}"), Span::call_site());
140140
let args = build_args(struct_ty, &mut input.sig.inputs, &defaults)?;
141141
let optional = function::find_optional_parameter(
142142
args.iter().filter_map(|arg| match arg {

crates/macros/src/startup_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn build_classes(classes: &HashMap<String, Class>) -> Result<Vec<TokenStream>> {
6868
.map(|(name, class)| {
6969
let Class { class_name, .. } = &class;
7070
let ident = Ident::new(name, Span::call_site());
71-
let meta = Ident::new(&format!("_{}_META", name), Span::call_site());
71+
let meta = Ident::new(&format!("_{name}_META"), Span::call_site());
7272
let methods = class.methods.iter().map(|method| {
7373
let builder = method.get_builder(&ident);
7474
let flags = method.get_flags();

src/describe/stub.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl ToStub for Module {
8484
.map(|(ns, entries)| {
8585
let mut buf = String::new();
8686
if let Some(ns) = ns {
87-
writeln!(buf, "namespace {} {{", ns)?;
87+
writeln!(buf, "namespace {ns} {{")?;
8888
} else {
8989
writeln!(buf, "namespace {{")?;
9090
}
@@ -183,7 +183,7 @@ impl ToStub for DocBlock {
183183
if !self.0.is_empty() {
184184
writeln!(buf, "/**")?;
185185
for comment in self.0.iter() {
186-
writeln!(buf, " *{}", comment)?;
186+
writeln!(buf, " *{comment}")?;
187187
}
188188
writeln!(buf, " */")?;
189189
}
@@ -196,10 +196,10 @@ impl ToStub for Class {
196196
self.docs.fmt_stub(buf)?;
197197

198198
let (_, name) = split_namespace(self.name.as_ref());
199-
write!(buf, "class {} ", name)?;
199+
write!(buf, "class {name} ")?;
200200

201201
if let Option::Some(extends) = &self.extends {
202-
write!(buf, "extends {} ", extends)?;
202+
write!(buf, "extends {extends} ")?;
203203
}
204204

205205
if !self.implements.is_empty() {
@@ -249,7 +249,7 @@ impl ToStub for Property {
249249
}
250250
write!(buf, "${}", self.name)?;
251251
if let Option::Some(default) = &self.default {
252-
write!(buf, " = {}", default)?;
252+
write!(buf, " = {default}")?;
253253
}
254254
writeln!(buf, ";")
255255
}
@@ -311,7 +311,7 @@ impl ToStub for Constant {
311311

312312
write!(buf, "const {} = ", self.name)?;
313313
if let Option::Some(value) = &self.value {
314-
write!(buf, "{}", value)?;
314+
write!(buf, "{value}")?;
315315
} else {
316316
write!(buf, "null")?;
317317
}
@@ -381,6 +381,7 @@ mod test {
381381

382382
#[test]
383383
#[cfg(not(windows))]
384+
#[allow(clippy::uninlined_format_args)]
384385
pub fn test_indent() {
385386
use super::indent;
386387
use crate::describe::stub::NEW_LINE_SEPARATOR;

src/error.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ impl Display for Error {
6565
match self {
6666
Error::IncorrectArguments(n, expected) => write!(
6767
f,
68-
"Expected at least {} arguments, got {} arguments.",
69-
expected, n
68+
"Expected at least {expected} arguments, got {n} arguments."
7069
),
7170
Error::ZvalConversion(ty) => write!(
7271
f,
73-
"Could not convert Zval from type {} into primitive type.",
74-
ty
72+
"Could not convert Zval from type {ty} into primitive type."
7573
),
76-
Error::UnknownDatatype(dt) => write!(f, "Unknown datatype {}.", dt),
74+
Error::UnknownDatatype(dt) => write!(f, "Unknown datatype {dt}."),
7775
Error::InvalidTypeToDatatype(dt) => {
78-
write!(f, "Type flags did not contain a datatype: {:?}", dt)
76+
write!(f, "Type flags did not contain a datatype: {dt:?}")
7977
}
8078
Error::InvalidScope => write!(f, "Invalid scope."),
8179
Error::InvalidPointer => write!(f, "Invalid pointer."),
@@ -87,12 +85,12 @@ impl Display for Error {
8785
Error::InvalidUtf8 => write!(f, "Invalid Utf8 byte sequence."),
8886
Error::Callable => write!(f, "Could not call given function."),
8987
Error::InvalidException(flags) => {
90-
write!(f, "Invalid exception type was thrown: {:?}", flags)
88+
write!(f, "Invalid exception type was thrown: {flags:?}")
9189
}
9290
Error::IntegerOverflow => {
9391
write!(f, "Converting integer arguments resulted in an overflow.")
9492
}
95-
Error::Exception(e) => write!(f, "Exception was thrown: {:?}", e),
93+
Error::Exception(e) => write!(f, "Exception was thrown: {e:?}"),
9694
}
9795
}
9896
}

src/props.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a, T: 'a> Property<'a, T> {
140140
let value = get(self_);
141141
value
142142
.set_zval(retval, false)
143-
.map_err(|e| format!("Failed to return property value to PHP: {:?}", e))?;
143+
.map_err(|e| format!("Failed to return property value to PHP: {e:?}"))?;
144144
Ok(())
145145
}) as Box<dyn Fn(&T, &mut Zval) -> PhpResult + Send + Sync + 'a>
146146
});
@@ -196,7 +196,7 @@ impl<'a, T: 'a> Property<'a, T> {
196196
match self {
197197
Property::Field(field) => field(self_)
198198
.get(retval)
199-
.map_err(|e| format!("Failed to get property value: {:?}", e).into()),
199+
.map_err(|e| format!("Failed to get property value: {e:?}").into()),
200200
Property::Method { get, set: _ } => match get {
201201
Some(get) => get(self_, retval),
202202
None => Err("No getter available for this property.".into()),
@@ -244,7 +244,7 @@ impl<'a, T: 'a> Property<'a, T> {
244244
match self {
245245
Property::Field(field) => field(self_)
246246
.set(value)
247-
.map_err(|e| format!("Failed to set property value: {:?}", e).into()),
247+
.map_err(|e| format!("Failed to set property value: {e:?}").into()),
248248
Property::Method { get: _, set } => match set {
249249
Some(set) => set(self_, value),
250250
None => Err("No setter available for this property.".into()),

src/zend/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl ZendObjectHandlers {
176176
continue;
177177
}
178178
props.insert(name, zv).map_err(|e| {
179-
format!("Failed to insert value into properties hashtable: {:?}", e)
179+
format!("Failed to insert value into properties hashtable: {e:?}")
180180
})?;
181181
}
182182

0 commit comments

Comments
 (0)