diff --git a/derive_builder_core/src/builder.rs b/derive_builder_core/src/builder.rs index 3b1a515..72824f2 100644 --- a/derive_builder_core/src/builder.rs +++ b/derive_builder_core/src/builder.rs @@ -5,9 +5,7 @@ use quote::{format_ident, ToTokens, TokenStreamExt}; use syn::punctuated::Punctuated; use syn::{Path, TraitBound, TraitBoundModifier, TypeParamBound}; -use crate::{ - doc_comment_from, BuildMethod, BuilderField, BuilderPattern, DeprecationNotes, Setter, -}; +use crate::{doc_comment_from, BuildMethod, BuilderField, BuilderPattern, Setter}; const ALLOC_NOT_ENABLED_ERROR: &str = r#"`alloc` is disabled within 'derive_builder', consider one of the following: * enable feature `alloc` on 'dervie_builder' if a `global_allocator` is present @@ -146,8 +144,6 @@ pub struct Builder<'a> { pub must_derive_clone: bool, /// Doc-comment of the builder struct. pub doc_comment: Option, - /// Emit deprecation notes to the user. - pub deprecation_notes: DeprecationNotes, /// Whether or not a libstd is used. pub std: bool, } @@ -192,7 +188,6 @@ impl<'a> ToTokens for Builder<'a> { let impl_attrs = self.impl_attrs; let builder_doc_comment = &self.doc_comment; - let deprecation_notes = &self.deprecation_notes.as_item(); #[cfg(not(feature = "clippy"))] tokens.append_all(quote!(#[allow(clippy::all)])); @@ -217,7 +212,6 @@ impl<'a> ToTokens for Builder<'a> { #[allow(dead_code)] impl #impl_generics #builder_ident #impl_ty_generics #impl_where_clause { #(#functions)* - #deprecation_notes /// Create an empty builder, with all fields set to `None` or `PhantomData`. fn #create_empty() -> Self { @@ -396,7 +390,6 @@ macro_rules! default_builder { no_alloc: false, must_derive_clone: true, doc_comment: None, - deprecation_notes: DeprecationNotes::default(), std: true, } }; diff --git a/derive_builder_core/src/deprecation_notes.rs b/derive_builder_core/src/deprecation_notes.rs deleted file mode 100644 index 8bea557..0000000 --- a/derive_builder_core/src/deprecation_notes.rs +++ /dev/null @@ -1,103 +0,0 @@ -use proc_macro2::{Span, TokenStream}; -use quote::{ToTokens, TokenStreamExt}; - -/// Deprecation notes we want to emit to the user, implementing -/// `quote::ToTokens`. -/// -/// Can be expanded at every place that accepts statements and item definitions -/// (e.g. function bodys). -/// -/// # Examples -/// -/// Will expand to something like the following (depending on settings): -/// -/// ```rust,ignore -/// # #[macro_use] -/// # extern crate quote; -/// # extern crate derive_builder_core; -/// # use derive_builder_core::DeprecationNotes; -/// # fn main() { -/// # let mut note = DeprecationNotes::default(); -/// # note.push("Some Warning".to_string()); -/// # assert_eq!(quote!(#note).to_string(), quote!( -/// { -/// #[deprecated(note = "Some Warning")] -/// fn derive_builder_core_deprecation_note() { } -/// derive_builder_core_deprecation_note(); -/// } -/// # ).to_string()); -/// # } -/// ``` -/// -/// This will emit a deprecation warning in the downstream crate. Cool stuff. ^^ -/// -/// Proof of concept: -/// - -#[derive(Debug, Default, Clone)] -pub struct DeprecationNotes(Vec); - -impl ToTokens for DeprecationNotes { - fn to_tokens(&self, tokens: &mut TokenStream) { - for note in &self.0 { - let fn_ident = - syn::Ident::new("derive_builder_core_deprecation_note", Span::call_site()); - tokens.append_all(quote!( - { - #[deprecated(note=#note)] - fn #fn_ident() { } - #fn_ident(); - } - )); - } - } -} - -impl DeprecationNotes { - /// Appends a note to the collection. - #[cfg(test)] - pub fn push(&mut self, note: String) { - self.0.push(note) - } - - /// Create a view of these deprecation notes that can annotate a struct. - pub const fn as_item(&self) -> DeprecationNotesAsItem { - DeprecationNotesAsItem(self) - } -} - -/// A view of `DeprecationNotes` that can be used in any context that accept -/// items. -/// -/// Expands to a function `__deprecation_notes` which emits the notes. -#[derive(Debug)] -pub struct DeprecationNotesAsItem<'a>(&'a DeprecationNotes); - -impl<'a> ToTokens for DeprecationNotesAsItem<'a> { - fn to_tokens(&self, tokens: &mut TokenStream) { - let deprecation_notes = self.0; - - if !deprecation_notes.0.is_empty() { - tokens.append_all(quote!( - #[doc(hidden)] - fn derive_builder_core_deprecation_note() { - #deprecation_notes - } - )) - } - } -} - -#[test] -fn deprecation_note() { - let mut note = DeprecationNotes::default(); - note.push("Some Warning".to_string()); - assert_eq!( - quote!(#note).to_string(), - quote!({ - #[deprecated(note = "Some Warning")] - fn derive_builder_core_deprecation_note() {} - derive_builder_core_deprecation_note(); - }) - .to_string() - ); -} diff --git a/derive_builder_core/src/lib.rs b/derive_builder_core/src/lib.rs index 57e5989..6d2e71e 100644 --- a/derive_builder_core/src/lib.rs +++ b/derive_builder_core/src/lib.rs @@ -33,7 +33,6 @@ mod builder; mod builder_field; mod change_span; mod default_expression; -mod deprecation_notes; mod doc_comment; mod initializer; mod macro_options; @@ -47,7 +46,6 @@ pub(crate) use builder_field::{BuilderField, BuilderFieldType}; pub(crate) use change_span::change_span; use darling::FromDeriveInput; pub(crate) use default_expression::DefaultExpression; -pub(crate) use deprecation_notes::DeprecationNotes; pub(crate) use doc_comment::doc_comment_from; pub(crate) use initializer::{FieldConversion, Initializer}; pub(crate) use options::{BuilderPattern, Each}; diff --git a/derive_builder_core/src/macro_options/darling_opts.rs b/derive_builder_core/src/macro_options/darling_opts.rs index cb7c47a..3894b78 100644 --- a/derive_builder_core/src/macro_options/darling_opts.rs +++ b/derive_builder_core/src/macro_options/darling_opts.rs @@ -10,7 +10,7 @@ use syn::{spanned::Spanned, Attribute, Generics, Ident, Meta, Path}; use crate::{ BlockContents, Builder, BuilderField, BuilderFieldType, BuilderPattern, DefaultExpression, - DeprecationNotes, Each, FieldConversion, Initializer, Setter, + Each, FieldConversion, Initializer, Setter, }; #[derive(Debug, Clone)] @@ -587,9 +587,6 @@ pub struct Options { #[darling(default)] field: VisibilityAttr, - - #[darling(skip, default)] - deprecation_notes: DeprecationNotes, } /// Accessors for parsed properties. @@ -689,7 +686,6 @@ impl Options { no_alloc: cfg!(not(any(feature = "alloc", feature = "lib_has_std"))), must_derive_clone: self.requires_clone(), doc_comment: None, - deprecation_notes: Default::default(), std: !self.no_std.is_present(), } } @@ -855,10 +851,6 @@ impl<'a> FieldWithDefaults<'a> { pub fn use_parent_default(&self) -> bool { self.field.default.is_none() && self.parent.default.is_some() } - - pub fn deprecation_notes(&self) -> &DeprecationNotes { - &self.parent.deprecation_notes - } } /// Converters to codegen structs @@ -877,7 +869,6 @@ impl<'a> FieldWithDefaults<'a> { field_type: self.field_type(), generic_into: self.setter_into(), strip_option: self.setter_strip_option(), - deprecation_notes: self.deprecation_notes(), each: self.field.setter.each.as_ref(), } } diff --git a/derive_builder_core/src/setter.rs b/derive_builder_core/src/setter.rs index ed019f1..2f6bdb8 100644 --- a/derive_builder_core/src/setter.rs +++ b/derive_builder_core/src/setter.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use proc_macro2::{Span, TokenStream}; use quote::{ToTokens, TokenStreamExt}; -use crate::{BuilderFieldType, BuilderPattern, DeprecationNotes, Each}; +use crate::{BuilderFieldType, BuilderPattern, Each}; /// Setter for the struct fields in the build method, implementing /// `quote::ToTokens`. @@ -62,8 +62,6 @@ pub struct Setter<'a> { /// Make the setter remove the Option wrapper from the setter, remove the need to call Some(...). /// when combined with into, the into is used on the content Type of the Option. pub strip_option: bool, - /// Emit deprecation notes to the user. - pub deprecation_notes: &'a DeprecationNotes, /// Emit extend method. pub each: Option<&'a Each>, } @@ -77,7 +75,6 @@ impl<'a> ToTokens for Setter<'a> { let field_ident = self.field_ident; let ident = &self.ident; let attrs = self.attrs; - let deprecation_notes = self.deprecation_notes; let self_param: TokenStream; let return_ty: TokenStream; @@ -143,7 +140,6 @@ impl<'a> ToTokens for Setter<'a> { #vis fn #ident #ty_params (#self_param, value: #param_ty) -> #return_ty { - #deprecation_notes let mut new = #self_into_return_ty; new.#field_ident = #into_value; new @@ -214,7 +210,6 @@ impl<'a> ToTokens for Setter<'a> { where #ty: #crate_root::export::core::default::Default + #crate_root::export::core::iter::Extend, { - #deprecation_notes let mut new = #self_into_return_ty; new.#field_ident .#get_initialized_collection @@ -299,7 +294,6 @@ macro_rules! default_setter { field_type: BuilderFieldType::Optional(Box::leak(Box::new(parse_quote!(Foo)))), generic_into: false, strip_option: false, - deprecation_notes: &Default::default(), each: None, } }; @@ -508,13 +502,9 @@ mod tests { //let attrs = outer_attrs.parse_str("#[some_attr]").unwrap(); let attrs: Vec = vec![parse_quote!(#[some_attr])]; - let mut deprecated = DeprecationNotes::default(); - deprecated.push("Some example.".to_string()); - let mut setter = default_setter!(); setter.attrs = attrs.as_slice(); setter.generic_into = true; - setter.deprecation_notes = &deprecated; setter.try_setter = true; assert_eq!( @@ -523,7 +513,6 @@ mod tests { #[some_attr] #[allow(unused_mut)] pub fn foo >(&mut self, value: VALUE) -> &mut Self { - #deprecated let mut new = self; new.foo = ::db::export::core::option::Option::Some(value.into()); new