summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src/ident.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/syn/src/ident.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/src/ident.rs')
-rw-r--r--vendor/syn/src/ident.rs115
1 files changed, 60 insertions, 55 deletions
diff --git a/vendor/syn/src/ident.rs b/vendor/syn/src/ident.rs
index 8e3d8bda9..bd6f3f9f2 100644
--- a/vendor/syn/src/ident.rs
+++ b/vendor/syn/src/ident.rs
@@ -1,14 +1,9 @@
#[cfg(feature = "parsing")]
-use crate::buffer::Cursor;
-#[cfg(feature = "parsing")]
use crate::lookahead;
-#[cfg(feature = "parsing")]
-use crate::parse::{Parse, ParseStream, Result};
-#[cfg(feature = "parsing")]
-use crate::token::Token;
pub use proc_macro2::Ident;
+#[cfg(not(doc))] // rustdoc bug: https://github.com/rust-lang/rust/issues/105735
#[cfg(feature = "parsing")]
#[doc(hidden)]
#[allow(non_snake_case)]
@@ -16,54 +11,6 @@ pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
}
-#[cfg(feature = "parsing")]
-fn accept_as_ident(ident: &Ident) -> bool {
- match ident.to_string().as_str() {
- "_" |
- // Based on https://doc.rust-lang.org/grammar.html#keywords
- // and https://github.com/rust-lang/rfcs/blob/master/text/2421-unreservations-2018.md
- // and https://github.com/rust-lang/rfcs/blob/master/text/2420-unreserve-proc.md
- "abstract" | "as" | "become" | "box" | "break" | "const" | "continue" |
- "crate" | "do" | "else" | "enum" | "extern" | "false" | "final" | "fn" |
- "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match" |
- "mod" | "move" | "mut" | "override" | "priv" | "pub" | "ref" |
- "return" | "Self" | "self" | "static" | "struct" | "super" | "trait" |
- "true" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" |
- "where" | "while" | "yield" => false,
- _ => true,
- }
-}
-
-#[cfg(feature = "parsing")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
-impl Parse for Ident {
- fn parse(input: ParseStream) -> Result<Self> {
- input.step(|cursor| {
- if let Some((ident, rest)) = cursor.ident() {
- if accept_as_ident(&ident) {
- return Ok((ident, rest));
- }
- }
- Err(cursor.error("expected identifier"))
- })
- }
-}
-
-#[cfg(feature = "parsing")]
-impl Token for Ident {
- fn peek(cursor: Cursor) -> bool {
- if let Some((ident, _rest)) = cursor.ident() {
- accept_as_ident(&ident)
- } else {
- false
- }
- }
-
- fn display() -> &'static str {
- "identifier"
- }
-}
-
macro_rules! ident_from_token {
($token:ident) => {
impl From<Token![$token]> for Ident {
@@ -86,7 +33,7 @@ impl From<Token![_]> for Ident {
}
}
-pub fn xid_ok(symbol: &str) -> bool {
+pub(crate) fn xid_ok(symbol: &str) -> bool {
let mut chars = symbol.chars();
let first = chars.next().unwrap();
if !(first == '_' || unicode_ident::is_xid_start(first)) {
@@ -99,3 +46,61 @@ pub fn xid_ok(symbol: &str) -> bool {
}
true
}
+
+#[cfg(feature = "parsing")]
+mod parsing {
+ use crate::buffer::Cursor;
+ use crate::parse::{Parse, ParseStream, Result};
+ use crate::token::Token;
+ use proc_macro2::Ident;
+
+ fn accept_as_ident(ident: &Ident) -> bool {
+ match ident.to_string().as_str() {
+ "_" |
+ // Based on https://doc.rust-lang.org/1.65.0/reference/keywords.html
+ "abstract" | "as" | "async" | "await" | "become" | "box" | "break" |
+ "const" | "continue" | "crate" | "do" | "dyn" | "else" | "enum" |
+ "extern" | "false" | "final" | "fn" | "for" | "if" | "impl" | "in" |
+ "let" | "loop" | "macro" | "match" | "mod" | "move" | "mut" |
+ "override" | "priv" | "pub" | "ref" | "return" | "Self" | "self" |
+ "static" | "struct" | "super" | "trait" | "true" | "try" | "type" |
+ "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" |
+ "while" | "yield" => false,
+ _ => true,
+ }
+ }
+
+ #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
+ impl Parse for Ident {
+ fn parse(input: ParseStream) -> Result<Self> {
+ input.step(|cursor| {
+ if let Some((ident, rest)) = cursor.ident() {
+ if accept_as_ident(&ident) {
+ Ok((ident, rest))
+ } else {
+ Err(cursor.error(format_args!(
+ "expected identifier, found keyword `{}`",
+ ident,
+ )))
+ }
+ } else {
+ Err(cursor.error("expected identifier"))
+ }
+ })
+ }
+ }
+
+ impl Token for Ident {
+ fn peek(cursor: Cursor) -> bool {
+ if let Some((ident, _rest)) = cursor.ident() {
+ accept_as_ident(&ident)
+ } else {
+ false
+ }
+ }
+
+ fn display() -> &'static str {
+ "identifier"
+ }
+ }
+}