Auto merge of #78636 - dtolnay:puncteq, r=petrochenkov

Add PartialEq<char> for proc_macro::Punct

`punct.as_char() == '░'` is pervasive when parsing anything involving punct. I think `punct == '░'` is sufficiently unambiguous that it makes sense to provide the impl.

1899c489d4/library/proc_macro/src/quote.rs (L79)
1899c489d4/library/proc_macro/src/quote.rs (L83)
1899c489d4/src/test/ui/suggestions/auxiliary/issue-61963.rs (L26)
1899c489d4/src/test/ui/proc-macro/auxiliary/three-equals.rs (L23)
This commit is contained in:
bors 2020-11-24 00:30:25 +00:00
commit cb5b87133a
2 changed files with 16 additions and 1 deletions

View File

@ -842,6 +842,13 @@ impl fmt::Debug for Punct {
}
}
#[stable(feature = "proc_macro_punct_eq", since = "1.49.0")]
impl PartialEq<char> 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")]

View File

@ -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 == ':';
}
}