Skip to content

Not sound to use lifetimes in function signatures #1187

Open
@attente

Description

@attente

Seems like wasm-bindgen prohibits the use of lifetime specifiers in certain places where the compiler requires them. I have a test repo here: https://github.com/attente/wasm-bindgen-lifetime-issue

Building it, the error is:

[nix-shell:~/wasm-bindgen-lifetime-issue]$ cargo build --release --target=wasm32-unknown-unknown
   Compiling wasm-bindgen-lifetime-issue v0.1.0 (/home/william/wasm-bindgen-lifetime-issue)
error: it is currently not sound to use lifetimes in function signatures
  --> src/lib.rs:10:31
   |
10 |     pub fn f() -> Result<(), &'static str> {
   |                               ^^^^^^^

error: aborting due to previous error

error: Could not compile `wasm-bindgen-lifetime-issue`.

To learn more, run the command again with --verbose.

Unfortunately if I remove the 'static lifetime specifier, then the compiler will complain:

[nix-shell:~/wasm-bindgen-lifetime-issue]$ cargo build --release --target=wasm32-unknown-unknown
   Compiling wasm-bindgen-lifetime-issue v0.1.0 (/home/william/wasm-bindgen-lifetime-issue)
error[E0106]: missing lifetime specifier
  --> src/lib.rs:10:30
   |
10 |     pub fn f() -> Result<(), &str> {
   |                              ^ help: consider giving it a 'static lifetime: `&'static`
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from

error: aborting due to previous error

For more information about this error, try `rustc --explain E0106`.
error: Could not compile `wasm-bindgen-lifetime-issue`.

To learn more, run the command again with --verbose.

Is there any workaround for this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    more-typesAdding support for more Rust types to cross the boundary

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions