Skip to content

Commit 47f36a0

Browse files
authored
Merge pull request #44 from alexcrichton/unstable-flags
Rename procmacro2_unstable and proc-macro2/unstable
2 parents fa1864f + 1ebe397 commit 47f36a0

File tree

8 files changed

+94
-77
lines changed

8 files changed

+94
-77
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ matrix:
1111
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
1212
script:
1313
- cargo test
14-
- cargo build --features unstable
15-
- RUSTFLAGS='--cfg procmacro2_unstable' cargo test
16-
- RUSTFLAGS='--cfg procmacro2_unstable' cargo build --features unstable
17-
- RUSTFLAGS='--cfg procmacro2_unstable' cargo doc --no-deps
14+
- cargo build --features nightly
15+
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
16+
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build --features nightly
17+
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo doc --no-deps
1818
after_success:
1919
- travis-cargo --only nightly doc-upload
2020

2121
script:
2222
- cargo test
23-
- RUSTFLAGS='--cfg procmacro2_unstable' cargo test
23+
- RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo test
2424
env:
2525
global:
2626
- TRAVIS_CARGO_NIGHTLY_FEATURE=""

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ doctest = false
2121
unicode-xid = "0.1"
2222

2323
[features]
24-
unstable = []
24+
25+
# When enabled: act as a shim around the nightly compiler's proc_macro crate.
26+
# This requires a nightly compiler.
27+
#
28+
# When disabled: emulate the same API as the nightly compiler's proc_macro crate
29+
# but in a way that works on all stable compilers >=1.15.0.
30+
nightly = []
31+
32+
# Deprecated; use "nightly" instead.
33+
unstable = ["nightly"]

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn my_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
4848
}
4949
```
5050

51-
If you'd like you can enable the `unstable` feature in this crate. This will
51+
If you'd like you can enable the `nightly` feature in this crate. This will
5252
cause it to compile against the **unstable and nightly-only** features of the
5353
`proc_macro` crate. This in turn requires a nightly compiler. This should help
5454
preserve span information, however, coming in from the compiler itself.
@@ -57,19 +57,27 @@ You can enable this feature via:
5757

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

6363

6464
## Unstable Features
6565

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

70-
To export these features, the `procmacro2_unstable` config flag must be passed
71-
to rustc. To pass this flag, run `cargo` with
72-
`RUSTFLAGS='--cfg procmacro2_unstable' cargo build`.
71+
To enable these features, the `procmacro2_semver_exempt` config flag must be
72+
passed to rustc.
73+
74+
```
75+
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build
76+
```
77+
78+
Note that this must not only be done for your crate, but for any crate that
79+
depends on your crate. This infectious nature is intentional, as it serves as a
80+
reminder that you are outside of the normal semver guarantees.
7381

7482

7583
# License

src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@
1414
//! to use this crate will be trivially able to switch to the upstream
1515
//! `proc_macro` crate once its API stabilizes.
1616
//!
17-
//! In the meantime this crate also has an `unstable` Cargo feature which
17+
//! In the meantime this crate also has a `nightly` Cargo feature which
1818
//! enables it to reimplement itself with the unstable API of `proc_macro`.
1919
//! This'll allow immediate usage of the beneficial upstream API, particularly
2020
//! around preserving span information.
2121
22-
#![cfg_attr(feature = "unstable", feature(proc_macro))]
22+
#![cfg_attr(feature = "nightly", feature(proc_macro))]
2323

2424
extern crate proc_macro;
2525

26-
#[cfg(not(feature = "unstable"))]
26+
#[cfg(not(feature = "nightly"))]
2727
extern crate unicode_xid;
2828

2929
use std::fmt;
3030
use std::str::FromStr;
3131
use std::iter::FromIterator;
3232

3333
#[macro_use]
34-
#[cfg(not(feature = "unstable"))]
34+
#[cfg(not(feature = "nightly"))]
3535
mod strnom;
3636

3737
#[path = "stable.rs"]
38-
#[cfg(not(feature = "unstable"))]
38+
#[cfg(not(feature = "nightly"))]
3939
mod imp;
4040
#[path = "unstable.rs"]
41-
#[cfg(feature = "unstable")]
41+
#[cfg(feature = "nightly")]
4242
mod imp;
4343

4444
#[macro_use]
@@ -104,14 +104,14 @@ impl TokenStream {
104104
}
105105

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

110-
#[cfg(procmacro2_unstable)]
110+
#[cfg(procmacro2_semver_exempt)]
111111
#[derive(Clone, PartialEq, Eq)]
112112
pub struct SourceFile(imp::SourceFile);
113113

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

126-
#[cfg(procmacro2_unstable)]
126+
#[cfg(procmacro2_semver_exempt)]
127127
impl AsRef<FileName> for SourceFile {
128128
fn as_ref(&self) -> &FileName {
129129
self.0.path()
130130
}
131131
}
132132

133-
#[cfg(procmacro2_unstable)]
133+
#[cfg(procmacro2_semver_exempt)]
134134
impl fmt::Debug for SourceFile {
135135
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
136136
self.0.fmt(f)
137137
}
138138
}
139139

140-
#[cfg(procmacro2_unstable)]
140+
#[cfg(procmacro2_semver_exempt)]
141141
pub struct LineColumn {
142142
pub line: usize,
143143
pub column: usize,
@@ -162,30 +162,30 @@ impl Span {
162162
Span(imp::Span::def_site())
163163
}
164164

165-
/// This method is only available when the `"unstable"` feature is enabled.
166-
#[cfg(feature = "unstable")]
165+
/// This method is only available when the `"nightly"` feature is enabled.
166+
#[cfg(feature = "nightly")]
167167
pub fn unstable(self) -> proc_macro::Span {
168168
self.0.unstable()
169169
}
170170

171-
#[cfg(procmacro2_unstable)]
171+
#[cfg(procmacro2_semver_exempt)]
172172
pub fn source_file(&self) -> SourceFile {
173173
SourceFile(self.0.source_file())
174174
}
175175

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

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

188-
#[cfg(procmacro2_unstable)]
188+
#[cfg(procmacro2_semver_exempt)]
189189
pub fn join(&self, other: Span) -> Option<Span> {
190190
self.0.join(other.0).map(Span)
191191
}

0 commit comments

Comments
 (0)