Skip to content

Commit

Permalink
Merge pull request #73 from dtolnay/deprecated
Browse files Browse the repository at this point in the history
Allow matches to refer to deprecated variants
  • Loading branch information
dtolnay authored Mar 29, 2020
2 parents 14b54d2 + 33166f7 commit 4ede816
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn impl_struct(input: Struct) -> TokenStream {
let pat = fields_pat(&input.fields);
Some(quote! {
#use_as_display
#[allow(unused_variables)]
#[allow(unused_variables, deprecated)]
let Self #pat = self;
#display
})
Expand All @@ -127,6 +127,7 @@ fn impl_struct(input: Struct) -> TokenStream {
let body = from_initializer(from_field, backtrace_field);
quote! {
impl #impl_generics std::convert::From<#from> for #ty #ty_generics #where_clause {
#[allow(deprecated)]
fn from(source: #from) -> Self {
#ty #body
}
Expand Down Expand Up @@ -177,6 +178,7 @@ fn impl_enum(input: Enum) -> TokenStream {
Some(quote! {
fn source(&self) -> std::option::Option<&(dyn std::error::Error + 'static)> {
use thiserror::private::AsDynError;
#[allow(deprecated)]
match self {
#(#arms)*
}
Expand Down Expand Up @@ -242,6 +244,7 @@ fn impl_enum(input: Enum) -> TokenStream {
});
Some(quote! {
fn backtrace(&self) -> std::option::Option<&std::backtrace::Backtrace> {
#[allow(deprecated)]
match self {
#(#arms)*
}
Expand Down Expand Up @@ -291,7 +294,7 @@ fn impl_enum(input: Enum) -> TokenStream {
impl #impl_generics std::fmt::Display for #ty #ty_generics #where_clause {
fn fmt(&self, __formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
#use_as_display
#[allow(unused_variables)]
#[allow(unused_variables, deprecated)]
match #void_deref self {
#(#arms,)*
}
Expand All @@ -310,6 +313,7 @@ fn impl_enum(input: Enum) -> TokenStream {
let body = from_initializer(from_field, backtrace_field);
Some(quote! {
impl #impl_generics std::convert::From<#from> for #ty #ty_generics #where_clause {
#[allow(deprecated)]
fn from(source: #from) -> Self {
#ty::#variant #body
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![deny(deprecated)]

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[deprecated]
#[error("...")]
Deprecated,
}

0 comments on commit 4ede816

Please sign in to comment.