Skip to content

Commit

Permalink
Add a deprecation warning for the std feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Jul 22, 2024
1 parent 41c193e commit 11a2482
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion enumset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ alloc = []
proc-macro-crate = ["enumset_derive/proc-macro-crate"]

# Deprecated features
std = ["alloc", "enumset_derive/proc-macro-crate"]
std = ["alloc", "enumset_derive/proc-macro-crate", "enumset_derive/std_deprecation_warning"]

[package.metadata.docs.rs]
all-features = true
Expand Down
1 change: 1 addition & 0 deletions enumset_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ proc-macro = true

[features]
serde = []
std_deprecation_warning = []

[dependencies]
darling = { version = "0.20", default-features = false }
Expand Down
20 changes: 15 additions & 5 deletions enumset_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,16 +871,18 @@ fn enum_set_type_impl(info: EnumSetInfo, warnings: Vec<(Span, &'static str)>) ->
#[proc_macro_derive(EnumSetType, attributes(enumset))]
pub fn derive_enum_set_type(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input);
let input_span = input.span();
let attrs: EnumsetAttrs = match EnumsetAttrs::from_derive_input(&input) {
Ok(attrs) => attrs,
Err(e) => return e.write_errors().into(),
};
match derive_enum_set_type_0(input, attrs) {
Ok(v) => v,
Err(e) => e.to_compile_error().into(),
}
derive_enum_set_type_0(input, attrs, input_span).unwrap_or_else(|e| e.to_compile_error().into())
}
fn derive_enum_set_type_0(input: DeriveInput, attrs: EnumsetAttrs) -> Result<TokenStream> {
fn derive_enum_set_type_0(
input: DeriveInput,
attrs: EnumsetAttrs,
_input_span: Span,
) -> Result<TokenStream> {
if !input.generics.params.is_empty() {
error(
input.generics.span(),
Expand Down Expand Up @@ -932,6 +934,14 @@ fn derive_enum_set_type_0(input: DeriveInput, attrs: EnumsetAttrs) -> Result<Tok
Use `#[enumset(serialize_repr = \"list\")]` instead.",
));
}
#[cfg(feature = "std_deprecation_warning")]
{
warnings.push((
_input_span,
"feature = \"std\" is depercated. If you rename `enumset`, use \
feature = \"proc-macro-crate\" instead. If you don't, remove the feature.",
));
}

// Parse enum variants
for variant in &data.variants {
Expand Down
1 change: 1 addition & 0 deletions enumset_test_trybuild/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 11a2482

Please sign in to comment.