Easier to accept &str in Ident::new
diff --git a/src/attr.rs b/src/attr.rs
index 90d9af9..cdbc142 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -121,12 +121,12 @@
}
TokenNode::Term(sym) => {
- let ident = Ident::new(sym, tts[0].span);
+ let ident = Ident::new(sym.as_str(), tts[0].span);
if tts.len() >= 3 {
if let TokenNode::Op('=', Spacing::Alone) = tts[1].kind {
if let TokenNode::Literal(ref lit) = tts[2].kind {
let pair = MetaNameValue {
- ident: Ident::new(sym, tts[0].span),
+ ident: Ident::new(sym.as_str(), tts[0].span),
eq_token: Token,
lit: Lit {
value: LitKind::Other(lit.clone()),
diff --git a/src/ident.rs b/src/ident.rs
index 0e2d521..908326e 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -96,9 +96,7 @@
/// by the parser to create `Ident`s from existing Rust source code.
///
/// Creating new `Ident`s programmatically is easier with `Ident::from`.
- pub fn new(sym: Term, span: Span) -> Self {
- let s = sym.as_str();
-
+ pub fn new(s: &str, span: Span) -> Self {
if s.is_empty() {
panic!("ident is not allowed to be empty; use Option<Ident>");
}
@@ -134,7 +132,7 @@
}
Ident {
- sym: sym,
+ sym: Term::intern(s),
span: span,
}
}
@@ -142,43 +140,43 @@
impl<'a> From<&'a str> for Ident {
fn from(s: &str) -> Self {
- Ident::new(Term::intern(s), Span::default())
+ Ident::new(s, Span::default())
}
}
impl From<Token![self]> for Ident {
fn from(tok: Token![self]) -> Self {
- Ident::new(Term::intern("self"), tok.0)
+ Ident::new("self", tok.0)
}
}
impl From<Token![Self]> for Ident {
fn from(tok: Token![Self]) -> Self {
- Ident::new(Term::intern("Self"), tok.0)
+ Ident::new("Self", tok.0)
}
}
impl From<Token![super]> for Ident {
fn from(tok: Token![super]) -> Self {
- Ident::new(Term::intern("super"), tok.0)
+ Ident::new("super", tok.0)
}
}
impl From<Token![crate]> for Ident {
fn from(tok: Token![crate]) -> Self {
- Ident::new(Term::intern("crate"), tok.0)
+ Ident::new("crate", tok.0)
}
}
impl<'a> From<Cow<'a, str>> for Ident {
fn from(s: Cow<'a, str>) -> Self {
- Ident::new(Term::intern(&s), Span::default())
+ Ident::new(&s, Span::default())
}
}
impl From<String> for Ident {
fn from(s: String) -> Self {
- Ident::new(Term::intern(&s), Span::default())
+ Ident::new(&s, Span::default())
}
}