Skip to content

Mute clippy transmute warnings #320

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions qmetaobject_impl/src/qobject_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ pub fn generate(input: TokenStream, is_qobject: bool, qt_version: QtVersion) ->
} else {
quote! {
#[allow(unused_variables)]
let mut obj = ::std::mem::transmute::<*mut ::std::os::raw::c_void, &mut #name #ty_generics>(o);
let mut obj = &*o;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would think you still need to cast to the right type explicitly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's why the CI is failling.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this solution looks wrong. I kept the transmute to cast to the right type as *mut, but dereferenced it now to &mut outside of the transmute.

}
};

Expand Down Expand Up @@ -875,7 +875,12 @@ pub fn generate(input: TokenStream, is_qobject: bool, qt_version: QtVersion) ->
.map(|arg| {
let n = &arg.name;
let ty = &arg.typ;
quote! { unsafe { ::std::mem::transmute::<& #ty, *mut ::std::os::raw::c_void>(& #n) } }
quote! {
{
let mut n = #n;
(&mut n as *mut #ty as *mut ::std::os::raw::c_void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that doesn't look right. It seems it's taking the address of n on the stack.

Copy link
Author

@Sh3Rm4n Sh3Rm4n Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either. This could be catched by the compiler? The code I've tested did not generate any errors. The let binding was necessary to get a mutable reference &mut. The compiler suggests to annotate the function argument with mut. I'll check if that is possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it might not be catched by the compiler since the user of the pointer uses unsafe code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I now use marked the function argument as mut so that a &mut reference can be taken.

}
}
})
.collect();
let array_size = signal.args.len() + 1;
Expand Down
Loading