Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushistov committed Nov 11, 2024
1 parent 5814ca3 commit 0371837
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions macroslib/src/cpp/cpp_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,22 @@ pub(in crate::cpp) fn generate_c_type(
CItem::Union(ref u) => u,
CItem::Fn(ref f) => {
let fn_id = format!("fn {}", f.sig.ident);
if is_item_defined(ctx, &module_name, &fn_id) {
if is_item_defined(ctx, module_name, &fn_id) {
continue;
}
add_func_forward_decl(ctx, f, src_id, module_name)?;
ctx.rust_code.push(f.into_token_stream());
define_item(ctx, &module_name, fn_id);
define_item(ctx, module_name, fn_id);
continue;
}
CItem::Static(ref s) => {
let s_id = format!("static {}", s.ident);
if is_item_defined(ctx, &module_name, &s_id) {
if is_item_defined(ctx, module_name, &s_id) {
continue;
}
add_const_forward_decl(ctx, s, src_id, module_name)?;
ctx.rust_code.push(s.into_token_stream());
define_item(ctx, &module_name, s_id);
define_item(ctx, module_name, s_id);
continue;
}
};
Expand Down Expand Up @@ -306,7 +306,7 @@ fn test_{name}_layout() {{
name = ctype.name(),
);
let mut mem_out = Vec::<u8>::new();
writeln!(&mut mem_out, "{} {{", s_id).expect(WRITE_TO_MEM_FAILED_MSG);
writeln!(&mut mem_out, "{s_id} {{").expect(WRITE_TO_MEM_FAILED_MSG);

let mut includes = FxHashSet::<SmolStr>::default();

Expand Down
4 changes: 2 additions & 2 deletions macroslib/src/cpp/fenum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
};

pub(in crate::cpp) fn generate_enum(ctx: &mut CppContext, fenum: &ForeignEnumInfo) -> Result<()> {
if (fenum.items.len() as u64) >= u64::from(u32::max_value()) {
if (fenum.items.len() as u64) >= u64::from(u32::MAX) {
return Err(DiagnosticError::new(
fenum.src_id,
fenum.span(),
Expand Down Expand Up @@ -212,7 +212,7 @@ typedef enum {enum_name} C{enum_name};
fn generate_rust_trait_for_enum(ctx: &mut CppContext, enum_info: &ForeignEnumInfo) -> Result<()> {
let mut arms_to_u32 = Vec::with_capacity(enum_info.items.len());
let mut arms_from_u32 = Vec::with_capacity(enum_info.items.len());
assert!((enum_info.items.len() as u64) <= u64::from(u32::max_value()));
assert!((enum_info.items.len() as u64) <= u64::from(u32::MAX));
for (i, item) in enum_info.items.iter().enumerate() {
let item_name = &item.rust_name;
let idx = i as u32;
Expand Down
6 changes: 3 additions & 3 deletions macroslib/src/cpp/map_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ struct CppContextForArg<'a, 'b> {
direction: Direction,
}

impl<'a, 'b> CppContextForArg<'a, 'b> {
impl CppContextForArg<'_, '_> {
fn arg_direction(&self, param1: Option<&str>) -> Result<Direction> {
match param1 {
Some("output") => Ok(Direction::Outgoing),
Some("input") => Ok(Direction::Incoming),
None => Ok(self.direction),
Some(param) => Err(DiagnosticError::new2(
self.arg_ty_span,
format!("Invalid argument '{}' for swig_f_type", param),
format!("Invalid argument '{param}' for swig_f_type"),
)),
}
}
}

impl<'a, 'b> TypeMapConvRuleInfoExpanderHelper for CppContextForArg<'a, 'b> {
impl TypeMapConvRuleInfoExpanderHelper for CppContextForArg<'_, '_> {
fn swig_i_type(&mut self, ty: &syn::Type, opt_arg: Option<&str>) -> Result<syn::Type> {
let rust_ty = self
.ctx
Expand Down
4 changes: 2 additions & 2 deletions macroslib/src/java_jni/fenum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(in crate::java_jni) fn generate_enum(
) -> Result<()> {
let enum_name = &fenum.name;
trace!("generate_enum: enum {}", enum_name);
if (fenum.items.len() as u64) >= (i32::max_value() as u64) {
if (fenum.items.len() as u64) >= (i32::MAX as u64) {
return Err(DiagnosticError::new(
fenum.src_id,
fenum.span(),
Expand Down Expand Up @@ -178,7 +178,7 @@ public enum {enum_name} {{"#,
fn generate_rust_code_for_enum(ctx: &mut JavaContext, fenum: &ForeignEnumInfo) -> Result<()> {
let mut arms_to_jint = Vec::with_capacity(fenum.items.len());
let mut arms_from_jint = Vec::with_capacity(fenum.items.len());
assert!((fenum.items.len() as u64) <= u64::from(i32::max_value() as u32));
assert!((fenum.items.len() as u64) <= u64::from(i32::MAX as u32));
for (i, item) in fenum.items.iter().enumerate() {
let item_name = &item.rust_name;
let idx = i as i32;
Expand Down
2 changes: 1 addition & 1 deletion macroslib/src/java_jni/map_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn is_ty_implement_traits(tmap: &TypeMap, ty: &syn::Type, traits: &TraitNamesSet
}
}

impl<'a, 'b> TypeMapConvRuleInfoExpanderHelper for JavaContextForArg<'a, 'b> {
impl TypeMapConvRuleInfoExpanderHelper for JavaContextForArg<'_, '_> {
fn swig_i_type(&mut self, ty: &syn::Type, _opt_arg: Option<&str>) -> Result<syn::Type> {
let rust_ty = self
.ctx
Expand Down
4 changes: 2 additions & 2 deletions macroslib/src/java_jni/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn init(ctx: &mut JavaContext, _code: &[SourceCode]) -> Result<()> {
let src_path = ctx
.cfg
.output_dir
.join(&format!("{}.java", INTERNAL_PTR_MARKER));
.join(format!("{INTERNAL_PTR_MARKER}.java"));
let mut src_file = FileWriteCache::new(&src_path, ctx.generated_foreign_files);
writeln!(
src_file,
Expand All @@ -382,7 +382,7 @@ package {package};
let src_path = ctx
.cfg
.output_dir
.join(&format!("{}.java", REACHABILITY_FENCE_CLASS));
.join(format!("{REACHABILITY_FENCE_CLASS}.java"));
let mut src_file = FileWriteCache::new(&src_path, ctx.generated_foreign_files);
write!(
src_file,
Expand Down
4 changes: 2 additions & 2 deletions macroslib/src/namegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ where
new_name.clear();
write!(&mut new_name, "{}{}", templ, idx).expect("write to String failed, no free mem?");
idx += 1;
if idx == u64::max_value() {
panic!("it is impossible find name for {}", templ);
if idx == u64::MAX {
panic!("it is impossible find name for {templ}");
}
}
}
4 changes: 2 additions & 2 deletions macroslib/src/typemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Default for TypeMap {

struct DisplayTypesConvGraph<'a>(&'a TypesConvGraph);

impl<'a> fmt::Display for DisplayTypesConvGraph<'a> {
impl fmt::Display for DisplayTypesConvGraph<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> std::result::Result<(), fmt::Error> {
let conv_graph = self.0;
writeln!(f, "conversion graph begin")?;
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<'a> TypeGraphSnapshot<'a> {
}
}

impl<'a> Drop for TypeGraphSnapshot<'a> {
impl Drop for TypeGraphSnapshot<'_> {
fn drop(&mut self) {
for edge in self.new_edges.iter().rev() {
self.conv_graph.remove_edge(*edge);
Expand Down
2 changes: 1 addition & 1 deletion macroslib/src/typemap/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ pub(in crate::typemap) fn replace_all_types_with(
struct ReplaceTypes<'a, 'b> {
subst_map: &'a TyParamsSubstMap<'b>,
}
impl<'a, 'b> VisitMut for ReplaceTypes<'a, 'b> {
impl VisitMut for ReplaceTypes<'_, '_> {
fn visit_type_mut(&mut self, t: &mut Type) {
let ty_name = normalize_type(t);
if let Some(Some(subst)) = self.subst_map.get(&ty_name) {
Expand Down
2 changes: 1 addition & 1 deletion macroslib/src/typemap/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ fn get_foreigner_hint_for_generic(
attrs[1].1,
format!("Several {} attributes", attr_name),
);
err.span_note((src_id, attrs[0].1), &format!("First {}", attr_name));
err.span_note((src_id, attrs[0].1), format!("First {attr_name}"));
return Err(err);
}
let mut ty_params = generic.type_params();
Expand Down
4 changes: 2 additions & 2 deletions macroslib/src/typemap/typemap_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl TypeMapConvRuleInfo {
}
match (
self.rtype_left_to_right.as_ref(),
self.ftype_left_to_right.get(0),
self.ftype_left_to_right.first(),
) {
(
Some(RTypeConvRule {
Expand Down Expand Up @@ -785,7 +785,7 @@ fn expand_type(
generic_aliases: &'a [CalcGenericAlias<'c>],
err: Option<DiagnosticError>,
}
impl<'a, 'b, 'c> VisitMut for ReplaceTypes<'a, 'b, 'c> {
impl VisitMut for ReplaceTypes<'_, '_, '_> {
fn visit_type_mut(&mut self, t: &mut Type) {
if self.err.is_some() {
return;
Expand Down
2 changes: 1 addition & 1 deletion macroslib/src/typemap/typemap_macro/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl syn::parse::Parse for TypeMapConvRuleInfo {
if mac.path.is_ident(DEFINE_C_TYPE) {
if c_types.is_some() || generic_c_types.is_some() {
return Err(
input.error(format!("{} should be used only once", DEFINE_C_TYPE))
input.error(format!("{DEFINE_C_TYPE} should be used only once"))
);
}
match syn::parse2::<CItems>(mac.tokens.clone()) {
Expand Down

0 comments on commit 0371837

Please sign in to comment.