Skip to content

Commit 86fde7c

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 86fde7c

File tree

6 files changed

+188
-171
lines changed

6 files changed

+188
-171
lines changed

Cargo.toml

+1-1
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

+2-2
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

+43-38
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
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")]
@@ -284,26 +284,26 @@ impl fmt::Debug for Span {
284284
#[derive(Clone)]
285285
pub enum TokenTree {
286286
Group(Group),
287-
Term(Term),
288-
Op(Op),
287+
Ident(Ident),
288+
Punct(Punct),
289289
Literal(Literal),
290290
}
291291

292292
impl TokenTree {
293293
pub fn span(&self) -> Span {
294294
match *self {
295295
TokenTree::Group(ref t) => t.span(),
296-
TokenTree::Term(ref t) => t.span(),
297-
TokenTree::Op(ref t) => t.span(),
296+
TokenTree::Ident(ref t) => t.span(),
297+
TokenTree::Punct(ref t) => t.span(),
298298
TokenTree::Literal(ref t) => t.span(),
299299
}
300300
}
301301

302302
pub fn set_span(&mut self, span: Span) {
303303
match *self {
304304
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),
305+
TokenTree::Ident(ref mut t) => t.set_span(span),
306+
TokenTree::Punct(ref mut t) => t.set_span(span),
307307
TokenTree::Literal(ref mut t) => t.set_span(span),
308308
}
309309
}
@@ -315,15 +315,15 @@ impl From<Group> for TokenTree {
315315
}
316316
}
317317

318-
impl From<Term> for TokenTree {
319-
fn from(g: Term) -> TokenTree {
320-
TokenTree::Term(g)
318+
impl From<Ident> for TokenTree {
319+
fn from(g: Ident) -> TokenTree {
320+
TokenTree::Ident(g)
321321
}
322322
}
323323

324-
impl From<Op> for TokenTree {
325-
fn from(g: Op) -> TokenTree {
326-
TokenTree::Op(g)
324+
impl From<Punct> for TokenTree {
325+
fn from(g: Punct) -> TokenTree {
326+
TokenTree::Punct(g)
327327
}
328328
}
329329

@@ -337,8 +337,8 @@ impl fmt::Display for TokenTree {
337337
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
338338
match *self {
339339
TokenTree::Group(ref t) => t.fmt(f),
340-
TokenTree::Term(ref t) => t.fmt(f),
341-
TokenTree::Op(ref t) => t.fmt(f),
340+
TokenTree::Ident(ref t) => t.fmt(f),
341+
TokenTree::Punct(ref t) => t.fmt(f),
342342
TokenTree::Literal(ref t) => t.fmt(f),
343343
}
344344
}
@@ -350,8 +350,8 @@ impl fmt::Debug for TokenTree {
350350
// so don't bother with an extra layer of indirection
351351
match *self {
352352
TokenTree::Group(ref t) => t.fmt(f),
353-
TokenTree::Term(ref t) => t.fmt(f),
354-
TokenTree::Op(ref t) => t.fmt(f),
353+
TokenTree::Ident(ref t) => t.fmt(f),
354+
TokenTree::Punct(ref t) => t.fmt(f),
355355
TokenTree::Literal(ref t) => t.fmt(f),
356356
}
357357
}
@@ -416,7 +416,7 @@ impl fmt::Debug for Group {
416416
}
417417

418418
#[derive(Copy, Clone)]
419-
pub struct Op {
419+
pub struct Punct {
420420
op: char,
421421
spacing: Spacing,
422422
span: Span,
@@ -428,16 +428,16 @@ pub enum Spacing {
428428
Joint,
429429
}
430430

431-
impl Op {
432-
pub fn new(op: char, spacing: Spacing) -> Op {
433-
Op {
431+
impl Punct {
432+
pub fn new(op: char, spacing: Spacing) -> Punct {
433+
Punct {
434434
op: op,
435435
spacing: spacing,
436436
span: Span::call_site(),
437437
}
438438
}
439439

440-
pub fn op(&self) -> char {
440+
pub fn as_char(&self) -> char {
441441
self.op
442442
}
443443

@@ -454,15 +454,15 @@ impl Op {
454454
}
455455
}
456456

457-
impl fmt::Display for Op {
457+
impl fmt::Display for Punct {
458458
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
459459
self.op.fmt(f)
460460
}
461461
}
462462

463-
impl fmt::Debug for Op {
463+
impl fmt::Debug for Punct {
464464
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
465-
let mut debug = fmt.debug_struct("Op");
465+
let mut debug = fmt.debug_struct("Punct");
466466
debug.field("op", &self.op);
467467
debug.field("spacing", &self.spacing);
468468
#[cfg(procmacro2_semver_exempt)]
@@ -471,26 +471,31 @@ impl fmt::Debug for Op {
471471
}
472472
}
473473

474-
#[derive(Copy, Clone)]
475-
pub struct Term {
476-
inner: imp::Term,
474+
#[derive(Clone)]
475+
pub struct Ident {
476+
inner: imp::Ident,
477477
_marker: marker::PhantomData<Rc<()>>,
478478
}
479479

480-
impl Term {
481-
fn _new(inner: imp::Term) -> Term {
482-
Term {
480+
impl Ident {
481+
fn _new(inner: imp::Ident) -> Ident {
482+
Ident {
483483
inner: inner,
484484
_marker: marker::PhantomData,
485485
}
486486
}
487487

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

492-
pub fn as_str(&self) -> &str {
493-
self.inner.as_str()
497+
fn _new_raw(string: &str, span: Span) -> Ident {
498+
Ident::_new(imp::Ident::new_raw(string, span.inner))
494499
}
495500

496501
pub fn span(&self) -> Span {
@@ -502,13 +507,13 @@ impl Term {
502507
}
503508
}
504509

505-
impl fmt::Display for Term {
510+
impl fmt::Display for Ident {
506511
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
507-
self.as_str().fmt(f)
512+
self.inner.fmt(f)
508513
}
509514
}
510515

511-
impl fmt::Debug for Term {
516+
impl fmt::Debug for Ident {
512517
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
513518
self.inner.fmt(f)
514519
}

0 commit comments

Comments
 (0)