diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-05-05 22:45:59 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-05-15 23:24:16 +0300 |
| commit | 780616ed74d22d96cb7464c2d558244bd665e39a (patch) | |
| tree | 693e8f57a1f278a9a21b344e4cf2bfe73b2d13a0 /src/libsyntax/parse | |
| parent | f116ab6e6e2c02d5b623c64793e25742244bec55 (diff) | |
| download | rust-780616ed74d22d96cb7464c2d558244bd665e39a.tar.gz rust-780616ed74d22d96cb7464c2d558244bd665e39a.zip | |
proc_macro: Validate inputs to `Punct::new` and `Ident::new`
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 22a0261d8c6..4da7b8e93d9 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1770,6 +1770,15 @@ fn ident_continue(c: Option<char>) -> bool { (c > '\x7f' && c.is_xid_continue()) } +// The string is a valid identifier or a lifetime identifier. +pub fn is_valid_ident(s: &str) -> bool { + let mut chars = s.chars(); + match chars.next() { + Some('\'') => ident_start(chars.next()) && chars.all(|ch| ident_continue(Some(ch))), + ch => ident_start(ch) && chars.all(|ch| ident_continue(Some(ch))) + } +} + #[cfg(test)] mod tests { use super::*; |
