-
Notifications
You must be signed in to change notification settings - Fork 92
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
base: master
Are you sure you want to change the base?
Conversation
* `clippy::transmute_ptr_to_ref` for QGadget * `clippy::useless_transmute` for QObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR.
But i'm not sure if this is correct, see inline comments.
qmetaobject_impl/src/qobject_impl.rs
Outdated
quote! { | ||
{ | ||
let mut n = #n; | ||
(&mut n as *mut #ty as *mut ::std::os::raw::c_void) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
qmetaobject_impl/src/qobject_impl.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Overall these changes are all inside of |
b6d98e5
to
fdf587c
Compare
Alright, I'm not sure what caused this failure https://github.com/woboq/qmetaobject-rs/actions/runs/14596502246/job/40950448403, I could reproduce it locally, but also after reverting my changes (if I haven't done anything incorrectly). As my goal is to mute the clippy warnigs, let's see if |
I think this could be done without transmute, only with pointer cast |
Alright, with the last CI run https://github.com/woboq/qmetaobject-rs/actions/runs/14612927424/job/41009015057 and the current change master...Sh3Rm4n:qmetaobject-rs:4622085296b20e2fb27bf081d64c9216a1502c04 (which does no code changes) I think the CI failure is not related to this PR |
Indeed, the CI seems broken in master :-( |
clippy::transmute_ptr_to_ref
for QGadgetclippy::useless_transmute
for QObjectCloses #291