Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion soroban-sdk-macros/src/derive_event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
attribute::remove_attributes_from_item, default_crate_path, doc::docs_from_attrs,
export_arg_v2_deprecation, map_type::map_type, shaking, symbol, DEFAULT_XDR_RW_LIMITS,
export_arg_v2_deprecation, lib_arg_deprecation, map_type::map_type, shaking, symbol,
DEFAULT_XDR_RW_LIMITS,
};
use darling::{ast::NestedMeta, Error, FromMeta};
use heck::ToSnakeCase;
Expand Down Expand Up @@ -68,12 +69,14 @@ fn derive_event_or_err(metadata: TokenStream2, input: TokenStream2) -> Result<To
let args = ContractEventArgs::from_list(&args)?;
let input = parse2::<DeriveInput>(input)?;
let export_deprecation = export_arg_v2_deprecation(&args.export, &input.ident);
let lib_deprecation = lib_arg_deprecation(&args.lib, &input.ident);
let derived = derive_impls(&args, &input)?;
let mut input = input;
remove_attributes_from_item(&mut input.data, &["topic", "data"]);
Ok(quote! {
#input
#export_deprecation
#lib_deprecation
#derived
}
.into())
Expand Down
22 changes: 22 additions & 0 deletions soroban-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ pub(crate) fn export_arg_v2_deprecation(export: &Option<bool>, ident: &syn::Iden
}
}

/// Emit a deprecation warning when `lib` is set on a contract type, error, or
/// event. The argument is a vestige of an earlier design that was never used
/// and will be removed in a future release.
pub(crate) fn lib_arg_deprecation(lib: &Option<String>, ident: &syn::Ident) -> TokenStream2 {
if lib.is_some() {
let marker = format_ident!("__SOROBAN_LIB_ARG_DEPRECATED_FOR_{}", ident);
quote! {
#[doc(hidden)]
#[allow(non_upper_case_globals)]
#[deprecated = "`lib` is deprecated and will be removed in a future release"]
const #marker: () = ();
const _: () = #marker;
}
} else {
TokenStream2::new()
}
}

#[proc_macro]
pub fn internal_symbol_short(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand Down Expand Up @@ -456,6 +474,7 @@ pub fn contracttype(metadata: TokenStream, input: TokenStream) -> TokenStream {
Err(e) => return e.to_compile_error().into(),
}
let export_deprecation = export_arg_v2_deprecation(&args.export, ident);
let lib_deprecation = lib_arg_deprecation(&args.lib, ident);
// Under `experimental_spec_shaking_v2` the spec is always emitted and
// reachability determines what is retained, so the `export` argument is
// ignored (a deprecation warning is emitted above). Otherwise, honor an
Expand Down Expand Up @@ -512,6 +531,7 @@ pub fn contracttype(metadata: TokenStream, input: TokenStream) -> TokenStream {
quote! {
#input
#export_deprecation
#lib_deprecation
#derived
}
.into()
Expand All @@ -533,6 +553,7 @@ pub fn contracterror(metadata: TokenStream, input: TokenStream) -> TokenStream {
let ident = &input.ident;
let attrs = &input.attrs;
let export_deprecation = export_arg_v2_deprecation(&args.export, ident);
let lib_deprecation = lib_arg_deprecation(&args.lib, ident);
// Under `experimental_spec_shaking_v2` the spec is always emitted and
// reachability determines what is retained, so the `export` argument is
// ignored (a deprecation warning is emitted above). Otherwise, honor an
Expand Down Expand Up @@ -567,6 +588,7 @@ pub fn contracterror(metadata: TokenStream, input: TokenStream) -> TokenStream {
quote! {
#input
#export_deprecation
#lib_deprecation
#derived
}
.into()
Expand Down
1 change: 1 addition & 0 deletions soroban-sdk/tests/compile_fails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
fn compile_fails() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/compile_fails/contracttrait_cfg_errors.rs");
t.compile_fail("tests/compile_fails/contracttype_lib_deprecated.rs");
}
25 changes: 25 additions & 0 deletions soroban-sdk/tests/compile_fails/contracttype_lib_deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Setting `lib` on `contracttype`, `contracterror`, or `contractevent` is
// deprecated. With the `deprecated` lint denied, using it must fail to compile,
// proving the deprecation warning is emitted.
#![deny(deprecated)]

use soroban_sdk::{contracterror, contractevent, contracttype};

#[contracttype(lib = "libname")]
pub struct S {
pub a: u32,
}

#[contracterror(lib = "libname")]
#[derive(Copy, Clone)]
#[repr(u32)]
pub enum E {
A = 1,
}

#[contractevent(lib = "libname")]
pub struct Ev {
pub a: u32,
}

fn main() {}
23 changes: 23 additions & 0 deletions soroban-sdk/tests/compile_fails/contracttype_lib_deprecated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: use of deprecated constant `__SOROBAN_LIB_ARG_DEPRECATED_FOR_S`: `lib` is deprecated and will be removed in a future release
--> tests/compile_fails/contracttype_lib_deprecated.rs:9:12
|
9 | pub struct S {
| ^
|
note: the lint level is defined here
--> tests/compile_fails/contracttype_lib_deprecated.rs:4:9
|
4 | #![deny(deprecated)]
| ^^^^^^^^^^

error: use of deprecated constant `__SOROBAN_LIB_ARG_DEPRECATED_FOR_E`: `lib` is deprecated and will be removed in a future release
--> tests/compile_fails/contracttype_lib_deprecated.rs:16:10
|
16 | pub enum E {
| ^

error: use of deprecated constant `__SOROBAN_LIB_ARG_DEPRECATED_FOR_Ev`: `lib` is deprecated and will be removed in a future release
--> tests/compile_fails/contracttype_lib_deprecated.rs:21:12
|
21 | pub struct Ev {
| ^^
Loading