From 807bdb48e4d6af82fdb894c0b702e869458591a8 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 2 Mar 2024 11:55:19 +0100 Subject: [PATCH] Revert "Allow using `'static` lifetimes in functions (#3856)" (#3865) --- CHANGELOG.md | 5 -- crates/macro-support/src/parser.rs | 12 ++-- crates/macro/ui-tests/invalid-imports-1.rs | 41 ------------ .../macro/ui-tests/invalid-imports-1.stderr | 65 ------------------- crates/macro/ui-tests/invalid-imports-2.rs | 8 --- .../macro/ui-tests/invalid-imports-2.stderr | 5 -- crates/macro/ui-tests/invalid-imports.rs | 2 - crates/macro/ui-tests/invalid-imports.stderr | 6 ++ 8 files changed, 11 insertions(+), 133 deletions(-) delete mode 100644 crates/macro/ui-tests/invalid-imports-1.rs delete mode 100644 crates/macro/ui-tests/invalid-imports-1.stderr delete mode 100644 crates/macro/ui-tests/invalid-imports-2.rs delete mode 100644 crates/macro/ui-tests/invalid-imports-2.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index b4c87dd8df4..8004077535b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,11 +21,6 @@ * Allow overriding the URL used for headless tests by setting `WASM_BINDGEN_TEST_ADDRESS`. [#3861](https://github.com/rustwasm/wasm-bindgen/pull/3861) -### Changed - -* Allow using `'static` lifetimes in functions marked with `#[wasm_bindgen]`. This does not allow references where they were not allowed before! - [#3856](https://github.com/rustwasm/wasm-bindgen/pull/3856) - ### Fixed * Make .wasm output deterministic when using `--reference-types`. diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 5778eb50d41..eee4f66e95d 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -1652,14 +1652,12 @@ fn assert_no_lifetimes(sig: &syn::Signature) -> Result<(), Diagnostic> { } impl<'ast> syn::visit::Visit<'ast> for Walk { - 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 \ + 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 \ signatures" - )); - } + )); } } let mut walk = Walk { diff --git a/crates/macro/ui-tests/invalid-imports-1.rs b/crates/macro/ui-tests/invalid-imports-1.rs deleted file mode 100644 index e73ab2162d3..00000000000 --- a/crates/macro/ui-tests/invalid-imports-1.rs +++ /dev/null @@ -1,41 +0,0 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - type A; - - #[wasm_bindgen(method)] - fn f1(); - #[wasm_bindgen(method)] - fn f2(x: u32); - #[wasm_bindgen(method)] - fn f3(x: &&u32); - #[wasm_bindgen(method)] - fn f4(x: &foo::Bar); - #[wasm_bindgen(method)] - fn f4(x: &::Bar); - #[wasm_bindgen(method)] - fn f4(x: &Bar); - #[wasm_bindgen(method)] - fn f4(x: &dyn Fn(T)); - - #[wasm_bindgen(constructor)] - fn f(); - #[wasm_bindgen(constructor)] - fn f() -> ::Bar; - #[wasm_bindgen(constructor)] - fn f() -> &Bar; - - #[wasm_bindgen(catch)] - fn f() -> u32; - #[wasm_bindgen(catch)] - fn f() -> &u32; - #[wasm_bindgen(catch)] - fn f() -> Result<>; - #[wasm_bindgen(catch)] - fn f() -> Result<'a>; - #[wasm_bindgen(catch)] - fn f() -> Result<&'static u32>; -} - -fn main() {} diff --git a/crates/macro/ui-tests/invalid-imports-1.stderr b/crates/macro/ui-tests/invalid-imports-1.stderr deleted file mode 100644 index 24367ed92a9..00000000000 --- a/crates/macro/ui-tests/invalid-imports-1.stderr +++ /dev/null @@ -1,65 +0,0 @@ -error: imported methods must have at least one argument - --> ui-tests/invalid-imports-1.rs:8:5 - | -8 | fn f1(); - | ^^^^^^^^ - -error: first argument of method must be a shared reference - --> ui-tests/invalid-imports-1.rs:10:14 - | -10 | fn f2(x: u32); - | ^^^ - -error: first argument of method must be a path - --> ui-tests/invalid-imports-1.rs:12:15 - | -12 | fn f3(x: &&u32); - | ^^^^ - -error: paths with type parameters are not supported yet - --> ui-tests/invalid-imports-1.rs:18:15 - | -18 | fn f4(x: &Bar); - | ^^^^^^ - -error: first argument of method must be a path - --> ui-tests/invalid-imports-1.rs:20:15 - | -20 | fn f4(x: &dyn Fn(T)); - | ^^^^^^^^^ - -error: constructor returns must be bare types - --> ui-tests/invalid-imports-1.rs:23:5 - | -23 | fn f(); - | ^^^^^^^ - -error: return value of constructor must be a bare path - --> ui-tests/invalid-imports-1.rs:27:5 - | -27 | fn f() -> &Bar; - | ^^^^^^^^^^^^^^^ - -error: must be Result<...> - --> ui-tests/invalid-imports-1.rs:30:15 - | -30 | fn f() -> u32; - | ^^^ - -error: must be Result<...> - --> ui-tests/invalid-imports-1.rs:32:15 - | -32 | fn f() -> &u32; - | ^^^^ - -error: must have at least one generic parameter - --> ui-tests/invalid-imports-1.rs:34:15 - | -34 | fn f() -> Result<>; - | ^^^^^^^^ - -error: it is currently not sound to use lifetimes in function signatures - --> ui-tests/invalid-imports-1.rs:36:22 - | -36 | fn f() -> Result<'a>; - | ^^ diff --git a/crates/macro/ui-tests/invalid-imports-2.rs b/crates/macro/ui-tests/invalid-imports-2.rs deleted file mode 100644 index 5cf461dec94..00000000000 --- a/crates/macro/ui-tests/invalid-imports-2.rs +++ /dev/null @@ -1,8 +0,0 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - fn f() -> &'static u32; -} - -fn main() {} diff --git a/crates/macro/ui-tests/invalid-imports-2.stderr b/crates/macro/ui-tests/invalid-imports-2.stderr deleted file mode 100644 index aee456ba278..00000000000 --- a/crates/macro/ui-tests/invalid-imports-2.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: cannot return references in #[wasm_bindgen] imports yet - --> ui-tests/invalid-imports-2.rs:5:15 - | -5 | fn f() -> &'static u32; - | ^^^^^^^^^^^^ diff --git a/crates/macro/ui-tests/invalid-imports.rs b/crates/macro/ui-tests/invalid-imports.rs index 7fc9e74510a..ceb7d33bf81 100644 --- a/crates/macro/ui-tests/invalid-imports.rs +++ b/crates/macro/ui-tests/invalid-imports.rs @@ -36,8 +36,6 @@ extern "C" { fn f() -> Result<>; #[wasm_bindgen(catch)] fn f() -> Result<'a>; - #[wasm_bindgen(catch)] - fn f() -> Result<&'static u32>; } fn main() {} diff --git a/crates/macro/ui-tests/invalid-imports.stderr b/crates/macro/ui-tests/invalid-imports.stderr index e1fbeb97ba2..c83c040e862 100644 --- a/crates/macro/ui-tests/invalid-imports.stderr +++ b/crates/macro/ui-tests/invalid-imports.stderr @@ -1,3 +1,9 @@ +error: it is currently not sound to use lifetimes in function signatures + --> ui-tests/invalid-imports.rs:7:16 + | +7 | fn f() -> &'static u32; + | ^^^^^^^ + error: imported methods must have at least one argument --> ui-tests/invalid-imports.rs:10:5 |