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

ffi struct produces warnings on +nightly #270

Open
sax opened this issue Apr 24, 2024 · 3 comments
Open

ffi struct produces warnings on +nightly #270

sax opened this issue Apr 24, 2024 · 3 comments

Comments

@sax
Copy link

sax commented Apr 24, 2024

I have a struct that I use to convert wrapped errors to strings that can be sent to Swift:

#[swift_bridge::bridge]
mod ffi {
  #[swift_bridge(swift_repr = "struct")]
  pub struct BridgedError {
    pub inner: String
  }
}

This compiles without any errors in Rust 1.77.2, but when I compile it with nightly it produces the following warning:

> cargo +nightly build -Zbuild-std --package my-bridge --target aarch64-apple-darwin

error: field `0` is never read
  --> rust/my-bridge/src/lib.rs:17:14
   |
14 | #[swift_bridge::bridge]
   | ----------------------- field in this variant
...
17 |   pub struct BridgedError {
   |              ^^^^^^^^^^^^
   |
note: the lint level is defined here
  --> rust/my-bridge/src/lib.rs:2:38
   |
2  | #![cfg_attr(feature = "strict", deny(warnings))]
   |                                      ^^^^^^^^
   = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
   |
17 |   pub struct () {
   |              ~~

I'm starting to play around with cross-compiling to watchOS, tvOS, and eventually visionOS, but am finding these targets only seem to build on nightly.

@chinedufn
Copy link
Owner

chinedufn commented Apr 28, 2024

Thanks for reporting this.

Looks like a similar to issue was opened for rustc 3 weeks ago rust-lang/rust#123418


Mind sharing a simple bridge module that reproduces this warning?

I cannot reproduce this warning using the provided example.

@Bright-Shard
Copy link
Contributor

Bright-Shard commented Apr 28, 2024

Also on nightly some of the ui tests fail to run. It looks like very minor issues - unexpected warnings (maybe related to that issue?) and some of the spans seem to have changed.

Output
test tests/ui/args-into-argument-not-found.rs ... mismatch

EXPECTED:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: Argument "arg_typo" was not found in "fn some_function(..)"
 --> tests/ui/args-into-argument-not-found.rs:7:42
  |
7 |         #[swift_bridge(args_into = (arg, arg_typo))]
  |                                          ^^^^^^^^

error: Argument "bar" was not found in "fn some_method(..)"
  --> tests/ui/args-into-argument-not-found.rs:13:42
   |
13 |         #[swift_bridge(args_into = (foo, bar))]
   |                                          ^^^
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

ACTUAL OUTPUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error: Argument "arg_typo" was not found in "fn some_function(..)"
 --> tests/ui/args-into-argument-not-found.rs:7:42
  |
7 |         #[swift_bridge(args_into = (arg, arg_typo))]
  |                                          ^^^^^^^^

error: Argument "bar" was not found in "fn some_method(..)"
  --> tests/ui/args-into-argument-not-found.rs:13:42
   |
13 |         #[swift_bridge(args_into = (foo, bar))]
   |                                          ^^^

warning: unused variable: `arg`
  --> tests/ui/args-into-argument-not-found.rs:18:18
   |
18 | fn some_function(arg: u8) {}
   |                  ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `foo`
  --> tests/ui/args-into-argument-not-found.rs:23:27
   |
23 |     fn some_method(&self, foo: u8) {}
   |                           ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
note: If the actual output is the correct output you can bless it by rerunning
      your test with the environment variable TRYBUILD=overwrite

test tests/ui/incorrect-argument-type.rs ... mismatch

EXPECTED:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0308]: mismatched types
  --> tests/ui/incorrect-argument-type.rs:15:16
   |
10 | #[swift_bridge::bridge]
   | ----------------------- arguments to this function are incorrect
...
15 |         fn fn1(arg: &str);
   |                ^^^^^^ expected `u16`, found `&str`
   |
note: function defined here
  --> tests/ui/incorrect-argument-type.rs:24:4
   |
24 | fn some_function(_arg: u16) {}
   |    ^^^^^^^^^^^^^ ---------
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

ACTUAL OUTPUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0308]: mismatched types
  --> tests/ui/incorrect-argument-type.rs:15:16
   |
