Skip to content

Commit

Permalink
Merge pull request #404 from dtolnay/fromfn
Browse files Browse the repository at this point in the history
Unspan From impl contents
  • Loading branch information
dtolnay authored Dec 21, 2024
2 parents c008375 + e5169bb commit 0a0516d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,15 @@ fn impl_struct(input: Struct) -> TokenStream {
let from = unoptional_type(from_field.ty);
let source_var = Ident::new("source", span);
let body = from_initializer(from_field, backtrace_field, &source_var);
let from_function = quote! {
fn from(#source_var: #from) -> Self {
#ty #body
}
};
let from_impl = quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
fn from(#source_var: #from) -> Self {
#ty #body
}
#from_function
}
};
Some(quote! {
Expand Down Expand Up @@ -436,12 +439,15 @@ fn impl_enum(input: Enum) -> TokenStream {
let from = unoptional_type(from_field.ty);
let source_var = Ident::new("source", span);
let body = from_initializer(from_field, backtrace_field, &source_var);
let from_function = quote! {
fn from(#source_var: #from) -> Self {
#ty::#variant #body
}
};
let from_impl = quote_spanned! {span=>
#[automatically_derived]
impl #impl_generics ::core::convert::From<#from> for #ty #ty_generics #where_clause {
fn from(#source_var: #from) -> Self {
#ty::#variant #body
}
#from_function
}
};
Some(quote! {
Expand Down

0 comments on commit 0a0516d

Please sign in to comment.