Skip to content

needless_pass_by_value for the extern functions #1844

@stanislav-tkach

Description

@stanislav-tkach

Probably, needless_pass_by_value can be disabled for the extern functions. I'm not sure that it will be correct for all situations, so I'm going to describe my problem.

I'm using jni-rs crate that provides a thin wrapper around Java JNI interface pointer:

#[repr(C)]
pub struct JNIEnv<'a> {
    internal: *mut sys::JNIEnv,
    lifetime: PhantomData<&'a ()>,
}

It is passed by value to all functions that should be accessed from the Java side. For example:

#[no_mangle]
#[allow(non_snake_case)]
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
pub extern "C" fn Java_com_..._foo(
    env: JNIEnv,
    _: JClass,
    ...
) {
    ...
}

I don't like to suppress this warning for the entire project, but adding allow(needless_pass_by_value) to all extern functions isn't nice, either. Perhaps, jni-rs can pass such parameters by reference, but it will be just reference to pointer. What is the best approach here? 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions