Skip to content

Commit

Permalink
Auto merge of rust-lang#78636 - dtolnay:puncteq, r=petrochenkov
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Nov 24, 2020
2 parents f32a0cc + 4652032 commit cb5b871
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
10 changes: 9 additions & 1 deletion library/proc_macro/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(proc_macro_span)]

use proc_macro::LineColumn;
use proc_macro::{LineColumn, Punct};

#[test]
fn test_line_column_ord() {
Expand All @@ -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 == ':';
}
}

0 comments on commit cb5b871

Please sign in to comment.