Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
h33p committed Nov 25, 2021
1 parent abbaa87 commit 4e2703d
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -179,7 +179,7 @@ jobs:
platform: x64
- name: Build the plugins
run: cargo build --release -p plugin-api -p plugin-lib -p cglue-bindgen
- name: Build and C++ plugin library
- name: Build C++ plugin library
run: |
cd examples/cpp-plugin-lib/
make
Expand Down
20 changes: 10 additions & 10 deletions cglue-bindgen/src/codegen/c.rs
Expand Up @@ -72,12 +72,12 @@ pub fn parse_header(header: &str, config: &Config) -> Result<String> {
// Check if we need to typedef `TypeLayout`
let type_layout_re = Regex::new(r"((typedef [\s]+)|struct) TypeLayout")?;
let needs_type_layout =
header.contains("const TypeLayout *") && !type_layout_re.is_match(&header);
header.contains("const TypeLayout *") && !type_layout_re.is_match(header);

// PROCESSING:

// Remove zsized ret tmps
let header = zsr_regex.replace_all(&header, "");
let header = zsr_regex.replace_all(header, "");

let gr_regex = group_ret_tmp_regex(&zst_rets)?;
let header = gr_regex.replace_all(&header, "");
Expand Down Expand Up @@ -233,7 +233,7 @@ void ctx_{prefix}_drop({ty} *self) {{
for (t, second_half, _, _, funcs) in &obj_vtbls {
let container_ty = format!("struct CGlueObjContainer_{}", second_half);

let vtbl = Vtable::new(t.to_string(), &funcs, &container_ty)?;
let vtbl = Vtable::new(t.to_string(), funcs, &container_ty)?;

for f in vtbl.functions {
vtbl_types.entry(f.name).or_default().insert(t.clone());
Expand Down Expand Up @@ -264,15 +264,15 @@ void ctx_{prefix}_drop({ty} *self) {{
} = inner_map
.get(inner.as_str())
.copied()
.unwrap_or(ContainerType::from_name(inner.as_str()));
.unwrap_or_else(|| ContainerType::from_name(inner.as_str()));
let ContextType {
ty_prefix: ctx,
drop_impl: context_wrappers,
..
} = context_map
.get(context.as_str())
.copied()
.unwrap_or(ContextType::from_name(context.as_str()));
.unwrap_or_else(|| ContextType::from_name(context.as_str()));

let wrappers = vtbl.create_wrappers_c(
("container", "vtbl"),
Expand Down Expand Up @@ -317,28 +317,28 @@ void ctx_{prefix}_drop({ty} *self) {{
} = inner_map
.get(inner.as_str())
.copied()
.unwrap_or(ContainerType::from_name(inner.as_str()));
.unwrap_or_else(|| ContainerType::from_name(inner.as_str()));
let ContextType {
ty_prefix: ctx,
drop_impl: context_wrappers,
..
} = context_map
.get(context.as_str())
.copied()
.unwrap_or(ContextType::from_name(context.as_str()));
.unwrap_or_else(|| ContextType::from_name(context.as_str()));

let wrappers = vtbl.create_wrappers_c(
("container", &format!("vtbl_{}", vtbl.name.to_lowercase())),
("", &|_| Some(&cont)),
(&container_ty, &inner, container_wrappers.is_some()),
(&container_ty, inner, container_wrappers.is_some()),
(&context, ctx, context_wrappers.is_some()),
(&this_ty, &[]),
&mut generated_funcs,
config,
);

if config.default_context.as_deref() == Some(ctx)
&& config.default_container.as_deref() == Some(&inner)
&& config.default_container.as_deref() == Some(inner)
{
shortened_typedefs.push((this_ty, cont.to_string()));
}
Expand Down Expand Up @@ -726,7 +726,7 @@ typedef (struct )?{ty} (?P<new_ty>.+);
header = typedef_regex
.replace(&header, |caps: &Captures| {
let new_ty = caps["new_ty"].to_string();
types_to_explore.push_front((root.clone(), ty.clone(), new_ty.clone()));
types_to_explore.push_front((root.clone(), ty.clone(), new_ty));
format!(
"{}{}{}",
&caps["old_typedef"], &caps["new_typedef"], &caps["inbetween"]
Expand Down
4 changes: 2 additions & 2 deletions cglue-bindgen/src/codegen/cpp.rs
Expand Up @@ -153,7 +153,7 @@ pub fn parse_header(header: &str, config: &Config) -> Result<String> {
let type_layout_re =
Regex::new(r"((((typedef [\s]+)|struct) TypeLayout)|(using TypeLayout =))")?;
let needs_type_layout =
header.contains("const TypeLayout *") && !type_layout_re.is_match(&header);
header.contains("const TypeLayout *") && !type_layout_re.is_match(header);

// PROCESSING:

Expand Down Expand Up @@ -889,7 +889,7 @@ struct [^\{\}\n]+<.*CGlueInst.*>)?",
}
}

Ok(header.into())
Ok(header)
}

fn zero_sized_ret_regex() -> Result<Regex> {
Expand Down
7 changes: 4 additions & 3 deletions cglue-bindgen/src/types.rs
Expand Up @@ -383,7 +383,7 @@ impl<'a> Iterator for ArgsParser<'a> {

let name = ret.rsplit(&['&', '*', ' '][..]).next()?;

Some((&ret[..(ret.len() - name.len())].trim(), name.trim()))
Some((ret[..(ret.len() - name.len())].trim(), name.trim()))
}
}

Expand All @@ -401,7 +401,7 @@ impl Vtable {
))?;

for func in functions_str.split(';').filter(|s| !s.is_empty()) {
if let Some(cap) = reg.captures(&func) {
if let Some(cap) = reg.captures(func) {
let cont = &cap["cont"];

let mut arguments = vec![];
Expand Down Expand Up @@ -463,6 +463,7 @@ impl Vtable {
ret
}

#[allow(clippy::too_many_arguments)]
pub fn create_wrappers_c<'a>(
&self,
cont_vtbl: (&str, &str),
Expand All @@ -486,7 +487,7 @@ impl Vtable {
})
.iter(),
) {
let ty_prefix = ty_prefix(&f);
let ty_prefix = ty_prefix(f);

let (prefix, cast_self) = if f.moves_self || f.return_type == this_ty {
let config_match = config.default_context.as_deref() == Some(context_info.1)
Expand Down
1 change: 0 additions & 1 deletion cglue-gen/Cargo.toml
Expand Up @@ -21,7 +21,6 @@ lazy_static = "1"

[features]
default = []
no_empty_retwrap = []
rust_void = []
unstable = []
layout_checks = []
3 changes: 2 additions & 1 deletion cglue-gen/src/func.rs
Expand Up @@ -328,6 +328,7 @@ pub struct ParsedFunc {
}

impl ParsedFunc {
#[allow(clippy::too_many_arguments)]
pub fn new(
sig: Signature,
trait_name: Ident,
Expand Down Expand Up @@ -651,7 +652,7 @@ impl ParsedFunc {
_ => (quote!(), args, c_out),
};

let doc_text = format!(" Getter for {}.", name.to_string());
let doc_text = format!(" Getter for {}.", name);

let gen = quote! {
#[doc = #doc_text]
Expand Down
2 changes: 1 addition & 1 deletion cglue-gen/src/trait_groups.rs
Expand Up @@ -63,7 +63,7 @@ impl From<Path> for TraitInfo {
}

/// Describes parse trait group, allows to generate code for it.
#[cfg_attr(not(feature = "unstable"), allow(unused))]
#[cfg_attr(feature = "unstable", allow(unused))]
pub struct TraitGroup {
name: Ident,
cont_name: Ident,
Expand Down
16 changes: 4 additions & 12 deletions cglue-gen/src/traits.rs
Expand Up @@ -227,14 +227,12 @@ pub fn process_item(
quote!(#from_lifetime_simple)
};

let cglue_f_tys = if let Some(ty_ident) = ty_ident {
Some((
let cglue_f_tys = ty_ident.as_ref().map(|ty_ident| {
(
quote!(<CGlueC::ObjType as #trait_name<#hrtb_lifetime_use #gen_use>>::#ty_ident),
quote!(<CGlueC::ObjType as #trait_name<#simple_lifetime_use #gen_use>>::#ty_ident),
))
} else {
None
};
)
});

let mut new_ty_hrtb = from_new_ty.clone();
let mut new_ty_simple = from_new_ty_simple.clone();
Expand Down Expand Up @@ -785,12 +783,6 @@ pub fn gen_trait(mut tr: ItemTrait, ext_name: Option<&Ident>) -> TokenStream {
func.ret_default_def(&mut ret_tmp_default_defs);
}

// If no types are wrapped, and feature is not enabled, inject a 1 byte padding.
if cfg!(feature = "no_empty_retwrap") && ret_tmp_type_defs.is_empty() {
ret_tmp_type_defs.extend(quote!(_padding: u8,));
ret_tmp_default_defs.extend(quote!(_padding: 0,));
}

// Define Default calls for temp storage
let mut ret_tmp_getter_defs = TokenStream::new();

Expand Down
1 change: 0 additions & 1 deletion cglue-macro/Cargo.toml
Expand Up @@ -22,7 +22,6 @@ cglue-gen = { version = "0.2", path = "../cglue-gen" }

[features]
default = []
no_empty_retwrap = ["cglue-gen/no_empty_retwrap"]
rust_void = ["cglue-gen/rust_void"]
unstable = ["cglue-gen/unstable"]
layout_checks = ["cglue-gen/layout_checks"]
1 change: 0 additions & 1 deletion cglue/Cargo.toml
Expand Up @@ -20,7 +20,6 @@ abi_stable = { version = "0.10", git = "https://github.com/rodrimati1992/abi_sta

[features]
default = ["std"]
no_empty_retwrap = ["cglue-macro/no_empty_retwrap"]
std = ["no-std-compat/std"]
rust_void = ["cglue-macro/rust_void"]
unstable = ["cglue-macro/unstable", "try_default"]
Expand Down
10 changes: 2 additions & 8 deletions cglue/src/trait_group.rs
Expand Up @@ -534,18 +534,12 @@ impl VerifyLayout {

/// Check if the layout is strictly valid.
pub fn is_valid_strict(&self) -> bool {
match self {
VerifyLayout::Valid => true,
_ => false,
}
matches!(self, VerifyLayout::Valid)
}

/// Check if the layout is either fully valid, or unknown.
pub fn is_valid_relaxed(&self) -> bool {
match self {
VerifyLayout::Valid | VerifyLayout::Unknown => true,
_ => false,
}
matches!(self, VerifyLayout::Valid | VerifyLayout::Unknown)
}

/// Combine 2 layouts and return whether the layout is still fully valid.
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin-api/src/lib.rs
Expand Up @@ -155,4 +155,4 @@ unsafe fn load_plugin_impl(name: &str) -> Result<PluginInnerArcBox<'static>, Err
/// Layout that should be embedded to a `PluginHeader`.
/// Other layouts are not necessary, because the very root depends on them already.
#[no_mangle]
pub static ROOT_LAYOUT: &'static TypeLayout = PluginInnerArcBox::LAYOUT;
pub static ROOT_LAYOUT: &TypeLayout = PluginInnerArcBox::LAYOUT;
2 changes: 1 addition & 1 deletion examples/plugin-lib/src/lib.rs
Expand Up @@ -43,7 +43,7 @@ impl MainFeature for KvStore {

impl KeyValueStore for KvStore {
fn write_key_value(&mut self, name: &str, val: usize) {
self.map.insert(name.to_string().into(), val);
self.map.insert(name.to_string(), val);
}

fn get_key_value(&self, name: &str) -> usize {
Expand Down

0 comments on commit 4e2703d

Please sign in to comment.