Skip to content

Commit

Permalink
Rename procmacro2_unstable to procmacro2_semver_exempt
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 3, 2018
1 parent d66ecf6 commit 1ebe397
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 63 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ matrix:
script:
- cargo test
- cargo build --features nightly
- RUSTFLAGS='--cfg procmacro2_unstable' cargo test
- RUSTFLAGS='--cfg procmacro2_unstable' cargo build --features nightly
- RUSTFLAGS='--cfg procmacro2_unstable' cargo doc --no-deps
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build --features nightly
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo doc --no-deps
after_success:
- travis-cargo --only nightly doc-upload

script:
- cargo test
- RUSTFLAGS='--cfg procmacro2_unstable' cargo test
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
env:
global:
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ proc-macro2 = { version = "0.1", features = ["nightly"] }

`proc-macro2` supports exporting some methods from `proc_macro` which are
currently highly unstable, and may not be stabilized in the first pass of
`proc_macro` stabilizations. These features are not exported by default.
`proc_macro` stabilizations. These features are not exported by default. Minor
versions of `proc-macro2` may make breaking changes to them at any time.

To export these features, the `procmacro2_unstable` config flag must be passed
to rustc. To pass this flag, run `cargo` with
`RUSTFLAGS='--cfg procmacro2_unstable' cargo build`.
To enable these features, the `procmacro2_semver_exempt` config flag must be
passed to rustc.

```
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build
```

Note that this must not only be done for your crate, but for any crate that
depends on your crate. This infectious nature is intentional, as it serves as a
reminder that you are outside of the normal semver guarantees.


# License
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ impl TokenStream {
}

