Skip to content

Commit

Permalink
Allow using 'static lifetimes in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Feb 25, 2024
1 parent 0c09e15 commit f2e1ceb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* Add `TryFrom` implementations for `Number`, that allow losslessly converting from 64- and 128-bits numbers.
[#3847](https://github.com/rustwasm/wasm-bindgen/pull/3847)

### Changed

* Allow using `'static` lifetimes in functions marked with `#[wasm_bindgen]`.
[#3856](https://github.com/rustwasm/wasm-bindgen/pull/3856)

### Fixed

* Make .wasm output deterministic when using `--reference-types`.
Expand Down
12 changes: 7 additions & 5 deletions crates/macro-support/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,12 +1652,14 @@ fn assert_no_lifetimes(sig: &syn::Signature) -> Result<(), Diagnostic> {
}

impl<'ast> syn::visit::Visit<'ast> for Walk {
fn visit_lifetime(&mut self, i: &'ast syn::Lifetime) {
self.diagnostics.push(err_span!(
i,
"it is currently not sound to use lifetimes in function \
fn visit_lifetime(&mut self, lifetime: &'ast syn::Lifetime) {
if lifetime.ident != "static" {
self.diagnostics.push(err_span!(
lifetime,
"it is currently not sound to use lifetimes in function \
signatures"
));
));
}
}
}
let mut walk = Walk {
Expand Down
2 changes: 2 additions & 0 deletions crates/macro/ui-tests/invalid-imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern "C" {
fn f() -> Result<>;
#[wasm_bindgen(catch)]
fn f() -> Result<'a>;
#[wasm_bindgen(catch)]
fn f() -> Result<&'static u32>;
}

fn main() {}

0 comments on commit f2e1ceb

Please sign in to comment.