Skip to content

Remove unnecessary parenthesis around closure trait object type #1659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analysis/child_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn analyze(
if config.child_type.is_some() && child_type.is_none() {
let owner_name = RustType::try_new(env, type_tid).into_string();
let child_type: &str = config.child_type.as_ref().unwrap();
error!("Bad child type `{}` for `{}`", child_type, owner_name);
error!("Bad child type `{child_type}` for `{owner_name}`");
return properties;
}

Expand Down
4 changes: 2 additions & 2 deletions src/analysis/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn ffi_type(env: &Env, tid: TypeId, c_type: &str) -> Result {
| Type::Interface(Interface {
c_type: expected, ..
}) if is_gpointer(c_type) => {
info!("[c:type `gpointer` instead of `*mut {}`, fixing]", expected);
info!("[c:type `gpointer` instead of `*mut {expected}`, fixing]");
ffi_inner(env, tid, expected).map_any(|rust_type| {
rust_type.alter_type(|typ_| format!("*mut {typ_}"))
})
Expand All @@ -62,7 +62,7 @@ pub fn ffi_type(env: &Env, tid: TypeId, c_type: &str) -> Result {
ffi_inner(env, tid, &inner)
.map_any(|rust_type| rust_type.alter_type(|typ_| format!("{ptr} {typ_}")))
};
trace!("ffi_type({:?}, {}) -> {:?}", tid, c_type, res);
trace!("ffi_type({tid:?}, {c_type}) -> {res:?}");
res
}

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Info {
LocationInObject::ClassExt | LocationInObject::ClassExtManual => {
let trait_name = format!("{}Ext", self.trait_name);
(
format!("subclass::prelude::{}", trait_name).into(),
format!("subclass::prelude::{trait_name}").into(),
trait_name.into(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/out_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn use_function_return_for_result(
.find_map(|f| f.ret.use_return_for_result.as_ref());
if let Some(use_return_for_result) = use_return_for_result {
if typ == Default::default() {
error!("Function \"{}\": use_return_for_result set to true, but function has no return value", func_name);
error!("Function \"{func_name}\": use_return_for_result set to true, but function has no return value");
return false;
}
return *use_return_for_result;
Expand Down
13 changes: 3 additions & 10 deletions src/analysis/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,10 @@ fn analyze_property(
};
let mut notifiable = !prop.construct_only;
if generate_set && generate.contains(PropertyGenerateFlags::GET) && !readable {
warn!(
"Attempt to generate getter for notreadable property \"{}.{}\"",
type_name, name
);
warn!("Attempt to generate getter for notreadable property \"{type_name}.{name}\"");
}
if generate_set && generate.contains(PropertyGenerateFlags::SET) && !writable {
warn!(
"Attempt to generate setter for nonwritable property \"{}.{}\"",
type_name, name
);
warn!("Attempt to generate setter for nonwritable property \"{type_name}.{name}\"");
}
readable &= generate.contains(PropertyGenerateFlags::GET);
writable &= generate.contains(PropertyGenerateFlags::SET);
Expand Down Expand Up @@ -300,8 +294,7 @@ fn analyze_property(
if !*nullable {
// TODO: support non-nullable setter if found any
warn!(
"Non nullable setter for property generated as nullable \"{}.{}\"",
type_name, name
"Non nullable setter for property generated as nullable \"{type_name}.{name}\""
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn new(env: &Env, obj: &GObject) -> Option<Info> {
"Have to use get_type function for {full_name} but version is higher than for the type ({get_type_version:?} > {version:?})"
);
} else {
error!("Missing memory management functions for {}", full_name);
error!("Missing memory management functions for {full_name}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl<'env> RustTypeBuilder<'env> {
}
Ok(if *self.nullable {
if self.scope.is_call() {
format!("Option<&mut dyn ({ret})>")
format!("Option<&mut dyn {ret}>")
} else {
format!("Option<Box_<dyn {ret} + 'static>>")
}
Expand Down
16 changes: 7 additions & 9 deletions src/codegen/doc/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn replace_c_types(
let name = &caps[3];
find_method_or_function_by_ctype(None, name, env, in_type).unwrap_or_else(|| {
if !IGNORE_C_WARNING_FUNCS.contains(&name) {
info!("No function found for `{}()`", name);
info!("No function found for `{name}()`");
}
format!("`{}{}()`", caps.get(2).map_or("", |m| m.as_str()), name)
})
Expand All @@ -222,7 +222,7 @@ fn replace_c_types(
if let Some(member_path) = caps.get(3).map(|m| m.as_str()) {
let method_name = member_path.trim_start_matches('.');
find_member(symbol_name, method_name, env, in_type).unwrap_or_else(|| {
info!("`#{}` not found as method", symbol_name);
info!("`#{symbol_name}` not found as method");
format!("`{symbol_name}{member_path}`")
})
} else if let Some(type_) = find_type(symbol_name, env) {
Expand All @@ -231,12 +231,11 @@ fn replace_c_types(
find_constant_or_variant(symbol_name, env, in_type)
{
warn!(
"`{}` matches a constant/variant and should use `%` prefix instead of `#`",
symbol_name
"`{symbol_name}` matches a constant/variant and should use `%` prefix instead of `#`"
);
constant_or_variant
} else {
info!("Type `#{}` not found", symbol_name);
info!("Type `#{symbol_name}` not found");
format!("`{symbol_name}`")
}
}
Expand All @@ -245,8 +244,7 @@ fn replace_c_types(
// symbol truly belongs to `in_type`!
if let Some(type_) = find_type(symbol_name, env) {
warn!(
"`{}` matches a type and should use `#` prefix instead of `%`",
symbol_name
"`{symbol_name}` matches a type and should use `#` prefix instead of `%`"
);
type_
} else if let Some(constant_or_variant) =
Expand Down Expand Up @@ -280,7 +278,7 @@ fn find_constant_or_variant_wrapper(
in_type: Option<(&TypeId, Option<LocationInObject>)>,
) -> String {
find_constant_or_variant(symbol_name, env, in_type).unwrap_or_else(|| {
info!("Constant or variant `%{}` not found", symbol_name);
info!("Constant or variant `%{symbol_name}` not found");
format!("`{symbol_name}`")
})
}
Expand Down Expand Up @@ -465,7 +463,7 @@ pub(crate) fn find_method_or_function(
let visible_parent = object
.and_then(|o| o.trait_name.clone())
.unwrap_or_else(|| format!("{}Ext", record_info.name));
let parent = format!("subclass::prelude::{}", visible_parent);
let parent = format!("subclass::prelude::{visible_parent}");
let is_self = in_type == Some((&record_info.type_id, None));
Some(fn_info.doc_link(Some(&parent), Some(&visible_parent), is_self))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub fn define_fundamental_type(
// We can't use type_ from glib::wrapper! because that would auto-implement
// Value traits which are often not the correct types
writeln!(w, "\n")?;
writeln!(w, "impl StaticType for {} {{", type_name)?;
writeln!(w, "impl StaticType for {type_name} {{")?;
writeln!(w, "\tfn static_type() -> {} {{", use_glib_type(env, "Type"))?;
writeln!(
w,
Expand Down
8 changes: 2 additions & 6 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ pub fn generate_default_impl<
Some(m) => m,
None => {
log::error!(
"type `{}` doesn't have a member named `{}`. Not generating default impl.",
type_name,
default_value,
"type `{type_name}` doesn't have a member named `{default_value}`. Not generating default impl.",
);
return Ok(());
}
Expand All @@ -138,9 +136,7 @@ pub fn generate_default_impl<
Some(n) => n,
None => {
log::error!(
"member `{}` on type `{}` isn't generated so no default impl.",
default_value,
type_name,
"member `{default_value}` on type `{type_name}` isn't generated so no default impl.",
);
return Ok(());
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn generate(

let mut path = root_path.join(&mod_name);
path.set_extension("rs");
info!("Generating file {:?}", path);
info!("Generating file {path:?}");

save_to_file(path, env.config.make_backup, |w| {
super::object::generate(w, env, class_analysis)
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {

let mut path = root_path.join(&mod_name);
path.set_extension("rs");
info!("Generating file {:?}", path);
info!("Generating file {path:?}");

save_to_file(path, env.config.make_backup, |w| {
super::record::generate(w, env, record_analysis)
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ pub fn generate(env: &Env) {
let path = env.config.target_path.join("build.rs");

if !split_build_rs || !path.exists() {
info!("Generating file {:?}", path);
info!("Generating file {path:?}");
save_to_file(&path, env.config.make_backup, |w| {
generate_build_script(w, env, split_build_rs)
});
}

if split_build_rs {
let path = env.config.target_path.join("build_version.rs");
info!("Generating file {:?}", path);
info!("Generating file {path:?}");
save_to_file(&path, env.config.make_backup, |w| {
generate_build_version(w, env)
});
Expand Down
10 changes: 5 additions & 5 deletions src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn ffi_type(env: &Env, tid: library::TypeId, c_type: &str) -> Result {
c_type: ref expected,
..
}) if c_type == "gpointer" => {
info!("[c:type `gpointer` instead of `*mut {}`, fixing]", expected);
info!("[c:type `gpointer` instead of `*mut {expected}`, fixing]");
ffi_inner(env, tid, expected.clone()).map_any(|rust_type| {
rust_type.alter_type(|typ_| format!("*mut {typ_}"))
})
Expand All @@ -55,7 +55,7 @@ pub fn ffi_type(env: &Env, tid: library::TypeId, c_type: &str) -> Result {
ffi_inner(env, tid, inner)
.map_any(|rust_type| rust_type.alter_type(|typ_| format!("{ptr} {typ_}")))
};
trace!("ffi_type({:?}, {}) -> {:?}", tid, c_type, res);
trace!("ffi_type({tid:?}, {c_type}) -> {res:?}");
res
}

Expand Down Expand Up @@ -129,7 +129,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
declared_c_type,
typ.get_name()
);
warn!("{}", msg);
warn!("{msg}");
return Err(TypeError::Mismatch(msg));
}
} else {
Expand Down Expand Up @@ -172,7 +172,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
glib_name,
env.library.type_(tid).get_name()
);
warn!("{}", msg);
warn!("{msg}");
Err(TypeError::Mismatch(msg))
}
} else {
Expand All @@ -184,7 +184,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
env.library.type_(tid).get_name(),
inner
);
warn!("{}", msg);
warn!("{msg}");
Err(TypeError::Mismatch(msg))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn generate(env: &Env) {

let path = env.config.auto_path.join(file_name_sys("lib"));

info!("Generating file {:?}", path);
info!("Generating file {path:?}");
save_to_file(&path, env.config.make_backup, |w| generate_lib(w, env));
}

Expand Down
8 changes: 4 additions & 4 deletions src/codegen/sys/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn is_name_made_up(name: &str) -> bool {
}

fn generate_manual_h(env: &Env, path: &Path, w: &mut dyn Write) -> io::Result<()> {
info!("Generating file {:?}", path);
info!("Generating file {path:?}");
writeln!(
w,
"// Feel free to edit this file, it won't be regenerated by gir generator unless removed."
Expand All @@ -217,7 +217,7 @@ fn generate_layout_c(
w: &mut dyn Write,
ctypes: &[CType],
) -> io::Result<()> {
info!("Generating file {:?}", path);
info!("Generating file {path:?}");
general::start_comments(w, &env.config)?;
writeln!(w)?;
writeln!(w, "#include \"manual.h\"")?;
Expand Down Expand Up @@ -245,7 +245,7 @@ fn generate_constant_c(
w: &mut dyn Write,
cconsts: &[CConstant],
) -> io::Result<()> {
info!("Generating file {:?}", path);
info!("Generating file {path:?}");
general::start_comments(w, &env.config)?;
writeln!(w)?;
writeln!(w, "#include \"manual.h\"")?;
Expand Down Expand Up @@ -306,7 +306,7 @@ fn generate_abi_rs(
package_names = format!("\"{package_names}\"");
}

info!("Generating file {:?}", path);
info!("Generating file {path:?}");
general::start_comments(w, &env.config)?;
writeln!(w)?;
writeln!(w, "#![cfg(unix)]")?;
Expand Down
10 changes: 6 additions & 4 deletions src/codegen/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ pub fn generate(
in_trait: bool,
indent: usize,
) -> Result<()> {
let (self_bound, fn_self_bound) = in_trait
.then(|| {
let (self_bound, fn_self_bound) = if in_trait {
{
(
format!("{}: IsA<{}>, ", TYPE_PARAMETERS_START, analysis.type_name),
Some(TYPE_PARAMETERS_START.to_string()),
)
})
.unwrap_or_default();
}
} else {
Default::default()
};

let prepend = tabs(indent);
let params_str = trampoline_parameters(env, analysis);
Expand Down
11 changes: 4 additions & 7 deletions src/config/child_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Parse for ChildProperty {
let name = if let Some(name) = name {
name
} else {
error!("No child property name for `{}`", object_name);
error!("No child property name for `{object_name}`");
return None;
};

Expand All @@ -37,10 +37,7 @@ impl Parse for ChildProperty {
let type_name = if let Some(type_name) = type_name {
type_name
} else {
error!(
"No type for child property `{}` for `{}`",
name, object_name
);
error!("No type for child property `{name}` for `{object_name}`");
return None;
};
let doc_hidden = toml
Expand Down Expand Up @@ -100,10 +97,10 @@ impl Parse for ChildProperties {
})
} else {
if child_name.is_some() {
error!("`{}` has child_name but no child_prop's", object_name);
error!("`{object_name}` has child_name but no child_prop's");
}
if child_type.is_some() {
error!("`{}` has child_type but no child_prop's", object_name);
error!("`{object_name}` has child_type but no child_prop's");
}
None
}
Expand Down
5 changes: 1 addition & 4 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub struct Constant {
impl Parse for Constant {
fn parse(toml: &Value, object_name: &str) -> Option<Self> {
let Some(ident) = Ident::parse(toml, object_name, "constant") else {
error!(
"No 'name' or 'pattern' given for constant for object {}",
object_name
);
error!("No 'name' or 'pattern' given for constant for object {object_name}");
return None;
};
toml.check_unwanted(
Expand Down
2 changes: 1 addition & 1 deletion src/config/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Parse for Derive {
let names = match toml.lookup("name").and_then(Value::as_str) {
Some(names) => names,
None => {
error!("No 'name' given for derive for object {}", object_name);
error!("No 'name' given for derive for object {object_name}");
return None;
}
};
Expand Down
Loading
Loading