10 | #[swift_bridge::bridge]
   | ----------------------- arguments to this function are incorrect
...
15 |         fn fn1(arg: &str);
   |                ^^^^^^^^^ expected `u16`, found `&str`
   |
note: function defined here
  --> tests/ui/incorrect-argument-type.rs:24:4
   |
24 | fn some_function(_arg: u16) {}
   |    ^^^^^^^^^^^^^ ---------
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
note: If the actual output is the correct output you can bless it by rerunning
      your test with the environment variable TRYBUILD=overwrite

test tests/ui/incorrect-return-type.rs ... mismatch

EXPECTED:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0308]: mismatched types
  --> tests/ui/incorrect-return-type.rs:6:1
   |
6  |   #[swift_bridge::bridge]
   |   ^^^^^^^^^^^^^^^^^^^^^^^ expected `SomeType`, found `&SomeType`
...
9  |           type SomeType;
   |  ______________-
10 | |
11 | |         #[swift_bridge(rust_name = "some_function")]
   | |_________- expected due to this
   |
   = note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> tests/ui/incorrect-return-type.rs:6:1
   |
6  |   #[swift_bridge::bridge]
   |   ^^^^^^^^^^^^^^^^^^^^^^^ expected `SomeType`, found `Option<SomeType>`
...
9  |           type SomeType;
   |  ______________-
10 | |
11 | |         #[swift_bridge(rust_name = "some_function")]
12 | |         fn fn1() -> SomeType;
13 | |         #[swift_bridge(rust_name = "another_function")]
   | |_________- expected due to this
   |
   = note: expected struct `SomeType`
                found enum `Option<SomeType>`
   = note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using `Option::expect` to unwrap the `Option<SomeType>` value, panicking if the value is an `Option::None`
   |
6  | #[swift_bridge::bridge].expect("REASON")
   |                        +++++++++++++++++
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈

ACTUAL OUTPUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
error[E0308]: mismatched types
  --> tests/ui/incorrect-return-type.rs:6:1
   |
6  |   #[swift_bridge::bridge]
   |   ^^^^^^^^^^^^^^^^^^^^^^^ expected `SomeType`, found `&SomeType`
...
9  |           type SomeType;
   |  ______________-
10 | |
11 | |         #[swift_bridge(rust_name = "some_function")]
12 | |         fn fn1() -> SomeType;
   | |_____________________________- expected due to this
   |
   = note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> tests/ui/incorrect-return-type.rs:6:1
   |
6  |   #[swift_bridge::bridge]
   |   ^^^^^^^^^^^^^^^^^^^^^^^ expected `SomeType`, found `Option<SomeType>`
...
9  |           type SomeType;
   |  ______________-
10 | |
11 | |         #[swift_bridge(rust_name = "some_function")]
12 | |         fn fn1() -> SomeType;
13 | |         #[swift_bridge(rust_name = "another_function")]
14 | |         fn fn2() -> SomeType;
   | |_____________________________- expected due to this
   |
   = note: expected struct `SomeType`
                found enum `Option<SomeType>`
   = note: this error originates in the attribute macro `swift_bridge::bridge` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using `Option::expect` to unwrap the `Option<SomeType>` value, panicking if the value is an `Option::None`
   |
6  | #[swift_bridge::bridge].expect("REASON")
   |                        +++++++++++++++++
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
note: If the actual output is the correct output you can bless it by rerunning
      your test with the environment variable TRYBUILD=overwrite

test tests/ui/invalid-associated-to-attribute.rs ... ok
test tests/ui/invalid-copy-attribute.rs ... ok
test tests/ui/invalid-module-item.rs ... ok
test tests/ui/opaque-copy-type-mut-ref.rs ... ok
test tests/ui/unrecognized-argument-attribute.rs ... ok
test tests/ui/unrecognized-enum-attribute.rs ... ok
test tests/ui/unrecognized-function-attribute.rs ... ok
test tests/ui/unrecognized-opaque-type-attribute.rs ... ok


test ui_tests::ui ... FAILED

@sax
Copy link
Author

sax commented May 2, 2024

@chinedufn Took a bit longer than expected, but here's a gist you can clone and see the issue:
https://gist.github.com/sax/9c4b3b841d15ed62fde135da28b783fa

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

No branches or pull requests

3 participants