From f21ce8a20f77244493112f48184fd30ad0c58d31 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 14 Mar 2022 19:45:16 -0700 Subject: [PATCH] Implement extra-traits for syn::parse::Nothing --- src/parse.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/parse.rs b/src/parse.rs index d85968bd24..5fa0636727 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -199,6 +199,8 @@ use crate::token::Token; use proc_macro2::{self, Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree}; use std::cell::Cell; use std::fmt::{self, Debug, Display}; +#[cfg(feature = "extra-traits")] +use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use std::mem; use std::ops::Deref; @@ -1285,3 +1287,29 @@ impl Parse for Nothing { Ok(Nothing) } } + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl Debug for Nothing { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("Nothing") + } +} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl Eq for Nothing {} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl PartialEq for Nothing { + fn eq(&self, _other: &Self) -> bool { + true + } +} + +#[cfg(feature = "extra-traits")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] +impl Hash for Nothing { + fn hash(&self, _state: &mut H) {} +}