From e5b23db0b18e1dbd229841bab398258a36c4ed87 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 21 Oct 2025 21:48:47 -0700 Subject: [PATCH 1/2] Add test of Display for Ident --- tests/test.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 968c127..faeab0a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -705,6 +705,17 @@ fn raw_identifier() { assert!(tts.next().is_none()); } +#[test] +fn test_display_ident() { + let ident = Ident::new("proc_macro", Span::call_site()); + assert_eq!(format!("{ident}"), "proc_macro"); + assert_eq!(format!("{ident:-^14}"), "--proc_macro--"); + + let ident = Ident::new_raw("proc_macro", Span::call_site()); + assert_eq!(format!("{ident}"), "r#proc_macro"); + assert_eq!(format!("{ident:-^14}"), "r#--proc_macro--"); // FIXME +} + #[test] fn test_debug_ident() { let ident = Ident::new("proc_macro", Span::call_site()); From 48b68dbdf5b0fde1cad09da7ff05c22e771e2e7f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 21 Oct 2025 21:52:01 -0700 Subject: [PATCH 2/2] Ignore formatting options for padding, alignment, width --- src/fallback.rs | 2 +- tests/test.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fallback.rs b/src/fallback.rs index 8e85d2a..61b7b91 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -889,7 +889,7 @@ impl Display for Ident { if self.raw { f.write_str("r#")?; } - Display::fmt(&self.sym, f) + f.write_str(&self.sym) } } diff --git a/tests/test.rs b/tests/test.rs index faeab0a..39a75b5 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -709,11 +709,11 @@ fn raw_identifier() { fn test_display_ident() { let ident = Ident::new("proc_macro", Span::call_site()); assert_eq!(format!("{ident}"), "proc_macro"); - assert_eq!(format!("{ident:-^14}"), "--proc_macro--"); + assert_eq!(format!("{ident:-^14}"), "proc_macro"); let ident = Ident::new_raw("proc_macro", Span::call_site()); assert_eq!(format!("{ident}"), "r#proc_macro"); - assert_eq!(format!("{ident:-^14}"), "r#--proc_macro--"); // FIXME + assert_eq!(format!("{ident:-^14}"), "r#proc_macro"); } #[test]