Skip to content

Commit 7c36206

Browse files
authored
fix: remove anyhow from default features again (#19)
## Description * Remove `anyhow` from the default features. This was added inadvertently in #14 * Clippy fixes for `n0-error-macros` * Do not run doc examples in n0-error-macros as doctests, they don't compile without n0-error ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent 554fcfa commit 7c36206

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inherits = 'dev'
2222
opt-level = 1
2323

2424
[features]
25-
default = ["anyhow"]
25+
default = []
2626
anyhow = ["dep:anyhow"]
2727

2828
[workspace]

n0-error-macros/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use syn::{
1111
/// This macro can be applied to enums and structs and the syntax `#[stack_error(args)]`,
1212
/// where `args` is a comma-seperated list of arguments.
1313
/// * **`add_meta`** adds a `n0_error::Meta` field to the struct or each each enum variant. The `Meta`
14-
/// struct contains call-site location metadata for the error.
14+
/// struct contains call-site location metadata for the error.
1515
/// - If the item has named fields, the field will added with name `meta`
1616
/// - If the item is a tuple, the field will be added as the last field and marked with `#[error(meta)]`
1717
/// - It the item is a unit, it will be altered to named fields, and the field
@@ -26,7 +26,7 @@ use syn::{
2626
///
2727
/// ## Example
2828
///
29-
/// ```rust
29+
/// ```ignore
3030
/// #[stack_error(derive, add_meta, from_sources)]
3131
/// enum MyError {
3232
/// #[error("io failed")]
@@ -36,7 +36,7 @@ use syn::{
3636
/// }
3737
/// ```
3838
/// expands to
39-
/// ```rust
39+
/// ```ignore
4040
/// #[derive(n0_error::StackError)]
4141
/// #[error(from_sources)]
4242
/// enum MyError {
@@ -318,15 +318,15 @@ impl<'a> VariantIdent<'a> {
318318
}
319319
fn item_ident(&self) -> &Ident {
320320
match self {
321-
VariantIdent::Struct(ident) => &ident,
322-
VariantIdent::Variant(ident, _) => &ident,
321+
VariantIdent::Struct(ident) => ident,
322+
VariantIdent::Variant(ident, _) => ident,
323323
}
324324
}
325325

326326
fn inner(&self) -> &Ident {
327327
match self {
328-
VariantIdent::Struct(ident) => &ident,
329-
VariantIdent::Variant(_, ident) => &ident,
328+
VariantIdent::Struct(ident) => ident,
329+
VariantIdent::Variant(_, ident) => ident,
330330
}
331331
}
332332
}
@@ -357,7 +357,7 @@ impl<'a> VariantInfo<'a> {
357357
attrs: &[Attribute],
358358
args: &EnumAttrArgs,
359359
) -> Result<VariantInfo<'a>, syn::Error> {
360-
let display = DisplayArgs::parse(&attrs)?;
360+
let display = DisplayArgs::parse(attrs)?;
361361
let (kind, fields): (Kind, Vec<FieldInfo>) = match fields {
362362
Fields::Named(ref fields) => (
363363
Kind::Named,
@@ -419,10 +419,10 @@ impl<'a> VariantInfo<'a> {
419419
let from_field = fields
420420
.iter()
421421
.find(|f| f.args.from)
422-
.or_else(|| args.from_sources.then(|| source_field).flatten());
422+
.or_else(|| args.from_sources.then_some(source_field).flatten());
423423
let meta_field = fields.iter().find(|f| f.is_meta()).cloned();
424424
Ok(VariantInfo {
425-
ident: ident.clone(),
425+
ident,
426426
kind,
427427
display,
428428
from: from_field.cloned(),
@@ -464,7 +464,7 @@ impl<'a> VariantInfo<'a> {
464464
Kind::Unit => quote! { #slf },
465465
Kind::Named => quote! { #slf { .. } },
466466
Kind::Tuple => {
467-
let pats = std::iter::repeat(quote! { _ }).take(self.fields.len());
467+
let pats = std::iter::repeat_n(quote! { _ }, self.fields.len());
468468
quote! { #slf ( #(#pats),* ) }
469469
}
470470
}
@@ -487,7 +487,7 @@ impl<'a> VariantInfo<'a> {
487487
}
488488
}
489489

490-
fn from_impl(&self) -> Option<(&syn::Type, proc_macro2::TokenStream)> {
490+
fn generate_from_impl(&self) -> Option<(&syn::Type, proc_macro2::TokenStream)> {
491491
self.from.as_ref().map(|from_field| {
492492
let ty = &from_field.field.ty;
493493
let fields = self.fields.iter().map(|field| {
@@ -657,7 +657,7 @@ fn generate_enum_impls(
657657

658658
// From impls for variant fields marked with #[from]
659659
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
660-
let from_impls = variants.iter().filter_map(|vi| vi.from_impl()).map(|(ty, construct)| {
660+
let from_impls = variants.iter().filter_map(|vi| vi.generate_from_impl()).map(|(ty, construct)| {
661661
quote! {
662662
impl #impl_generics ::core::convert::From<#ty> for #enum_ident #ty_generics #where_clause {
663663
#[track_caller]
@@ -821,7 +821,7 @@ fn generate_struct_impl(
821821
}
822822
}
823823
Kind::Tuple => {
824-
let binds = (0..info.fields.len()).map(|i| syn::Index::from(i));
824+
let binds = (0..info.fields.len()).map(syn::Index::from);
825825
quote! {
826826
let mut dbg = f.debug_tuple(#item_name);
827827
#( dbg.field(&self.#binds); )*;
@@ -833,7 +833,7 @@ fn generate_struct_impl(
833833

834834
// From impls for fields marked with #[error(from)] (or inferred via from_sources)
835835
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
836-
let from_impl = info.from_impl().map(|(ty, construct)| {
836+
let from_impl = info.generate_from_impl().map(|(ty, construct)| {
837837
quote! {
838838
impl #impl_generics ::core::convert::From<#ty> for #item_ident #ty_generics #where_clause {
839839
#[track_caller]

0 commit comments

Comments
 (0)