Skip to content

Commit 0957edd

Browse files
authored
Merge pull request #40 from alexcrichton/span
Omit Span::lo/hi when not using procmacro2_unstable
2 parents 92ab1b4 + 79105e5 commit 0957edd

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33

44
matrix:
55
include:
6-
- rust: 1.18.0
6+
- rust: 1.15.0
77
- rust: stable
88
- rust: beta
99
- rust: nightly

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ impl Span {
170170
#[cfg(procmacro2_unstable)]
171171
pub fn start(&self) -> LineColumn {
172172
let imp::LineColumn{ line, column } = self.0.start();
173-
LineColumn { line, column }
173+
LineColumn { line: line, column: column }
174174
}
175175

176176
#[cfg(procmacro2_unstable)]
177177
pub fn end(&self) -> LineColumn {
178178
let imp::LineColumn{ line, column } = self.0.end();
179-
LineColumn { line, column }
179+
LineColumn { line: line, column: column }
180180
}
181181

182182
#[cfg(procmacro2_unstable)]

src/stable.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ fn get_cursor(src: &str) -> Cursor {
5454
fn get_cursor(src: &str) -> Cursor {
5555
Cursor {
5656
rest: src,
57-
off: 0,
5857
}
5958
}
6059

@@ -313,15 +312,26 @@ impl Codemap {
313312
}
314313

315314
#[derive(Clone, Copy, Debug)]
316-
pub struct Span { lo: u32, hi: u32 }
315+
pub struct Span {
316+
#[cfg(procmacro2_unstable)]
317+
lo: u32,
318+
#[cfg(procmacro2_unstable)]
319+
hi: u32,
320+
}
317321

318322
impl Span {
323+
#[cfg(not(procmacro2_unstable))]
324+
pub fn call_site() -> Span {
325+
Span {}
326+
}
327+
328+
#[cfg(procmacro2_unstable)]
319329
pub fn call_site() -> Span {
320330
Span { lo: 0, hi: 0 }
321331
}
322332

323333
pub fn def_site() -> Span {
324-
Span { lo: 0, hi: 0 }
334+
Span::call_site()
325335
}
326336

327337
#[cfg(procmacro2_unstable)]
@@ -568,6 +578,16 @@ named!(token_stream -> ::TokenStream, map!(
568578
|trees| ::TokenStream(TokenStream { inner: trees })
569579
));
570580

581+
#[cfg(not(procmacro2_unstable))]
582+
fn token_tree(input: Cursor) -> PResult<TokenTree> {
583+
let (input, kind) = token_kind(input)?;
584+
Ok((input, TokenTree {
585+
span: ::Span(Span {}),
586+
kind: kind,
587+
}))
588+
}
589+
590+
#[cfg(procmacro2_unstable)]
571591
fn token_tree(input: Cursor) -> PResult<TokenTree> {
572592
let input = skip_whitespace(input);
573593
let lo = input.off;

src/strnom.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ use imp::LexError;
99
#[derive(Copy, Clone, Eq, PartialEq)]
1010
pub struct Cursor<'a> {
1111
pub rest: &'a str,
12+
#[cfg(procmacro2_unstable)]
1213
pub off: u32,
1314
}
1415

1516
impl<'a> Cursor<'a> {
17+
#[cfg(not(procmacro2_unstable))]
18+
pub fn advance(&self, amt: usize) -> Cursor<'a> {
19+
Cursor {
20+
rest: &self.rest[amt..],
21+
}
22+
}
23+
#[cfg(procmacro2_unstable)]
1624
pub fn advance(&self, amt: usize) -> Cursor<'a> {
1725
Cursor {
1826
rest: &self.rest[amt..],

tests/test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
extern crate proc_macro2;
22

3-
use proc_macro2::{Term, Literal, TokenStream, TokenNode, Span};
3+
use proc_macro2::{Term, Literal, TokenStream};
4+
5+
#[cfg(procmacro2_unstable)]
6+
use proc_macro2::TokenNode;
7+
8+
#[cfg(procmacro2_unstable)]
9+
#[cfg(not(feature = "unstable"))]
10+
use proc_macro2::Span;
411

512
#[test]
613
fn symbols() {

0 commit comments

Comments
 (0)