Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Field<'a> {
pub span: proc_macro2::Span,
}

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Style {
Struct,
Tuple,
Expand Down
11 changes: 10 additions & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ pub fn derive(input: &ast::Input) -> proc_macro2::TokenStream {
};
let method = syn::Ident::new(method, proc_macro2::Span::call_site());

let field_prints: Vec<_> = field_prints.collect();
let exhaustive = field_prints.len() == bis.len();
let finish = if exhaustive || style != ast::Style::Struct {
"finish"
} else {
"finish_non_exhaustive"
};
let finish = syn::Ident::new(finish, proc_macro2::Span::call_site());

if attrs.debug_transparent() {
quote_spanned! {arm_name.span()=>
#(#field_prints)*
Expand All @@ -81,7 +90,7 @@ pub fn derive(input: &ast::Input) -> proc_macro2::TokenStream {
quote_spanned! {arm_name.span()=>
let mut __debug_trait_builder = #formatter.#method(#name);
#(#field_prints)*
__debug_trait_builder.finish()
__debug_trait_builder.#finish()
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions tests/derive-debug-generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ struct PhantomTuple<T> {

#[test]
fn main() {
assert_eq!(Foo { foo: 42, bar: NoDebug }.to_show(), "Foo { foo: 42 }".to_string());
assert_eq!(Foo { foo: 42, bar: NoDebug }.to_show(), "Foo { foo: 42, .. }".to_string());
assert_eq!(Bar(42, NoDebug).to_show(), "Bar(42)".to_string());
assert_eq!(C::V1::<i32, NoDebug>(12).to_show(), "V1(12)".to_string());
assert_eq!(C::V2::<i32, NoDebug>(NoDebug).to_show(), "V2".to_string());
assert_eq!(C::V3::<i32, NoDebug>("foo".to_string()).to_show(), "V3(\"foo\")".to_string());
assert_eq!(D::V1 { a: NoDebug }.to_show(), "V1".to_string());
assert_eq!(D::V1 { a: NoDebug }.to_show(), "V1 { .. }".to_string());
assert_eq!(F(NoDebug).to_show(), "F".to_string());
assert_eq!(G(42, NoDebug).to_show(), "G(42)".to_string());
assert_eq!(J(NoDebug).to_show(), "J".to_string());
Expand Down
4 changes: 2 additions & 2 deletions tests/derive-debug-packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ impl<T: std::fmt::Debug> ToDebug for T {

#[test]
fn main() {
assert_eq!(Foo { foo: 42, bar: 1 }.to_show(), "Foo { foo: 42 }".to_string());
assert_eq!(Foo { foo: 42, bar: 1 }.to_show(), "Foo { foo: 42, .. }".to_string());
assert_eq!(Bar(42, 1).to_show(), "Bar(42)".to_string());
assert_eq!(F(42).to_show(), "F".to_string());
assert_eq!(G(42, 0).to_show(), "G(42)".to_string());
assert_eq!(J(NoDebug).to_show(), "J".to_string());
assert_eq!(K(42, NoDebug).to_show(), "K(42)".to_string());
assert_eq!(L{ foo: NoDebug }.to_show(), "L".to_string());
assert_eq!(L{ foo: NoDebug }.to_show(), "L { .. }".to_string());
}
4 changes: 2 additions & 2 deletions tests/derive-debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl<T: std::fmt::Debug> ToDebug for T {

#[test]
fn main() {
assert_eq!(Foo { foo: 42, bar: 1 }.to_show(), "Foo { foo: 42 }".to_string());
assert_eq!(Foo { foo: 42, bar: 1 }.to_show(), "Foo { foo: 42, .. }".to_string());
assert_eq!(Bar(42, 1).to_show(), "Bar(42)".to_string());
assert_eq!(C::V1(12).to_show(), "V1(12)".to_string());
assert_eq!(C::V2(12).to_show(), "V2".to_string());
assert_eq!(C::V3("foo".to_string()).to_show(), "V3(\"foo\")".to_string());
assert_eq!(D::V1 { a: 42 }.to_show(), "V1".to_string());
assert_eq!(D::V1 { a: 42 }.to_show(), "V1 { .. }".to_string());
assert_eq!(F(42).to_show(), "F".to_string());
assert_eq!(G(42, 0).to_show(), "G(42)".to_string());
assert_eq!(J(NoDebug).to_show(), "J".to_string());
Expand Down