-
Notifications
You must be signed in to change notification settings - Fork 347
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
Suppress unused_unsafe
warnings within the generated code.
#1415
Suppress unused_unsafe
warnings within the generated code.
#1415
Conversation
This PR is motivated by the desire to address the TODO at https://skia-review.googlesource.com/c/skia/+/928799/4/experimental/rust_png/ffi/FFI.rs |
Hmmm... when re-reading the commit / PR description, the 2nd part seems out-of-place (since there is no Let me do a quick force-push to update the commit descriptions... sorry... |
Sometimes Rust functions declared inside the `#[cxx::bridge]` have to be marked as unsafe (e.g. if they need to use an explicit lifetime). When the actual, wrapped function is _not_ unsafe, then the generated code will result in an `unused_unsafe` warning. For example: ``` Compiling cxx-test-suite v0.0.0 (/usr/local/google/home/lukasza/src/github/cxx/tests/ffi) error: unnecessary `unsafe` block --> tests/ffi/lib.rs:276:19 | 276 | unsafe fn r_return_str_via_out_param<'a>(shared: &'a Shared, out_param: &mut &'a str); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block | note: the lint level is defined here --> tests/ffi/lib.rs:20:9 | 20 | #![deny(warnings)] // Check that expansion of `cxx::bridge` doesn't trigger warnings. | ^^^^^^^^ = note: `#[deny(unused_unsafe)]` implied by `#[deny(warnings)]` ``` The warning above comes from the following expansion: ``` unsafe fn __r_return_str_via_out_param<'a>(...) { // The `unsafe` block below is unnecessary if the actual, wrapped // function is *not* `unsafe`. unsafe { super::r_return_str_via_out_param(...) } } ``` This commit avoids the warning by including an explicit `#[allow(unused_unsafe)]` in the generated code.
f1497ad
to
86e8c0c
Compare
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!
Published in 1.0.135. |
This CL updates the `WORKSPACE.bazel` dependency on `cxx` and `cxxbridge-cmd` crates to version `1.0.135`. This CL is motivated by the desire to stop suppressing warnings in the proc-macro-generated code, because in the new vesion that code should be clean of warnings (after dtolnay/cxx#1415). The following commands have been used to mirror the crates: $ go run ./bazel/gcs_mirror/gcs_mirror.go \ --url https://crates.io/api/v1/crates/cxxbridge-cmd/1.0.135/download \ --sha256 4717c9c806a9e07fdcb34c84965a414ea40fafe57667187052cf1eb7f5e8a8a9 \ --add_suffix=.tar.gz $ go run ./bazel/gcs_mirror/gcs_mirror.go \ --url https://crates.io/api/v1/crates/cxx/1.0.135/download \ --sha256 4d44ff199ff93242c3afe480ab588d544dd08d72e92885e152ffebc670f076ad \ --add_suffix=.tar.gz Bug: chromium:383521545 Change-Id: I713067e42c87384a76f42773adaf36a834a25735 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/930418 Reviewed-by: Kaylee Lubick <kjlubick@google.com> Commit-Queue: Łukasz Anforowicz <lukasza@google.com>
Sometimes Rust functions declared inside the
#[cxx::bridge]
have to be marked as unsafe (e.g. if they need to use an explicit lifetime). When the actual, wrapped function is not unsafe, then the generated code will result in anunused_unsafe
warning. For example:The warning above comes from the following expansion:
This commit avoids the warning by including an explicit
#[allow(unused_unsafe)]
in the generated code.