Skip to content

Commit eb3943a

Browse files
committed
Track upstream proc_macro changes
* Rename `Term` to `Ident` * Rename `Punct` to `Op` * Remove `Term::as_str` * Rename `Op::op` to `Punct::as_char` * `Term::new` no longer accepts lifetimes or raw idents * Lifetimes are lexed as a `Joint` `'` character followed by an `Ident` * `Ident::new_raw` is a new `procmacro2_semver_exempt` API for creating raw identifiers.
1 parent 47c9301 commit eb3943a

File tree

6 files changed

+217
-171
lines changed

6 files changed

+217
-171
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "proc-macro2"
3-
version = "0.3.8" # remember to update html_root_url
3+
version = "0.4.0" # remember to update html_root_url
44
authors = ["Alex Crichton <[email protected]>"]
55
license = "MIT/Apache-2.0"
66
readme = "README.md"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ itself. Usage is done via:
2727

2828
```toml
2929
[dependencies]
30-
proc-macro2 = "0.3"
30+
proc-macro2 = "0.4"
3131
```
3232

3333
followed by
@@ -57,7 +57,7 @@ You can enable this feature via:
5757

5858
```toml
5959
[dependencies]
60-
proc-macro2 = { version = "0.3", features = ["nightly"] }
60+
proc-macro2 = { version = "0.4", features = ["nightly"] }
6161
```
6262

6363

src/lib.rs

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@
4343
//! [ts]: https://doc.rust-lang.org/proc_macro/struct.TokenStream.html
4444
4545
// Proc-macro2 types in rustdoc of other crates get linked to here.
46-
#![doc(html_root_url = "https://docs.rs/proc-macro2/0.3.8")]
46+
#![doc(html_root_url = "https://docs.rs/proc-macro2/0.4.0")]
4747
#![cfg_attr(feature = "nightly", feature(proc_macro))]
4848

4949
#[cfg(feature = "proc-macro")]
5050
extern crate proc_macro;
5151
extern crate unicode_xid;
5252

53+
use std::cmp::Ordering;
5354
use std::fmt;
55+
use std::hash::{Hash, Hasher};
5456
use std::iter::FromIterator;
5557
use std::marker;
5658
use std::rc::Rc;
@@ -284,26 +286,26 @@ impl fmt::Debug for Span {
284286
#[derive(Clone)]
285287
pub enum TokenTree {
286288
Group(Group),
287-
Term(Term),
288-
Op(Op),
289+
Ident(Ident),
290+
Punct(Punct),
289291
Literal(Literal),
290292
}
291293

292294
impl TokenTree {
293295
pub fn span(&self) -> Span {
294296
match *self {
295297
TokenTree::Group(ref t) => t.span(),
296-
TokenTree::Term(ref t) => t.span(),
297-
TokenTree::Op(ref t) => t.span(),
298+
TokenTree::Ident(ref t) => t.span(),
299+
TokenTree::Punct(ref t) => t.span(),
298300
TokenTree::Literal(ref t) => t.span(),
299301
}
300302
}
301303

302304
pub fn set_span(&mut self, span: Span) {
303305
match *self {
304306
TokenTree::Group(ref mut t) => t.set_span(span),
305-
TokenTree::Term(ref mut t) => t.set_span(span),
306-
TokenTree::Op(ref mut t) => t.set_span(span),
307+
TokenTree::Ident(ref mut t) => t.set_span(span),
308+
TokenTree::Punct(ref mut t) => t.set_span(span),
307309
TokenTree::Literal(ref mut t) => t.set_span(span),
308310
}
309311
}
@@ -315,15 +317,15 @@ impl From<Group> for TokenTree {
315317
}
316318
}
317319

318-
impl From<Term> for TokenTree {
319-
fn from(g: Term) -> TokenTree {
320-
TokenTree::Term(g)
320+
impl From<Ident> for TokenTree {
321+
fn from(g: Ident) -> TokenTree {
322+
TokenTree::Ident(g)
321323
}
322324
}
323325

324-
impl From<Op> for TokenTree {
325-
fn from(g: Op) -> TokenTree {
326-
TokenTree::Op(g)
326+
impl From<Punct> for TokenTree {
327+
fn from(g: Punct) -> TokenTree {
328+
TokenTree::Punct(g)
327329
}
328330
}
329331

@@ -337,8 +339,8 @@ impl fmt::Display for TokenTree {
337339
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
338340
match *self {
339341
TokenTree::Group(ref t) => t.fmt(f),
340-
TokenTree::Term(ref t) => t.fmt(f),
341-
TokenTree::Op(ref t) => t.fmt(f),
342+
TokenTree::Ident(ref t) => t.fmt(f),
343+
TokenTree::Punct(ref t) => t.fmt(f),
342344
TokenTree::Literal(ref t) => t.fmt(f),
343345
}
344346
}
@@ -350,8 +352,8 @@ impl fmt::Debug for TokenTree {
350352
// so don't bother with an extra layer of indirection
351353
match *self {
352354
TokenTree::Group(ref t) => t.fmt(f),
353-
TokenTree::Term(ref t) => t.fmt(f),
354-
TokenTree::Op(ref t) => t.fmt(f),
355+
TokenTree::Ident(ref t) => t.fmt(f),
356+
TokenTree::Punct(ref t) => t.fmt(f),
355357
TokenTree::Literal(ref t) => t.fmt(f),
356358
}
357359
}
@@ -416,7 +418,7 @@ impl fmt::Debug for Group {
416418
}
417419

418420
#[derive(Copy, Clone)]
419-
pub struct Op {
421+
pub struct Punct {
420422
op: char,
421423
spacing: Spacing,
422424
span: Span,
@@ -428,16 +430,16 @@ pub enum Spacing {
428430
Joint,
429431
}
430432

431-
impl Op {
432-
pub fn new(op: char, spacing: Spacing) -> Op {
433-
Op {
433+
impl Punct {
434+
pub fn new(op: char, spacing: Spacing) -> Punct {
435+
Punct {
434436
op: op,
435437
spacing: spacing,
436438
span: Span::call_site(),
437439
}
438440
}
439441

440-
pub fn op(&self) -> char {
442+
pub fn as_char(&self) -> char {
441443
self.op
442444
}
443445

@@ -454,15 +456,15 @@ impl Op {
454456
}
455457
}
456458

457-
impl fmt::Display for Op {
459+
impl fmt::Display for Punct {
458460
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
459461
self.op.fmt(f)
460462
}
461463
}
462464

463-
impl fmt::Debug for Op {
465+
impl fmt::Debug for Punct {
464466
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
465-
let mut debug = fmt.debug_struct("Op");
467+
let mut debug = fmt.debug_struct("Punct");
466468
debug.field("op", &self.op);
467469
debug.field("spacing", &self.spacing);
468470
#[cfg(procmacro2_semver_exempt)]
@@ -471,26 +473,31 @@ impl fmt::Debug for Op {
471473
}
472474
}
473475

474-
#[derive(Copy, Clone)]
475-
pub struct Term {
476-
inner: imp::Term,
476+
#[derive(Clone)]
477+
pub struct Ident {
478+
inner: imp::Ident,
477479
_marker: marker::PhantomData<Rc<()>>,
478480
}
479481

480-
impl Term {
481-
fn _new(inner: imp::Term) -> Term {
482-
Term {
482+
impl Ident {
483+
fn _new(inner: imp::Ident) -> Ident {
484+
Ident {
483485
inner: inner,
484486
_marker: marker::PhantomData,
485487
}
486488
}
487489

488-
pub fn new(string: &str, span: Span) -> Term {
489-
Term::_new(imp::Term::new(string, span.inner))
490+
pub fn new(string: &str, span: Span) -> Ident {
491+
Ident::_new(imp::Ident::new(string, span.inner))
492+
}
493+
494+
#[cfg(procmacro2_semver_exempt)]
495+
pub fn new_raw(string: &str, span: Span) -> Ident {
496+
Ident::_new_raw(string, span)
490497
}
491498

492-
pub fn as_str(&self) -> &str {
493-
self.inner.as_str()
499+
fn _new_raw(string: &str, span: Span) -> Ident {
500+
Ident::_new(imp::Ident::new_raw(string, span.inner))
494501
}
495502

496503
pub fn span(&self) -> Span {
@@ -502,13 +509,40 @@ impl Term {
502509
}
503510
}
504511

505-
impl fmt::Display for Term {
512+
impl PartialEq for Ident {
513+
fn eq(&self, other: &Ident) -> bool{
514+
self.to_string() == other.to_string()
515+
}
516+
}
517+
518+
impl Eq for Ident {
519+
}
520+
521+
impl PartialOrd for Ident {
522+
fn partial_cmp(&self, other: &Ident) -> Option<Ordering> {
523+
Some(self.cmp(other))
524+
}
525+
}
526+
527+
impl Ord for Ident {
528+
fn cmp(&self, other: &Ident) -> Ordering {
529+
self.to_string().cmp(&other.to_string())
530+
}
531+
}
532+
533+
impl Hash for Ident {
534+
fn hash<H: Hasher>(&self, hasher: &mut H) {
535+
self.to_string().hash(hasher)
536+
}
537+
}
538+
539+
impl fmt::Display for Ident {
506540
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
507-
self.as_str().fmt(f)
541+
self.inner.fmt(f)
508542
}
509543
}
510544

511-
impl fmt::Debug for Term {
545+
impl fmt::Debug for Ident {
512546
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
513547
self.inner.fmt(f)
514548
}

0 commit comments

Comments
 (0)