1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
From 628af8d1cec18eac117fc976d5b2483a2f30f7c4 Mon Sep 17 00:00:00 2001
From: Chris Coulter <c.coulter@gmail.com>
Date: Thu, 17 Nov 2022 09:12:02 +1100
Subject: [PATCH] Replace failure with anyhow.
Origin: https://github.com/ecstatic-morse/enum-utils/pull/6
- failure is deprecated and has security flaws.
- anyhow is a drop in replacement.
---
Cargo.toml | 6 +-----
src/attr.rs | 18 +++++++++---------
src/conv.rs | 2 +-
src/from_str.rs | 2 +-
src/iter.rs | 2 +-
5 files changed, 13 insertions(+), 17 deletions(-)
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,10 +26,8 @@
[dependencies.enum-utils-from-str]
version = "0.1.2"
-[dependencies.failure]
-version = "0.1"
-features = ["std"]
-default-features = false
+[dependencies.anyhow]
+version = "1.0"
[dependencies.proc-macro2]
version = "1.0"
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -2,7 +2,7 @@
use std::convert::{TryFrom, TryInto};
use std::fmt;
-use failure::{bail, format_err, Fallible};
+use anyhow::{bail, format_err, Result};
#[derive(Debug, Clone, Copy)]
pub enum Primitive {
@@ -68,7 +68,7 @@
}
pub fn parse_primitive_repr<'a>(attrs: impl 'a + Iterator<Item = &'a syn::Attribute>)
- -> Fallible<Option<(Primitive, syn::Path)>>
+ -> Result<Option<(Primitive, syn::Path)>>
{
let mut repr = None;
for attr in attrs {
@@ -117,13 +117,13 @@
}
}
-pub type ErrorList = LinkedList<failure::Error>;
+pub type ErrorList = LinkedList<anyhow::Error>;
macro_rules! bail_list {
($msg:literal $( , $args:expr )* $(,)?) => {
{
let mut list = ErrorList::new();
- list.push_back(failure::format_err!($msg, $($args),*));
+ list.push_back(anyhow::format_err!($msg, $($args),*));
return Err(list);
}
}
@@ -139,7 +139,7 @@
}
impl Attr {
- pub fn parse_attrs(attr: &syn::Attribute) -> impl Iterator<Item = Fallible<Self>> {
+ pub fn parse_attrs(attr: &syn::Attribute) -> impl Iterator<Item = Result<Self>> {
use syn::NestedMeta;
Self::get_args(attr)
@@ -167,7 +167,7 @@
/// Parse an attr from the `syn::Meta` inside parens after "enumeration".
impl TryFrom<&'_ syn::Meta> for Attr {
- type Error = failure::Error;
+ type Error = anyhow::Error;
fn try_from(meta: &syn::Meta) -> Result<Self, Self::Error> {
use syn::{Lit, Meta, MetaNameValue};
@@ -217,7 +217,7 @@
impl VariantAttrs {
pub fn from_attrs<T>(attrs: T) -> Result<Self, ErrorList>
- where T: IntoIterator<Item = Fallible<Attr>>,
+ where T: IntoIterator<Item = Result<Attr>>,
{
let mut ret = VariantAttrs::default();
let mut errors = ErrorList::default();
@@ -258,7 +258,7 @@
impl EnumAttrs {
pub fn from_attrs<T>(attrs: T) -> Result<Self, ErrorList>
- where T: IntoIterator<Item = Fallible<Attr>>,
+ where T: IntoIterator<Item = Result<Attr>>,
{
let mut ret = EnumAttrs::default();
let mut errors = ErrorList::default();
@@ -295,7 +295,7 @@
/// This will be `None` if no `#[repr]` was specified, or an error if parsing failed or
/// multiple `#[repr]`s were specified.
- pub primitive_repr: Fallible<Option<(Primitive, syn::Path)>>,
+ pub primitive_repr: Result<Option<(Primitive, syn::Path)>>,
pub variants: Vec<(&'a syn::Variant, VariantAttrs)>,
--- a/src/conv.rs
+++ b/src/conv.rs
@@ -1,4 +1,4 @@
-use failure::format_err;
+use anyhow::format_err;
use proc_macro2::{TokenStream, Span};
use quote::quote;
--- a/src/from_str.rs
+++ b/src/from_str.rs
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;
-use failure::format_err;
+use anyhow::format_err;
use proc_macro2::TokenStream;
use quote::quote;
--- a/src/iter.rs
+++ b/src/iter.rs
@@ -1,6 +1,6 @@
use std::ops::{Range, RangeInclusive};
-use failure::format_err;
+use anyhow::format_err;
use proc_macro2::{Literal, TokenStream};
use quote::quote;
|