mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-11-26 20:15:22 +01:00
chore(clippy): Fix clippy warnings. (#228)
This commit is contained in:
parent
0b27dc349f
commit
e6afecbddd
12
build.rs
12
build.rs
@ -31,7 +31,7 @@ pub trait PHPProvider<'a>: Sized {
|
||||
/// Writes the bindings to a file.
|
||||
fn write_bindings(&self, bindings: String, writer: &mut impl Write) -> Result<()> {
|
||||
for line in bindings.lines() {
|
||||
writeln!(writer, "{}", line)?;
|
||||
writeln!(writer, "{line}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -126,7 +126,7 @@ impl PHPInfo {
|
||||
}
|
||||
|
||||
fn get_key(&self, key: &str) -> Option<&str> {
|
||||
let split = format!("{} => ", key);
|
||||
let split = format!("{key} => ");
|
||||
for line in self.0.lines() {
|
||||
let components: Vec<_> = line.split(&split).collect();
|
||||
if components.len() > 1 {
|
||||
@ -160,11 +160,7 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
|
||||
.iter()
|
||||
.map(|inc| format!("-I{}", inc.to_string_lossy())),
|
||||
)
|
||||
.clang_args(
|
||||
defines
|
||||
.iter()
|
||||
.map(|(var, val)| format!("-D{}={}", var, val)),
|
||||
)
|
||||
.clang_args(defines.iter().map(|(var, val)| format!("-D{var}={val}")))
|
||||
.rustfmt_bindings(true)
|
||||
.no_copy("_zval_struct")
|
||||
.no_copy("_zend_string")
|
||||
@ -237,7 +233,7 @@ fn main() -> Result<()> {
|
||||
println!("cargo:rerun-if-changed={}", path.to_string_lossy());
|
||||
}
|
||||
for env_var in ["PHP", "PHP_CONFIG", "PATH"] {
|
||||
println!("cargo:rerun-if-env-changed={}", env_var);
|
||||
println!("cargo:rerun-if-env-changed={env_var}");
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
@ -10,7 +10,7 @@ use dialoguer::{Confirm, Select};
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::{BufRead, BufReader, Seek, SeekFrom, Write},
|
||||
io::{BufRead, BufReader, Seek, Write},
|
||||
path::PathBuf,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
@ -207,7 +207,7 @@ impl Install {
|
||||
.open(php_ini)
|
||||
.with_context(|| "Failed to open `php.ini`")?;
|
||||
|
||||
let mut ext_line = format!("extension={}", ext_name);
|
||||
let mut ext_line = format!("extension={ext_name}");
|
||||
|
||||
let mut new_lines = vec![];
|
||||
for line in BufReader::new(&file).lines() {
|
||||
@ -225,7 +225,7 @@ impl Install {
|
||||
}
|
||||
|
||||
new_lines.push(ext_line);
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
file.rewind()?;
|
||||
file.set_len(0)?;
|
||||
file.write(new_lines.join("\n").as_bytes())
|
||||
.with_context(|| "Failed to update `php.ini`")?;
|
||||
@ -255,9 +255,8 @@ fn get_ext_dir() -> AResult<PathBuf> {
|
||||
ext_dir
|
||||
);
|
||||
} else {
|
||||
std::fs::create_dir(&ext_dir).with_context(|| {
|
||||
format!("Failed to create extension directory at {:?}", ext_dir)
|
||||
})?;
|
||||
std::fs::create_dir(&ext_dir)
|
||||
.with_context(|| format!("Failed to create extension directory at {ext_dir:?}"))?;
|
||||
}
|
||||
}
|
||||
Ok(ext_dir)
|
||||
@ -341,7 +340,7 @@ impl Remove {
|
||||
}
|
||||
}
|
||||
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
file.rewind()?;
|
||||
file.set_len(0)?;
|
||||
file.write(new_lines.join("\n").as_bytes())
|
||||
.with_context(|| "Failed to update `php.ini`")?;
|
||||
@ -389,7 +388,7 @@ impl Stubs {
|
||||
.with_context(|| "Failed to generate stubs.")?;
|
||||
|
||||
if self.stdout {
|
||||
print!("{}", stubs);
|
||||
print!("{stubs}");
|
||||
} else {
|
||||
let out_path = if let Some(out_path) = &self.out {
|
||||
Cow::Borrowed(out_path)
|
||||
|
@ -52,7 +52,7 @@ pub fn parser(args: AttributeArgs, input: ItemFn) -> Result<(TokenStream, Functi
|
||||
..
|
||||
} = &sig;
|
||||
|
||||
let internal_ident = Ident::new(&format!("_internal_php_{}", ident), Span::call_site());
|
||||
let internal_ident = Ident::new(&format!("_internal_php_{ident}"), Span::call_site());
|
||||
let args = build_args(inputs, &attr_args.defaults)?;
|
||||
let optional = find_optional_parameter(args.iter(), attr_args.optional);
|
||||
let arg_definitions = build_arg_definitions(&args);
|
||||
|
@ -136,7 +136,7 @@ pub fn parser(
|
||||
} else {
|
||||
quote! { return; }
|
||||
};
|
||||
let internal_ident = Ident::new(&format!("_internal_php_{}", ident), Span::call_site());
|
||||
let internal_ident = Ident::new(&format!("_internal_php_{ident}"), Span::call_site());
|
||||
let args = build_args(struct_ty, &mut input.sig.inputs, &defaults)?;
|
||||
let optional = function::find_optional_parameter(
|
||||
args.iter().filter_map(|arg| match arg {
|
||||
|
@ -68,7 +68,7 @@ fn build_classes(classes: &HashMap<String, Class>) -> Result<Vec<TokenStream>> {
|
||||
.map(|(name, class)| {
|
||||
let Class { class_name, .. } = &class;
|
||||
let ident = Ident::new(name, Span::call_site());
|
||||
let meta = Ident::new(&format!("_{}_META", name), Span::call_site());
|
||||
let meta = Ident::new(&format!("_{name}_META"), Span::call_site());
|
||||
let methods = class.methods.iter().map(|method| {
|
||||
let builder = method.get_builder(&ident);
|
||||
let flags = method.get_flags();
|
||||
|
@ -84,7 +84,7 @@ impl ToStub for Module {
|
||||
.map(|(ns, entries)| {
|
||||
let mut buf = String::new();
|
||||
if let Some(ns) = ns {
|
||||
writeln!(buf, "namespace {} {{", ns)?;
|
||||
writeln!(buf, "namespace {ns} {{")?;
|
||||
} else {
|
||||
writeln!(buf, "namespace {{")?;
|
||||
}
|
||||
@ -183,7 +183,7 @@ impl ToStub for DocBlock {
|
||||
if !self.0.is_empty() {
|
||||
writeln!(buf, "/**")?;
|
||||
for comment in self.0.iter() {
|
||||
writeln!(buf, " *{}", comment)?;
|
||||
writeln!(buf, " *{comment}")?;
|
||||
}
|
||||
writeln!(buf, " */")?;
|
||||
}
|
||||
@ -196,10 +196,10 @@ impl ToStub for Class {
|
||||
self.docs.fmt_stub(buf)?;
|
||||
|
||||
let (_, name) = split_namespace(self.name.as_ref());
|
||||
write!(buf, "class {} ", name)?;
|
||||
write!(buf, "class {name} ")?;
|
||||
|
||||
if let Option::Some(extends) = &self.extends {
|
||||
write!(buf, "extends {} ", extends)?;
|
||||
write!(buf, "extends {extends} ")?;
|
||||
}
|
||||
|
||||
if !self.implements.is_empty() {
|
||||
@ -249,7 +249,7 @@ impl ToStub for Property {
|
||||
}
|
||||
write!(buf, "${}", self.name)?;
|
||||
if let Option::Some(default) = &self.default {
|
||||
write!(buf, " = {}", default)?;
|
||||
write!(buf, " = {default}")?;
|
||||
}
|
||||
writeln!(buf, ";")
|
||||
}
|
||||
@ -311,7 +311,7 @@ impl ToStub for Constant {
|
||||
|
||||
write!(buf, "const {} = ", self.name)?;
|
||||
if let Option::Some(value) = &self.value {
|
||||
write!(buf, "{}", value)?;
|
||||
write!(buf, "{value}")?;
|
||||
} else {
|
||||
write!(buf, "null")?;
|
||||
}
|
||||
@ -381,6 +381,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
#[allow(clippy::uninlined_format_args)]
|
||||
pub fn test_indent() {
|
||||
use super::indent;
|
||||
use crate::describe::stub::NEW_LINE_SEPARATOR;
|
||||
|
14
src/error.rs
14
src/error.rs
@ -65,17 +65,15 @@ impl Display for Error {
|
||||
match self {
|
||||
Error::IncorrectArguments(n, expected) => write!(
|
||||
f,
|
||||
"Expected at least {} arguments, got {} arguments.",
|
||||
expected, n
|
||||
"Expected at least {expected} arguments, got {n} arguments."
|
||||
),
|
||||
Error::ZvalConversion(ty) => write!(
|
||||
f,
|
||||
"Could not convert Zval from type {} into primitive type.",
|
||||
ty
|
||||
"Could not convert Zval from type {ty} into primitive type."
|
||||
),
|
||||
Error::UnknownDatatype(dt) => write!(f, "Unknown datatype {}.", dt),
|
||||
Error::UnknownDatatype(dt) => write!(f, "Unknown datatype {dt}."),
|
||||
Error::InvalidTypeToDatatype(dt) => {
|
||||
write!(f, "Type flags did not contain a datatype: {:?}", dt)
|
||||
write!(f, "Type flags did not contain a datatype: {dt:?}")
|
||||
}
|
||||
Error::InvalidScope => write!(f, "Invalid scope."),
|
||||
Error::InvalidPointer => write!(f, "Invalid pointer."),
|
||||
@ -87,12 +85,12 @@ impl Display for Error {
|
||||
Error::InvalidUtf8 => write!(f, "Invalid Utf8 byte sequence."),
|
||||
Error::Callable => write!(f, "Could not call given function."),
|
||||
Error::InvalidException(flags) => {
|
||||
write!(f, "Invalid exception type was thrown: {:?}", flags)
|
||||
write!(f, "Invalid exception type was thrown: {flags:?}")
|
||||
}
|
||||
Error::IntegerOverflow => {
|
||||
write!(f, "Converting integer arguments resulted in an overflow.")
|
||||
}
|
||||
Error::Exception(e) => write!(f, "Exception was thrown: {:?}", e),
|
||||
Error::Exception(e) => write!(f, "Exception was thrown: {e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ impl<'a, T: 'a> Property<'a, T> {
|
||||
let value = get(self_);
|
||||
value
|
||||
.set_zval(retval, false)
|
||||
.map_err(|e| format!("Failed to return property value to PHP: {:?}", e))?;
|
||||
.map_err(|e| format!("Failed to return property value to PHP: {e:?}"))?;
|
||||
Ok(())
|
||||
}) as Box<dyn Fn(&T, &mut Zval) -> PhpResult + Send + Sync + 'a>
|
||||
});
|
||||
@ -196,7 +196,7 @@ impl<'a, T: 'a> Property<'a, T> {
|
||||
match self {
|
||||
Property::Field(field) => field(self_)
|
||||
.get(retval)
|
||||
.map_err(|e| format!("Failed to get property value: {:?}", e).into()),
|
||||
.map_err(|e| format!("Failed to get property value: {e:?}").into()),
|
||||
Property::Method { get, set: _ } => match get {
|
||||
Some(get) => get(self_, retval),
|
||||
None => Err("No getter available for this property.".into()),
|
||||
@ -244,7 +244,7 @@ impl<'a, T: 'a> Property<'a, T> {
|
||||
match self {
|
||||
Property::Field(field) => field(self_)
|
||||
.set(value)
|
||||
.map_err(|e| format!("Failed to set property value: {:?}", e).into()),
|
||||
.map_err(|e| format!("Failed to set property value: {e:?}").into()),
|
||||
Property::Method { get: _, set } => match set {
|
||||
Some(set) => set(self_, value),
|
||||
None => Err("No setter available for this property.".into()),
|
||||
|
@ -176,7 +176,7 @@ impl ZendObjectHandlers {
|
||||
continue;
|
||||
}
|
||||
props.insert(name, zv).map_err(|e| {
|
||||
format!("Failed to insert value into properties hashtable: {:?}", e)
|
||||
format!("Failed to insert value into properties hashtable: {e:?}")
|
||||
})?;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user