Skip to content

Commit e191844

Browse files
committed
Drop deprecated codegen features
1 parent 1552ec6 commit e191844

File tree

4 files changed

+7
-54
lines changed

4 files changed

+7
-54
lines changed

rustler/src/resource/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,3 @@ pub use monitor::Monitor;
1818
pub use registration::Registration;
1919
pub use traits::Resource;
2020
use traits::ResourceExt;
21-
22-
/// Deprecated resource registration method
23-
///
24-
/// This macro will create a local `impl Resource` for the passed type and is thus incompatible
25-
/// with upcoming Rust language changes. Please implement the `Resource` trait directly and
26-
/// register it either using the `resource_impl` attribute or using the `Env::register` method:
27-
/// ```ignore
28-
/// fn on_load(env: Env) -> bool {
29-
/// env.register::<ResourceType>().is_ok()
30-
/// }
31-
/// ```
32-
#[macro_export]
33-
macro_rules! resource {
34-
($struct_name:ty, $env: ident) => {{
35-
impl $crate::Resource for $struct_name {}
36-
$env.register::<$struct_name>().is_ok()
37-
}};
38-
}

rustler_codegen/src/init.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
11
use proc_macro2::{Span, TokenStream};
2-
use quote::{quote, quote_spanned};
2+
use quote::quote;
33
use syn::parse::{Parse, ParseStream};
4-
use syn::spanned::Spanned;
54
use syn::{Ident, Result, Token};
65

76
#[derive(Debug)]
87
pub struct InitMacroInput {
98
name: syn::Lit,
109
load: TokenStream,
11-
maybe_warning: TokenStream,
1210
}
1311

1412
impl Parse for InitMacroInput {
1513
fn parse(input: ParseStream) -> Result<Self> {
1614
let name = syn::Lit::parse(input)?;
1715

18-
let maybe_warning = if input.peek(syn::token::Comma) && input.peek2(syn::token::Bracket) {
19-
// peeked, must be there
20-
let _ = syn::token::Comma::parse(input).unwrap();
21-
if let Ok(funcs) = syn::ExprArray::parse(input) {
22-
quote_spanned!(funcs.span() =>
23-
#[allow(dead_code)]
24-
fn rustler_init() {
25-
#[deprecated(
26-
since = "0.34.0",
27-
note = "Passing NIF functions explicitly is deprecated and this argument is ignored, please remove it"
28-
)]
29-
#[allow(non_upper_case_globals)]
30-
const explicit_nif_functions: () = ();
31-
let _ = explicit_nif_functions;
32-
}
33-
)
34-
} else {
35-
quote!()
36-
}
37-
} else {
38-
quote!()
39-
};
40-
4116
let options = parse_expr_assigns(input);
4217
let load = extract_option(options, "load");
4318

4419
Ok(InitMacroInput {
4520
name,
46-
load,
47-
maybe_warning,
21+
load
4822
})
4923
}
5024
}
@@ -81,7 +55,6 @@ impl From<InitMacroInput> for proc_macro2::TokenStream {
8155
fn from(input: InitMacroInput) -> Self {
8256
let name = input.name;
8357
let load = input.load;
84-
let maybe_warning = input.maybe_warning;
8558

8659
let inner = quote! {
8760
static mut NIF_ENTRY: Option<rustler::codegen_runtime::DEF_NIF_ENTRY> = None;
@@ -166,8 +139,6 @@ impl From<InitMacroInput> for proc_macro2::TokenStream {
166139
};
167140

168141
quote! {
169-
#maybe_warning
170-
171142
#[cfg(not(windows))]
172143
#[no_mangle]
173144
extern "C" fn #nif_init_name() -> *const ::rustler::codegen_runtime::DEF_NIF_ENTRY {

rustler_tests/native/rustler_test/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ mod test_term;
1919
mod test_thread;
2020
mod test_tuple;
2121

22-
// Intentional usage of the explicit form (in an "invalid" way, listing a wrong set of functions) to ensure that the warning stays alive
23-
rustler::init!("Elixir.RustlerTest", [deprecated, usage], load = load);
22+
rustler::init!("Elixir.RustlerTest", load = load);
2423

2524
fn load(env: rustler::Env, _: rustler::Term) -> bool {
2625
test_resource::on_load(env)

rustler_tests/native/rustler_test/src/test_resource.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub struct TestResource {
55
test_field: RwLock<i32>,
66
}
77

8+
#[rustler::resource_impl]
9+
impl Resource for TestResource {}
10+
811
struct TestMonitorResourceInner {
912
mon: Option<Monitor>,
1013
down_called: bool,
@@ -42,9 +45,7 @@ pub struct WithBinaries {
4245
impl Resource for WithBinaries {}
4346

4447
pub fn on_load(env: Env) -> bool {
45-
rustler::resource!(TestResource, env)
46-
&& env.register::<WithBinaries>().is_ok()
47-
&& env.register::<ImmutableResource>().is_ok()
48+
env.register::<WithBinaries>().is_ok() && env.register::<ImmutableResource>().is_ok()
4849
}
4950

5051
#[rustler::nif]

0 commit comments

Comments
 (0)