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

fix(macos): suppress unused_variables warning reported only in release build #790

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Dec 7, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

This PR fixes the warning when building this crate in release mode as follows:

$ cargo build --release
   Compiling wry v0.23.1 (/Users/rhysd/Develop/github.com/tauri-apps/wry)
warning: unused variable: `description`
   --> src/webview/wkwebview/download.rs:105:9
    |
105 |     let description = NSString(description).to_str().to_string();
    |         ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_description`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: `wry` (lib) generated 1 warning
    Finished release [optimized] target(s) in 2.31s

The description variable is used only when debug_assertions is enabled.

@rhysd rhysd requested a review from a team as a code owner December 7, 2022 06:34
@@ -102,6 +102,7 @@ pub extern "C" fn download_did_finish(this: &Object, _: Sel, download: id) {
pub extern "C" fn download_did_fail(this: &Object, _: Sel, download: id, error: id, _: id) {
unsafe {
let description: id = msg_send![error, localizedDescription];
#[allow(unused_variables)]
Copy link
Member

@wusyong wusyong Dec 7, 2022

Choose a reason for hiding this comment

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

How about we move these to debug_assertions below? And rename error to _error.

#[cfg(debug_assertions)]
{
    let description: id = msg_send![_error, localizedDescription];
    let description = NSString(description).to_str().to_string();
    eprintln!("Download failed with error: {}", description);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks better since allocation can be avoided. I'll have a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wusyong I revised my patch and force-pushed as e73c4e6

@wusyong wusyong merged commit 4e23c0f into tauri-apps:dev Dec 7, 2022
@github-actions github-actions bot mentioned this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants