Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export traits #273

Merged
merged 11 commits into from
Jul 23, 2023
2 changes: 1 addition & 1 deletion impl/src/add_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn expand(input: &DeriveInput, trait_name: &str) -> TokenStream {

quote! {
#[automatically_derived]
impl #impl_generics ::core::ops::#trait_ident for #input_type #ty_generics #where_clause {
impl #impl_generics ::derive_more::#trait_ident for #input_type #ty_generics #where_clause {
type Output = #output_type;

#[inline]
Expand Down
1 change: 0 additions & 1 deletion impl/src/as_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_type_bound(
input,
trait_name,
quote! { ::core::convert },
"as_mut".into(),
AttrParams::ignore_and_forward(),
false,
Expand Down
1 change: 0 additions & 1 deletion impl/src/as_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_type_bound(
input,
trait_name,
quote! { ::core::convert },
"as_ref".into(),
AttrParams::ignore_and_forward(),
false,
Expand Down
1 change: 0 additions & 1 deletion impl/src/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_field_ignore_and_forward(
input,
trait_name,
quote! { ::core::ops },
trait_name.to_lowercase(),
)?;
let SingleFieldData {
Expand Down
1 change: 0 additions & 1 deletion impl/src/deref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_field_ignore_and_forward(
input,
trait_name,
quote! { ::core::ops },
"deref_mut".into(),
)?;
let SingleFieldData {
Expand Down
14 changes: 6 additions & 8 deletions impl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub fn expand(
let state = State::with_attr_params(
input,
trait_name,
quote! { ::derive_more::__private::Error },
trait_name.to_lowercase(),
allowed_attr_params(),
)?;
Expand All @@ -39,7 +38,7 @@ pub fn expand(

let source = source.map(|source| {
quote! {
fn source(&self) -> Option<&(dyn ::derive_more::__private::Error + 'static)> {
fn source(&self) -> Option<&(dyn ::derive_more::Error + 'static)> {
use ::derive_more::__private::AsDynError;
#source
}
Expand Down Expand Up @@ -73,7 +72,7 @@ pub fn expand(
&generics,
quote! {
where
#(#bounds: ::core::fmt::Debug + ::core::fmt::Display + ::derive_more::__private::Error + 'static),*
#(#bounds: ::core::fmt::Debug + ::core::fmt::Display + ::derive_more::Error + 'static),*
},
);
}
Expand All @@ -82,7 +81,7 @@ pub fn expand(

let render = quote! {
#[automatically_derived]
impl #impl_generics ::derive_more::__private::Error for #ident #ty_generics #where_clause {
impl #impl_generics ::derive_more::Error for #ident #ty_generics #where_clause {
#source
#provide
}
Expand Down Expand Up @@ -120,7 +119,6 @@ fn render_enum(
let state = State::from_variant(
state.input,
state.trait_name,
state.trait_module.clone(),
state.trait_attr.clone(),
allowed_attr_params(),
variant,
Expand Down Expand Up @@ -207,7 +205,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> {
let source_provider = self.source.map(|source| {
let source_expr = &self.data.members[source];
quote! {
::derive_more::__private::Error::provide(&#source_expr, demand);
::derive_more::Error::provide(&#source_expr, demand);
}
});
let backtrace_provider = self
Expand Down Expand Up @@ -237,7 +235,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> {
let pattern = self.data.matcher(&[source], &[quote! { source }]);
Some(quote! {
#pattern => {
::derive_more::__private::Error::provide(source, demand);
::derive_more::Error::provide(source, demand);
}
})
}
Expand All @@ -249,7 +247,7 @@ impl<'input, 'state> ParsedFields<'input, 'state> {
Some(quote! {
#pattern => {
demand.provide_ref::<::std::backtrace::Backtrace>(backtrace);
::derive_more::__private::Error::provide(source, demand);
::derive_more::Error::provide(source, demand);
}
})
}
Expand Down
1 change: 0 additions & 1 deletion impl/src/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::new(
input,
trait_name,
quote! { ::core::str },
trait_name.to_lowercase(),
)?;

Expand Down
1 change: 0 additions & 1 deletion impl/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let mut state = State::with_field_ignore(
input,
trait_name,
quote! { ::core::ops },
trait_name.to_lowercase(),
)?;
state.add_trait_path_type_param(quote! { #index_type });
Expand Down
1 change: 0 additions & 1 deletion impl/src/index_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let mut state = State::with_field_ignore(
input,
trait_name,
quote! { ::core::ops },
"index_mut".into(),
)?;
state.add_trait_path_type_param(quote! { #index_type });
Expand Down
1 change: 0 additions & 1 deletion impl/src/into_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_field_ignore_and_refs(
input,
trait_name,
quote! { ::core::iter },
"into_iterator".into(),
)?;
let SingleFieldData {
Expand Down
1 change: 0 additions & 1 deletion impl/src/is_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_attr_params(
input,
trait_name,
quote! {},
"is_variant".into(),
AttrParams {
enum_: vec!["ignore"],
Expand Down
1 change: 0 additions & 1 deletion impl/src/mul_assign_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let mut state = State::with_attr_params(
input,
trait_name,
quote! { ::core::ops },
method_name,
AttrParams::struct_(vec!["forward"]),
)?;
Expand Down
1 change: 0 additions & 1 deletion impl/src/mul_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let mut state = State::with_attr_params(
input,
trait_name,
quote! { ::core::ops },
trait_name.to_lowercase(),
AttrParams::struct_(vec!["forward"]),
)?;
Expand Down
1 change: 0 additions & 1 deletion impl/src/sum_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::new(
input,
trait_name,
quote! { ::core::iter },
trait_name.to_lowercase(),
)?;
let multi_field_data = state.enabled_fields_data();
Expand Down
1 change: 0 additions & 1 deletion impl/src/try_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_attr_params(
input,
trait_name,
quote! { ::core::convert },
"try_into".into(),
AttrParams {
enum_: vec!["ignore", "owned", "ref", "ref_mut"],
Expand Down
1 change: 0 additions & 1 deletion impl/src/try_unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_attr_params(
input,
trait_name,
quote! {},
"try_unwrap".into(),
AttrParams {
enum_: vec!["ignore", "owned", "ref", "ref_mut"],
Expand Down
1 change: 0 additions & 1 deletion impl/src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
let state = State::with_attr_params(
input,
trait_name,
quote! {},
"unwrap".into(),
AttrParams {
enum_: vec!["ignore", "owned", "ref", "ref_mut"],
Expand Down
22 changes: 2 additions & 20 deletions impl/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ pub struct State<'input> {
pub trait_name: &'static str,
pub trait_ident: Ident,
pub method_ident: Ident,
pub trait_module: TokenStream,
pub trait_path: TokenStream,
pub trait_path_params: Vec<TokenStream>,
pub trait_attr: String,
Expand Down Expand Up @@ -314,13 +313,11 @@ impl<'input> State<'input> {
pub fn new<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
) -> Result<State<'arg_input>> {
State::new_impl(
input,
trait_name,
trait_module,
trait_attr,
AttrParams::default(),
true,
Expand All @@ -330,13 +327,11 @@ impl<'input> State<'input> {
pub fn with_field_ignore<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
) -> Result<State<'arg_input>> {
State::new_impl(
input,
trait_name,
trait_module,
trait_attr,
AttrParams::new(vec!["ignore"]),
true,
Expand All @@ -346,13 +341,11 @@ impl<'input> State<'input> {
pub fn with_field_ignore_and_forward<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
) -> Result<State<'arg_input>> {
State::new_impl(
input,
trait_name,
trait_module,
trait_attr,
AttrParams::new(vec!["ignore", "forward"]),
true,
Expand All @@ -362,13 +355,11 @@ impl<'input> State<'input> {
pub fn with_field_ignore_and_refs<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
) -> Result<State<'arg_input>> {
State::new_impl(
input,
trait_name,
trait_module,
trait_attr,
AttrParams::new(vec!["ignore", "owned", "ref", "ref_mut"]),
true,
Expand All @@ -378,14 +369,12 @@ impl<'input> State<'input> {
pub fn with_attr_params<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
allowed_attr_params: AttrParams,
) -> Result<State<'arg_input>> {
State::new_impl(
input,
trait_name,
trait_module,
trait_attr,
allowed_attr_params,
true,
Expand All @@ -395,15 +384,13 @@ impl<'input> State<'input> {
pub fn with_type_bound<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
allowed_attr_params: AttrParams,
add_type_bound: bool,
) -> Result<State<'arg_input>> {
Self::new_impl(
input,
trait_name,
trait_module,
trait_attr,
allowed_attr_params,
add_type_bound,
Expand All @@ -413,15 +400,14 @@ impl<'input> State<'input> {
fn new_impl<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
allowed_attr_params: AttrParams,
add_type_bound: bool,
) -> Result<State<'arg_input>> {
let trait_name = trait_name.trim_end_matches("ToInner");
let trait_ident = format_ident!("{trait_name}");
let method_ident = format_ident!("{trait_attr}");
let trait_path = quote! { #trait_module::#trait_ident };
let trait_path = quote! { ::derive_more::#trait_ident };
let (derive_type, fields, variants): (_, Vec<_>, Vec<_>) = match input.data {
Data::Struct(ref data_struct) => match data_struct.fields {
Fields::Unnamed(ref fields) => {
Expand Down Expand Up @@ -516,7 +502,6 @@ impl<'input> State<'input> {
State::from_variant(
input,
trait_name,
trait_module.clone(),
trait_attr.clone(),
allowed_attr_params.clone(),
variant,
Expand All @@ -539,7 +524,6 @@ impl<'input> State<'input> {
trait_name,
trait_ident,
method_ident,
trait_module,
trait_path,
trait_path_params: vec![],
trait_attr,
Expand All @@ -558,7 +542,6 @@ impl<'input> State<'input> {
pub fn from_variant<'arg_input>(
input: &'arg_input DeriveInput,
trait_name: &'static str,
trait_module: TokenStream,
trait_attr: String,
allowed_attr_params: AttrParams,
variant: &'arg_input Variant,
Expand All @@ -567,7 +550,7 @@ impl<'input> State<'input> {
let trait_name = trait_name.trim_end_matches("ToInner");
let trait_ident = format_ident!("{trait_name}");
let method_ident = format_ident!("{trait_attr}");
let trait_path = quote! { #trait_module::#trait_ident };
let trait_path = quote! { ::derive_more::#trait_ident };
let (derive_type, fields): (_, Vec<_>) = match variant.fields {
Fields::Unnamed(ref fields) => {
(DeriveType::Unnamed, unnamed_to_vec(fields))
Expand All @@ -593,7 +576,6 @@ impl<'input> State<'input> {
Ok(State {
input,
trait_name,
trait_module,
trait_path,
trait_path_params: vec![],
trait_attr,
Expand Down
2 changes: 2 additions & 0 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! [`core::fmt::DebugTuple`] reimplementation with
//! [`DebugTuple::finish_non_exhaustive()`] method.

use ::core;
use core::prelude::v1::*;
use core::fmt::{Debug, Formatter, Result, Write};

/// Same as [`core::fmt::DebugTuple`], but with
Expand Down
Loading