From 3f12d652a8871955a7e27e0369933288bc387dd5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Dec 2023 19:48:27 -0800 Subject: [PATCH 1/2] Include punctuation tokens in snapshot tests containing Punctuated --- tests/debug/mod.rs | 12 ++++++++---- tests/test_derive_input.rs | 14 ++++++++++++++ tests/test_expr.rs | 5 +++++ tests/test_generics.rs | 4 ++++ tests/test_item.rs | 2 ++ tests/test_meta.rs | 1 + tests/test_parse_quote.rs | 2 ++ tests/test_path.rs | 2 ++ tests/test_ty.rs | 6 ++++++ 9 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/debug/mod.rs b/tests/debug/mod.rs index fd814a8004..b6de67e1f7 100644 --- a/tests/debug/mod.rs +++ b/tests/debug/mod.rs @@ -115,12 +115,16 @@ where impl Debug for Lite> where Lite: Debug, + Lite

: Debug, { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter - .debug_list() - .entries(self.value.iter().map(Lite)) - .finish() + let mut list = formatter.debug_list(); + for pair in self.pairs() { + let (node, punct) = pair.into_tuple(); + list.entry(Lite(node)); + list.entries(punct.map(Lite)); + } + list.finish() } } diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs index 3ec6aecbc6..c3d31eb0e9 100644 --- a/tests/test_derive_input.rs +++ b/tests/test_derive_input.rs @@ -78,6 +78,7 @@ fn test_struct() { }, }, }, + Token![,], Field { vis: Visibility::Public, ident: Some("attrs"), @@ -157,6 +158,7 @@ fn test_union() { colon_token: Some, ty: Type::Tuple, }, + Token![,], Field { vis: Visibility::Inherited, ident: Some("value"), @@ -232,6 +234,7 @@ fn test_enum() { GenericParam::Type(TypeParam { ident: "T", }), + Token![,], GenericParam::Type(TypeParam { ident: "E", }), @@ -259,6 +262,7 @@ fn test_enum() { ], }, }, + Token![,], Variant { ident: "Err", fields: Fields::Unnamed { @@ -278,6 +282,7 @@ fn test_enum() { ], }, }, + Token![,], Variant { ident: "Surprise", fields: Fields::Unit, @@ -285,6 +290,7 @@ fn test_enum() { lit: 0isize, }), }, + Token![,], Variant { ident: "ProcMacroHack", fields: Fields::Unit, @@ -294,6 +300,7 @@ fn test_enum() { Expr::Lit { lit: 0, }, + Token![,], Expr::Lit { lit: "data", }, @@ -363,6 +370,7 @@ fn test_attr_with_mod_style_path_with_self() { PathSegment { ident: "foo", }, + Token![::], PathSegment { ident: "self", }, @@ -386,6 +394,7 @@ fn test_attr_with_mod_style_path_with_self() { PathSegment { ident: "foo", }, + Token![::], PathSegment { ident: "self", }, @@ -426,6 +435,7 @@ fn test_pub_restricted() { PathSegment { ident: "m", }, + Token![::], PathSegment { ident: "n", }, @@ -589,6 +599,7 @@ fn test_fields_on_named_struct() { }, }, }, + Token![,], Field { vis: Visibility::Public, ident: Some("bar"), @@ -603,6 +614,7 @@ fn test_fields_on_named_struct() { }, }, }, + Token![,], ], }, }, @@ -674,6 +686,7 @@ fn test_fields_on_tuple_struct() { }, }, }, + Token![,], Field { vis: Visibility::Public, ty: Type::Path { @@ -751,6 +764,7 @@ fn test_ambiguous_crate() { PathSegment { ident: "crate", }, + Token![::], PathSegment { ident: "X", }, diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 449b83bf53..fef2e9b95d 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -390,6 +390,7 @@ fn test_extended_interpolated_path() { PathSegment { ident: "a", }, + Token![::], PathSegment { ident: "b", }, @@ -411,6 +412,7 @@ fn test_extended_interpolated_path() { PathSegment { ident: "a", }, + Token![::], PathSegment { ident: "b", }, @@ -427,9 +429,11 @@ fn test_extended_interpolated_path() { PathSegment { ident: "a", }, + Token![::], PathSegment { ident: "b", }, + Token![::], PathSegment { ident: "c", }, @@ -451,6 +455,7 @@ fn test_extended_interpolated_path() { PathSegment { ident: "a", }, + Token![::], PathSegment { ident: "b", }, diff --git a/tests/test_generics.rs b/tests/test_generics.rs index b9bb75ef15..3faf0dba59 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -28,6 +28,7 @@ fn test_split_for_impl() { ident: "a", }, }), + Token![,], GenericParam::Lifetime(LifetimeParam { lifetime: Lifetime { ident: "b", @@ -39,6 +40,7 @@ fn test_split_for_impl() { }, ], }), + Token![,], GenericParam::Type(TypeParam { attrs: [ Attribute { @@ -227,6 +229,7 @@ fn test_fn_precedence_in_where_clause() { ], }, }), + Token![+], TypeParamBound::Trait(TraitBound { path: Path { segments: [ @@ -238,6 +241,7 @@ fn test_fn_precedence_in_where_clause() { }), ], }), + Token![,], ], }), }, diff --git a/tests/test_item.rs b/tests/test_item.rs index 11d4ba484b..db9e3ab515 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -230,6 +230,7 @@ fn test_supertraits() { ], }, }), + Token![+], ], } "###); @@ -318,6 +319,7 @@ fn test_impl_trait_trailing_plus() { ], }, }), + Token![+], ], }, ), diff --git a/tests/test_meta.rs b/tests/test_meta.rs index 91a9807000..d991c38e45 100644 --- a/tests/test_meta.rs +++ b/tests/test_meta.rs @@ -144,6 +144,7 @@ fn test_parse_path() { PathSegment { ident: "serde", }, + Token![::], PathSegment { ident: "Serialize", }, diff --git a/tests/test_parse_quote.rs b/tests/test_parse_quote.rs index b43e6f2b22..9eaab41e25 100644 --- a/tests/test_parse_quote.rs +++ b/tests/test_parse_quote.rs @@ -65,6 +65,7 @@ fn test_field() { PathSegment { ident: "primitive", }, + Token![::], PathSegment { ident: "bool", }, @@ -97,6 +98,7 @@ fn test_pat() { }), ], }, + Token![|], Pat::Ident { ident: "None", }, diff --git a/tests/test_path.rs b/tests/test_path.rs index 6aded74e6a..2873441abd 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -24,6 +24,7 @@ fn parse_interpolated_leading_component() { PathSegment { ident: "first", }, + Token![::], PathSegment { ident: "rest", }, @@ -39,6 +40,7 @@ fn parse_interpolated_leading_component() { PathSegment { ident: "first", }, + Token![::], PathSegment { ident: "rest", }, diff --git a/tests/test_ty.rs b/tests/test_ty.rs index a400a76124..16f2665d03 100644 --- a/tests/test_ty.rs +++ b/tests/test_ty.rs @@ -170,6 +170,7 @@ fn test_group_colons() { ], }, }, + Token![::], PathSegment { ident: "Item", }, @@ -245,6 +246,7 @@ fn test_trait_object() { ], }, }), + Token![+], TypeParamBound::Lifetime { ident: "static", }, @@ -260,6 +262,7 @@ fn test_trait_object() { TypeParamBound::Lifetime { ident: "a", }, + Token![+], TypeParamBound::Trait(TraitBound { path: Path { segments: [ @@ -294,6 +297,7 @@ fn test_trailing_plus() { ], }, }), + Token![+], ], } "###); @@ -313,6 +317,7 @@ fn test_trailing_plus() { ], }, }), + Token![+], ], } "###); @@ -331,6 +336,7 @@ fn test_trailing_plus() { ], }, }), + Token![+], ], } "###); From 131b40ba2904ec8755bb34466f369072dc34d588 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Dec 2023 19:51:31 -0800 Subject: [PATCH 2/2] Debug impl for punctuated::Pairs superseded by Punctuated --- tests/debug/mod.rs | 18 +----------------- tests/test_parse_quote.rs | 4 ++-- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/tests/debug/mod.rs b/tests/debug/mod.rs index b6de67e1f7..c9925a6d5c 100644 --- a/tests/debug/mod.rs +++ b/tests/debug/mod.rs @@ -11,7 +11,7 @@ use proc_macro2::{Ident, Literal, TokenStream}; use ref_cast::RefCast; use std::fmt::{self, Debug}; use std::ops::Deref; -use syn::punctuated::{self, Punctuated}; +use syn::punctuated::Punctuated; #[derive(RefCast)] #[repr(transparent)] @@ -128,22 +128,6 @@ where } } -impl<'a, T, P> Debug for Lite> -where - Lite: Debug, - Lite

: Debug, -{ - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - let mut list = formatter.debug_list(); - for pair in self.value.clone() { - let (node, punct) = pair.into_tuple(); - list.entry(Lite(node)); - list.entries(punct.map(Lite)); - } - list.finish() - } -} - struct Present; impl Debug for Present { diff --git a/tests/test_parse_quote.rs b/tests/test_parse_quote.rs index 9eaab41e25..73aae709af 100644 --- a/tests/test_parse_quote.rs +++ b/tests/test_parse_quote.rs @@ -113,7 +113,7 @@ fn test_pat() { #[test] fn test_punctuated() { let punctuated: Punctuated = parse_quote!(true | true); - snapshot!(punctuated.pairs(), @r###" + snapshot!(punctuated, @r###" [ Lit::Bool { value: true, @@ -126,7 +126,7 @@ fn test_punctuated() { "###); let punctuated: Punctuated = parse_quote!(true | true |); - snapshot!(punctuated.pairs(), @r###" + snapshot!(punctuated, @r###" [ Lit::Bool { value: true,