Skip to content

Commit

Permalink
Allow 'static in native functions
Browse files Browse the repository at this point in the history
Reviewed By: JakobDegen

Differential Revision: D59382674

fbshipit-source-id: e2647e9d974554ba7ee01076cbdbfd8d2db1f600
  • Loading branch information
stepancheg authored and facebook-github-bot committed Jul 6, 2024
1 parent a48557f commit 4ed9ec3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions starlark-rust/starlark/src/tests/derive/module/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::values::list_or_tuple::UnpackListOrTuple;
use crate::values::Heap;
use crate::values::StringValue;
use crate::values::Value;
use crate::values::ValueOfUnchecked;

// The examples from the starlark_module documentation.
#[test]
Expand Down Expand Up @@ -61,3 +62,15 @@ fn test_starlark_methods() {

MethodsBuilder::new().with(methods).build();
}

#[test]
fn test_static_allowed() {
#[starlark_module]
fn globals(globals: &mut GlobalsBuilder) {
fn test<'v>() -> anyhow::Result<ValueOfUnchecked<'v, &'static str>> {
panic!()
}
}

GlobalsBuilder::standard().with(globals).build();
}
2 changes: 1 addition & 1 deletion starlark-rust/starlark_derive/src/module/parse/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ fn check_lifetimes_in_type(ty: &Type, has_v: bool) -> syn::Result<()> {
#[allow(clippy::collapsible_if)]
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
if self.result.is_ok() {
if lifetime.ident != "_" {
if lifetime.ident != "_" && lifetime.ident != "static" {
if lifetime.ident != "v" {
self.result = Err(syn::Error::new(
lifetime.span(),
Expand Down

0 comments on commit 4ed9ec3

Please sign in to comment.