Skip to content

Commit c704b14

Browse files
nyurikemilio
authored andcommitted
Fix needless_pass_by_value lint
This also gets rid of some unneeded cloning
1 parent 4de3ada commit c704b14

File tree

9 files changed

+61
-60
lines changed

9 files changed

+61
-60
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ wildcard_imports = "allow"
8585
# TODO
8686
borrow_as_ptr = "allow"
8787
trivially_copy_pass_by_ref = "allow"
88-
needless_pass_by_value = "allow"
8988
unused_self = "allow"
9089

9190
# Theese seem to be ok to ignore for now

bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ pub fn test_item_discovery_callback() {
7676
),
7777
]);
7878

79-
compare_item_caches(info.borrow().clone(), expected);
79+
compare_item_caches(&info.borrow(), &expected);
8080
}
8181

82-
pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) {
82+
pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) {
8383
// We can't use a simple Eq::eq comparison because of two reasons:
8484
// - anonymous structs/unions will have a final name generated by bindgen which may change
8585
// if the header file or the bindgen logic is altered
@@ -89,8 +89,8 @@ pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) {
8989
compare_item_info(
9090
expected_item,
9191
generated_item,
92-
&expected,
93-
&generated,
92+
expected,
93+
generated,
9494
)
9595
});
9696

bindgen-tests/tests/quickchecking/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static CONTEXT: Mutex<Context> = Mutex::new(Context { output_path: None });
3737
// Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns
3838
// output of the associated command.
3939
fn run_predicate_script(
40-
header: fuzzers::HeaderC,
40+
header: &fuzzers::HeaderC,
4141
) -> Result<Output, Box<dyn Error>> {
4242
let dir = Builder::new().prefix("bindgen_prop").tempdir()?;
4343
let header_path = dir.path().join("prop_test.h");
@@ -77,8 +77,9 @@ fn run_predicate_script(
7777
// Generatable property. Pass generated headers off to run through the
7878
// `csmith-fuzzing/predicate.py` script. Success is measured by the success
7979
// status of that command.
80+
#[allow(clippy::needless_pass_by_value)]
8081
fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
81-
match run_predicate_script(header) {
82+
match run_predicate_script(&header) {
8283
Ok(o) => TestResult::from_bool(o.status.success()),
8384
Err(e) => {
8485
println!("{e:?}");

bindgen/codegen/dyngen.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl DynamicItems {
7575

7676
pub(crate) fn get_tokens(
7777
&self,
78-
lib_ident: Ident,
78+
lib_ident: &Ident,
7979
ctx: &BindgenContext,
8080
) -> TokenStream {
8181
let struct_members = &self.struct_members;
@@ -130,15 +130,15 @@ impl DynamicItems {
130130
#[allow(clippy::too_many_arguments)]
131131
pub(crate) fn push_func(
132132
&mut self,
133-
ident: Ident,
133+
ident: &Ident,
134134
abi: ClangAbi,
135135
is_variadic: bool,
136136
is_required: bool,
137-
args: Vec<TokenStream>,
138-
args_identifiers: Vec<TokenStream>,
139-
ret: TokenStream,
140-
ret_ty: TokenStream,
141-
attributes: Vec<TokenStream>,
137+
args: &[TokenStream],
138+
args_identifiers: &[TokenStream],
139+
ret: &TokenStream,
140+
ret_ty: &TokenStream,
141+
attributes: &[TokenStream],
142142
ctx: &BindgenContext,
143143
) {
144144
if !is_variadic {
@@ -205,8 +205,8 @@ impl DynamicItems {
205205

206206
pub fn push_var(
207207
&mut self,
208-
ident: Ident,
209-
ty: TokenStream,
208+
ident: &Ident,
209+
ty: &TokenStream,
210210
is_required: bool,
211211
wrap_unsafe_ops: bool,
212212
) {

bindgen/codegen/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) mod attributes {
5252
}
5353
}
5454

55-
pub(crate) fn doc(comment: String) -> TokenStream {
55+
pub(crate) fn doc(comment: &str) -> TokenStream {
5656
if comment.is_empty() {
5757
quote!()
5858
} else {

bindgen/codegen/impl_debug.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a> ImplDebug<'a> for Item {
130130

131131
fn debug_print(
132132
name: &str,
133-
name_ident: proc_macro2::TokenStream,
133+
name_ident: &proc_macro2::TokenStream,
134134
) -> Option<(String, Vec<proc_macro2::TokenStream>)> {
135135
Some((
136136
format!("{name}: {{:?}}"),
@@ -154,13 +154,13 @@ impl<'a> ImplDebug<'a> for Item {
154154
TypeKind::ObjCInterface(..) |
155155
TypeKind::ObjCId |
156156
TypeKind::Comp(..) |
157-
TypeKind::ObjCSel => debug_print(name, quote! { #name_ident }),
157+
TypeKind::ObjCSel => debug_print(name, &quote! { #name_ident }),
158158

159159
TypeKind::TemplateInstantiation(ref inst) => {
160160
if inst.is_opaque(ctx, self) {
161161
Some((format!("{name}: opaque"), vec![]))
162162
} else {
163-
debug_print(name, quote! { #name_ident })
163+
debug_print(name, &quote! { #name_ident })
164164
}
165165
}
166166

@@ -177,7 +177,7 @@ impl<'a> ImplDebug<'a> for Item {
177177
ctx.options().rust_features().larger_arrays
178178
{
179179
// The simple case
180-
debug_print(name, quote! { #name_ident })
180+
debug_print(name, &quote! { #name_ident })
181181
} else if ctx.options().use_core {
182182
// There is no String in core; reducing field visibility to avoid breaking
183183
// no_std setups.
@@ -233,7 +233,7 @@ impl<'a> ImplDebug<'a> for Item {
233233
{
234234
Some((format!("{name}: FunctionPointer"), vec![]))
235235
}
236-
_ => debug_print(name, quote! { #name_ident }),
236+
_ => debug_print(name, &quote! { #name_ident }),
237237
}
238238
}
239239

bindgen/codegen/impl_partialeq.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn gen_field(
7676
name: &str,
7777
) -> proc_macro2::TokenStream {
7878
fn quote_equals(
79-
name_ident: proc_macro2::Ident,
79+
name_ident: &proc_macro2::Ident,
8080
) -> proc_macro2::TokenStream {
8181
quote! { self.#name_ident == other.#name_ident }
8282
}
@@ -100,23 +100,23 @@ fn gen_field(
100100
TypeKind::Comp(..) |
101101
TypeKind::Pointer(_) |
102102
TypeKind::Function(..) |
103-
TypeKind::Opaque => quote_equals(name_ident),
103+
TypeKind::Opaque => quote_equals(&name_ident),
104104

105105
TypeKind::TemplateInstantiation(ref inst) => {
106106
if inst.is_opaque(ctx, ty_item) {
107107
quote! {
108108
&self. #name_ident [..] == &other. #name_ident [..]
109109
}
110110
} else {
111-
quote_equals(name_ident)
111+
quote_equals(&name_ident)
112112
}
113113
}
114114

115115
TypeKind::Array(_, len) => {
116116
if len <= RUST_DERIVE_IN_ARRAY_LIMIT ||
117117
ctx.options().rust_features().larger_arrays
118118
{
119-
quote_equals(name_ident)
119+
quote_equals(&name_ident)
120120
} else {
121121
quote! {
122122
&self. #name_ident [..] == &other. #name_ident [..]

0 commit comments

Comments
 (0)