Skip to content

Commit

Permalink
Corrections and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jul 19, 2024
1 parent 0570291 commit 5424185
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 11 additions & 6 deletions impl/src/fmt/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub fn expand(input: &syn::DeriveInput, _: &str) -> syn::Result<TokenStream> {
.generics
.params
.iter()
.filter_map(|param| match param {
syn::GenericParam::Type(param) => Some(&param.ident),
_ => None,
.filter_map(|p| match p {
syn::GenericParam::Type(t) => Some(&t.ident),
syn::GenericParam::Const(..) | syn::GenericParam::Lifetime(..) => None,
})
.collect();

Expand Down Expand Up @@ -393,6 +393,7 @@ impl<'a> Expansion<'a> {
}
}

/// Checks whether the provided [`syn::Path`] contains any of these [`Expansion::type_params`].
fn path_contains_generic_param(&self, path: &syn::Path) -> bool {
path.segments
.iter()
Expand All @@ -411,7 +412,7 @@ impl<'a> Expansion<'a> {
| syn::GenericArgument::AssocConst(_)
| syn::GenericArgument::Constraint(_) => false,
_ => unimplemented!(
"syntax is not supported by derive_more, please report a bug"
"syntax is not supported by `derive_more`, please report a bug",
),
}),
syn::PathArguments::Parenthesized(
Expand All @@ -428,7 +429,11 @@ impl<'a> Expansion<'a> {
})
}

/// Checks whether the provided [`syn::Type`] contains any of these [`Expansion::type_params`].
fn contains_generic_param(&self, ty: &syn::Type) -> bool {
if self.type_params.is_empty() {
return false;
}
match ty {
syn::Type::Path(syn::TypePath { qself, path }) => {
if let Some(qself) = qself {
Expand Down Expand Up @@ -478,13 +483,13 @@ impl<'a> Expansion<'a> {
syn::TypeParamBound::Lifetime(_) => false,
syn::TypeParamBound::Verbatim(_) => false,
_ => unimplemented!(
"syntax is not supported by derive_more, please report a bug"
"syntax is not supported by `derive_more`, please report a bug",
),
})
}
syn::Type::Verbatim(_) => false,
_ => unimplemented!(
"syntax is not supported by derive_more, please report a bug"
"syntax is not supported by `derive_more`, please report a bug",
),
}
}
Expand Down
12 changes: 7 additions & 5 deletions tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,9 @@ mod type_variables {

mod parens {
#![allow(unused_parens)] // test that type is found even in parentheses

use derive_more::Debug;

#[derive(Debug)]
struct Paren<T> {
t: (T),
Expand Down Expand Up @@ -2034,22 +2036,22 @@ mod type_variables {
"{:?}",
ItemStruct {
next: Some(Box::new(ItemStruct { next: None }))
}
},
),
"ItemStruct { next: Some(ItemStruct { next: None }) }"
"ItemStruct { next: Some(ItemStruct { next: None }) }",
);

assert_eq!(
format!("{:?}", ItemTuple(Some(Box::new(ItemTuple(None)))),),
"ItemTuple(Some(ItemTuple(None)))"
format!("{:?}", ItemTuple(Some(Box::new(ItemTuple(None))))),
"ItemTuple(Some(ItemTuple(None)))",
);

assert_eq!(
format!(
"{:?}",
ItemTupleContainerFmt(Some(Box::new(ItemTupleContainerFmt(None)))),
),
"Item(Some(Item(None)))"
"Item(Some(Item(None)))",
);

let item = ItemEnum::Node {
Expand Down

0 comments on commit 5424185

Please sign in to comment.