Skip to content

Commit

Permalink
Merge pull request #1144 from dtolnay/nothingtraits
Browse files Browse the repository at this point in the history
Implement extra-traits for syn::parse::Nothing
  • Loading branch information
dtolnay committed Mar 15, 2022
2 parents 3f0cfc1 + f21ce8a commit 531c56f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/parse.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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<H: Hasher>(&self, _state: &mut H) {}
}

0 comments on commit 531c56f

Please sign in to comment.