Skip to content

Commit f0b6802

Browse files
authored
Merge pull request #471 from dtolnay/punctnew
Check valid punctuation character in Punct::new
2 parents d60aaad + 98ea261 commit f0b6802

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)