diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 5a4b69cf6fc1b..4c44e85dae0ee 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -842,6 +842,13 @@ impl fmt::Debug for Punct { } } +#[stable(feature = "proc_macro_punct_eq", since = "1.49.0")] +impl PartialEq for Punct { + fn eq(&self, rhs: &char) -> bool { + self.as_char() == *rhs + } +} + /// An identifier (`ident`). #[derive(Clone)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] diff --git a/library/proc_macro/tests/test.rs b/library/proc_macro/tests/test.rs index 331b330cf29f0..d2e6b0bb8093b 100644 --- a/library/proc_macro/tests/test.rs +++ b/library/proc_macro/tests/test.rs @@ -1,6 +1,6 @@ #![feature(proc_macro_span)] -use proc_macro::LineColumn; +use proc_macro::{LineColumn, Punct}; #[test] fn test_line_column_ord() { @@ -10,3 +10,11 @@ fn test_line_column_ord() { assert!(line0_column0 < line0_column1); assert!(line0_column1 < line1_column0); } + +#[test] +fn test_punct_eq() { + // Good enough if it typechecks, since proc_macro::Punct can't exist in a test. + fn _check(punct: Punct) { + let _ = punct == ':'; + } +}