// Returned by reference, so we can't easily wrap it.
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub use imp::FileName;

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
#[derive(Clone, PartialEq, Eq)]
pub struct SourceFile(imp::SourceFile);

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl SourceFile {
/// Get the path to this source file as a string.
pub fn path(&self) -> &FileName {
Expand All @@ -123,21 +123,21 @@ impl SourceFile {
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl AsRef<FileName> for SourceFile {
fn as_ref(&self) -> &FileName {
self.0.path()
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl fmt::Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub struct LineColumn {
pub line: usize,
pub column: usize,
Expand Down Expand Up @@ -168,24 +168,24 @@ impl Span {
self.0.unstable()
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn source_file(&self) -> SourceFile {
SourceFile(self.0.source_file())
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn start(&self) -> LineColumn {
let imp::LineColumn{ line, column } = self.0.start();
LineColumn { line: line, column: column }
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn end(&self) -> LineColumn {
let imp::LineColumn{ line, column } = self.0.end();
LineColumn { line: line, column: column }
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn join(&self, other: Span) -> Option<Span> {
self.0.join(other.0).map(Span)
}
Expand Down
52 changes: 26 additions & 26 deletions src/stable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ascii;
use std::borrow::Borrow;
use std::cell::RefCell;
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
use std::cmp;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -36,7 +36,7 @@ impl TokenStream {
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
fn get_cursor(src: &str) -> Cursor {
// Create a dummy file & add it to the codemap
CODEMAP.with(|cm| {
Expand All @@ -50,7 +50,7 @@ fn get_cursor(src: &str) -> Cursor {
})
}

#[cfg(not(procmacro2_unstable))]
#[cfg(not(procmacro2_semver_exempt))]
fn get_cursor(src: &str) -> Cursor {
Cursor {
rest: src,
Expand Down Expand Up @@ -163,24 +163,24 @@ impl IntoIterator for TokenStream {
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FileName(String);

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl fmt::Display for FileName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
#[derive(Clone, PartialEq, Eq)]
pub struct SourceFile {
name: FileName,
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl SourceFile {
/// Get the path to this source file as a string.
pub fn path(&self) -> &FileName {
Expand All @@ -193,14 +193,14 @@ impl SourceFile {
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl AsRef<FileName> for SourceFile {
fn as_ref(&self) -> &FileName {
self.path()
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl fmt::Debug for SourceFile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("SourceFile")
Expand All @@ -210,14 +210,14 @@ impl fmt::Debug for SourceFile {
}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct LineColumn {
pub line: usize,
pub column: usize,
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
thread_local! {
static CODEMAP: RefCell<Codemap> = RefCell::new(Codemap {
// NOTE: We start with a single dummy file which all call_site() and
Expand All @@ -230,14 +230,14 @@ thread_local! {
});
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
struct FileInfo {
name: String,
span: Span,
lines: Vec<usize>,
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl FileInfo {
fn offset_line_column(&self, offset: usize) -> LineColumn {
assert!(self.span_within(Span { lo: offset as u32, hi: offset as u32 }));
Expand All @@ -260,7 +260,7 @@ impl FileInfo {
}

/// Computes the offsets of each line in the given source string.
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
fn lines_offsets(s: &str) -> Vec<usize> {
let mut lines = vec![0];
let mut prev = 0;
Expand All @@ -271,12 +271,12 @@ fn lines_offsets(s: &str) -> Vec<usize> {
lines
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
struct Codemap {
files: Vec<FileInfo>,
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
impl Codemap {
fn next_start_pos(&self) -> u32 {
// Add 1 so there's always space between files.
Expand Down Expand Up @@ -313,19 +313,19 @@ impl Codemap {

#[derive(Clone, Copy, Debug)]
pub struct Span {
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
lo: u32,
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
hi: u32,
}

impl Span {
#[cfg(not(procmacro2_unstable))]
#[cfg(not(procmacro2_semver_exempt))]
pub fn call_site() -> Span {
Span {}
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn call_site() -> Span {
Span { lo: 0, hi: 0 }
}
Expand All @@ -334,7 +334,7 @@ impl Span {
Span::call_site()
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn source_file(&self) -> SourceFile {
CODEMAP.with(|cm| {
let cm = cm.borrow();
Expand All @@ -345,7 +345,7 @@ impl Span {
})
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn start(&self) -> LineColumn {
CODEMAP.with(|cm| {
let cm = cm.borrow();
Expand All @@ -354,7 +354,7 @@ impl Span {
})
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn end(&self) -> LineColumn {
CODEMAP.with(|cm| {
let cm = cm.borrow();
Expand All @@ -363,7 +363,7 @@ impl Span {
})
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn join(&self, other: Span) -> Option<Span> {
CODEMAP.with(|cm| {
let cm = cm.borrow();
Expand Down Expand Up @@ -578,7 +578,7 @@ named!(token_stream -> ::TokenStream, map!(
|trees| ::TokenStream(TokenStream { inner: trees })
));

#[cfg(not(procmacro2_unstable))]
#[cfg(not(procmacro2_semver_exempt))]
fn token_tree(input: Cursor) -> PResult<TokenTree> {
let (input, kind) = token_kind(input)?;
Ok((input, TokenTree {
Expand All @@ -587,7 +587,7 @@ fn token_tree(input: Cursor) -> PResult<TokenTree> {
}))
}

#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
fn token_tree(input: Cursor) -> PResult<TokenTree> {
let input = skip_whitespace(input);
let lo = input.off;
Expand Down
6 changes: 3 additions & 3 deletions src/strnom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use imp::LexError;
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Cursor<'a> {
pub rest: &'a str,
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub off: u32,
}

impl<'a> Cursor<'a> {
#[cfg(not(procmacro2_unstable))]
#[cfg(not(procmacro2_semver_exempt))]
pub fn advance(&self, amt: usize) -> Cursor<'a> {
Cursor {
rest: &self.rest[amt..],
}
}
#[cfg(procmacro2_unstable)]
#[cfg(procmacro2_semver_exempt)]
pub fn advance(&self, amt: usize) -> Cursor<'a> {
Cursor {
rest: &self.rest[amt..],
Expand Down
Loading

0 comments on commit 1ebe397

Please sign in to comment.