Skip to content
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

Prevent clippy from tripping lint #1121

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Conversation

kristof-mattei
Copy link
Contributor

The following code

#[cxx_qt::bridge]
pub mod my_object {

    unsafe extern "RustQt" {
        #[qobject]
        #[qml_element]
        type Hello = super::HelloRust;
    }

    unsafe extern "RustQt" {
        #[qinvokable]
        pub fn say_hello(self: &Hello);
    }
}

#[derive(Default)]
pub struct HelloRust {}

impl my_object::Hello {
    pub fn say_hello(&self) {
        println!("Hello world!");
    }
}

Triggers

❮ cargo clippy -- -W clippy::pedantic
   Compiling qt-test v0.0.0-development (/Users/kristof/sources/kristof-mattei/qt-test)
warning: boxed return of the sized type `cxxqt_object::HelloRust`
 --> src/cxxqt_object.rs:1:1
  |
1 | #[cxx_qt::bridge]
  | ^^^^^^^^^^^^^^^^^
  |
  = help: changing this also requires a change to the return expressions in this function
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns
  = note: `-W clippy::unnecessary-box-returns` implied by `-W clippy::pedantic`
  = help: to override `-W clippy::pedantic` add `#[allow(clippy::unnecessary_box_returns)]`
  = note: this warning originates in the attribute macro `cxx_qt::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `qt-test` (bin "qt-test") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 11.27s

I have clippy::pedantic on and disable the ones I don't need, but I cannot disable this inside of the macro.

And since the macro always returns a Box I don't believe there is any harm in allowing it there.

@ahayzen-kdab
Copy link
Collaborator

Thanks! This looks good, i assume there aren't any other boxes we have that also trigger this 🤔 And note that the CI failures are unrelated to this branch and are regressions happening on main too.

@ahayzen-kdab ahayzen-kdab added the backport-candidate Change which could be backported to the stable series label Nov 15, 2024
@kristof-mattei
Copy link
Contributor Author

Thanks! This looks good, i assume there aren't any other boxes we have that also trigger this 🤔 And note that the CI failures are unrelated to this branch and are regressions happening on main too.

Went through the code base, updated the other instance where an std::boxed::Box is returned, and updated the expected test outputs.

Equally, ran tests and no errors returned contained either boxed or unnecessary_box_returns , to ensure I actually covered all cases.

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d8f0f98) to head (54aa4aa).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1121   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        71           
  Lines        11962     11967    +5     
=========================================
+ Hits         11962     11967    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Collaborator

@ahayzen-kdab ahayzen-kdab left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ahayzen-kdab ahayzen-kdab enabled auto-merge (rebase) November 25, 2024 13:17
@ahayzen-kdab ahayzen-kdab merged commit f5afefe into KDAB:main Nov 25, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-candidate Change which could be backported to the stable series
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants