diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-03-26 02:47:04 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-03-27 00:07:16 +0300 |
| commit | a637dd00c8536d86cfbe59d8a3881e29b3e55eeb (patch) | |
| tree | ca8496d6d87764c81e5db9021e924ef88e5991be /src/libsyntax/parse | |
| parent | ab8b961677ac5c74762dcea955aa0ff4d7fe4915 (diff) | |
| download | rust-a637dd00c8536d86cfbe59d8a3881e29b3e55eeb.tar.gz rust-a637dd00c8536d86cfbe59d8a3881e29b3e55eeb.zip | |
Fix pretty-printing for raw identifiers
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7798a7a77ee..e2dfca5d10a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -142,6 +142,13 @@ pub fn is_path_segment_keyword(id: ast::Ident) -> bool { id.name == keywords::DollarCrate.name() } +// We see this identifier in a normal identifier position, like variable name or a type. +// How was it written originally? Did it use the raw form? Let's try to guess. +pub fn is_raw_guess(ident: ast::Ident) -> bool { + ident.name != keywords::Invalid.name() && + is_reserved_ident(ident) && !is_path_segment_keyword(ident) +} + // Returns true for reserved identifiers used internally for elided lifetimes, // unnamed method parameters, crate root module, error recovery etc. pub fn is_special_ident(id: ast::Ident) -> bool { @@ -236,7 +243,7 @@ impl Token { /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary. pub fn from_ast_ident(ident: ast::Ident) -> Token { - Ident(ident, is_reserved_ident(ident) && !is_path_segment_keyword(ident)) + Ident(ident, is_raw_guess(ident)) } /// Returns `true` if the token starts with '>'. |
