Skip to content

Commit 98ea261

Browse files
committed
Check valid punctuation character in Punct::new
Valid punctuation characters generated by: use proc_macro::{Punct, Spacing, TokenStream}; use std::panic; #[proc_macro] pub fn punct_chars(_input: TokenStream) -> TokenStream { for ch in '\0'..=char::MAX { if let Ok(_) = panic::catch_unwind(|| { let _ = Punct::new(ch, Spacing::Alone); }) { eprintln!("{:?}", ch); } } TokenStream::new() }
1 parent d60aaad commit 98ea261

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,16 @@ impl Punct {
835835
/// The returned `Punct` will have the default span of `Span::call_site()`
836836
/// which can be further configured with the `set_span` method below.
837837
pub fn new(ch: char, spacing: Spacing) -> Self {
838-
Punct {
839-
ch,
840-
spacing,
841-
span: Span::call_site(),
838+
if let '!' | '#' | '$' | '%' | '&' | '\'' | '*' | '+' | ',' | '-' | '.' | '/' | ':' | ';'
839+
| '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' = ch
840+
{
841+
Punct {
842+
ch,
843+
spacing,
844+
span: Span::call_site(),
845+
}
846+
} else {
847+
panic!("unsupported proc macro punctuation character {:?}", ch);
842848
}
843849
}
844850

0 commit comments

Comments
 (0)