Require rustc that can support assoc consts for peek_any
diff --git a/build.rs b/build.rs
index 644bf75..2b2a419 100644
--- a/build.rs
+++ b/build.rs
@@ -15,6 +15,10 @@
println!("cargo:rustc-cfg=syn_can_use_thread_id");
}
+ if compiler.minor >= 20 {
+ println!("cargo:rustc-cfg=syn_can_use_associated_constants");
+ }
+
// Macro modularization allows re-exporting the `quote!` macro in 1.30+.
if compiler.minor >= 30 {
println!("cargo:rustc-cfg=syn_can_call_macro_by_path");
diff --git a/src/ext.rs b/src/ext.rs
index 91eec34..17721d5 100644
--- a/src/ext.rs
+++ b/src/ext.rs
@@ -4,9 +4,15 @@
use proc_macro2::Ident;
+use parse::{ParseStream, Result};
+
+#[cfg(syn_can_use_associated_constants)]
use buffer::Cursor;
-use parse::{ParseStream, Peek, Result};
+#[cfg(syn_can_use_associated_constants)]
+use parse::Peek;
+#[cfg(syn_can_use_associated_constants)]
use sealed::lookahead;
+#[cfg(syn_can_use_associated_constants)]
use token::CustomToken;
/// Additional methods for `Ident` not provided by proc-macro2 or libproc_macro.
@@ -53,6 +59,7 @@
///
/// This is different from `input.peek(Ident)` which only returns true in
/// the case of an ident which is not a Rust keyword.
+ #[cfg(syn_can_use_associated_constants)]
#[allow(non_upper_case_globals)]
const peek_any: private::PeekFn = private::PeekFn;
@@ -104,10 +111,12 @@
}
}
+#[cfg(syn_can_use_associated_constants)]
impl Peek for private::PeekFn {
type Token = private::IdentAny;
}
+#[cfg(syn_can_use_associated_constants)]
impl CustomToken for private::IdentAny {
fn peek(cursor: Cursor) -> bool {
cursor.ident().is_some()
@@ -118,6 +127,7 @@
}
}
+#[cfg(syn_can_use_associated_constants)]
impl lookahead::Sealed for private::PeekFn {}
mod private {
@@ -127,7 +137,9 @@
impl Sealed for Ident {}
+ #[cfg(syn_can_use_associated_constants)]
#[derive(Copy, Clone)]
pub struct PeekFn;
+ #[cfg(syn_can_use_associated_constants)]
pub struct IdentAny;
}