diff --git a/rustler_codegen/src/nif.rs b/rustler_codegen/src/nif.rs index ffee4c94..f7d65256 100644 --- a/rustler_codegen/src/nif.rs +++ b/rustler_codegen/src/nif.rs @@ -48,8 +48,12 @@ pub fn transcoder_decorator(nif_attributes: NifAttributes, fun: syn::ItemFn) -> let argument_names = create_function_params(inputs.clone()); let erl_func_name = nif_attributes .custom_name - .map(|n| syn::Ident::new(n.value().as_str(), Span::call_site())) - .unwrap_or_else(|| name.clone()); + .map(|n| n.value().to_string()) + .unwrap_or_else(|| name.clone().to_string()); + + if !erl_func_name.is_ascii() { + panic!("Only ASCII strings are supported as function names"); + } quote! { #[allow(non_camel_case_types)] diff --git a/rustler_tests/lib/rustler_test.ex b/rustler_tests/lib/rustler_test.ex index 1adaded7..ce424d40 100644 --- a/rustler_tests/lib/rustler_test.ex +++ b/rustler_tests/lib/rustler_test.ex @@ -121,7 +121,7 @@ defmodule RustlerTest do def raise_term_with_atom_error(), do: err() def term_with_tuple_error(), do: err() - def nif_attrs_can_rename(), do: err() + def nif_attrs_can_rename!(), do: err() def add_from_tuple(_tuple), do: err() def add_one_to_tuple(_tuple), do: err() diff --git a/rustler_tests/native/rustler_test/src/test_nif_attrs.rs b/rustler_tests/native/rustler_test/src/test_nif_attrs.rs index 1c40c22c..e992d0b8 100644 --- a/rustler_tests/native/rustler_test/src/test_nif_attrs.rs +++ b/rustler_tests/native/rustler_test/src/test_nif_attrs.rs @@ -1,4 +1,4 @@ -#[rustler::nif(name = "nif_attrs_can_rename")] +#[rustler::nif(name = "nif_attrs_can_rename!")] pub fn can_rename() -> bool { true } diff --git a/rustler_tests/test/nif_attrs_test.exs b/rustler_tests/test/nif_attrs_test.exs index 1e916c91..6805436e 100644 --- a/rustler_tests/test/nif_attrs_test.exs +++ b/rustler_tests/test/nif_attrs_test.exs @@ -2,6 +2,6 @@ defmodule NifAttrsTest do use ExUnit.Case test "can rename a NIF with an attribute" do - assert RustlerTest.nif_attrs_can_rename() + assert RustlerTest.nif_attrs_can_rename!() end end