Skip to content

Commit d981303

Browse files
authored
Merge branch 'master' into path
2 parents 9cd3b4c + 7c8bf4b commit d981303

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

.travis.yml

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

44
matrix:
55
include:
6-
- rust: 1.15.0
6+
- rust: 1.15.0 # oldest supported version
7+
script: cargo build
8+
- rust: 1.19.0 # first release with the --tests flag
9+
script: cargo test --tests
10+
- rust: 1.26.0 # first release on which our doc tests pass
711
- rust: stable
812
- rust: beta
913
- rust: nightly

Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ option, off by default, to also reimplement itself in terms of the upstream
1515
unstable API.
1616
"""
1717

18-
[lib]
19-
doctest = false
20-
2118
[package.metadata.docs.rs]
2219
rustc-args = ["--cfg", "procmacro2_semver_exempt"]
2320
rustdoc-args = ["--cfg", "procmacro2_semver_exempt"]
2421

2522
[dependencies]
2623
unicode-xid = "0.1"
2724

25+
[dev-dependencies]
26+
quote = "0.6"
27+
2828
[features]
2929
# When enabled: act as a shim around the nightly compiler's proc_macro crate.
3030
# This requires a nightly compiler.
@@ -38,3 +38,11 @@ default = ["proc-macro"]
3838

3939
[badges]
4040
travis-ci = { repository = "alexcrichton/proc-macro2" }
41+
42+
[patch.crates-io]
43+
# Our doc tests depend on quote which depends on proc-macro2. Without this line,
44+
# the proc-macro2 dependency of quote would be the released version of
45+
# proc-macro2. Quote would implement its traits for types from that proc-macro2,
46+
# meaning impls would be missing when tested against types from the local
47+
# proc-macro2.
48+
proc-macro2 = { path = "." }

src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,20 @@ impl fmt::Debug for LexError {
218218
/// This type is semver exempt and not exposed by default.
219219
#[cfg(procmacro2_semver_exempt)]
220220
#[derive(Clone, PartialEq, Eq)]
221-
pub struct SourceFile(imp::SourceFile);
221+
pub struct SourceFile {
222+
inner: imp::SourceFile,
223+
_marker: marker::PhantomData<Rc<()>>,
224+
}
222225

223226
#[cfg(procmacro2_semver_exempt)]
224227
impl SourceFile {
228+
fn _new(inner: imp::SourceFile) -> Self {
229+
SourceFile {
230+
inner: inner,
231+
_marker: marker::PhantomData,
232+
}
233+
}
234+
225235
/// Get the path to this source file.
226236
///
227237
/// ### Note
@@ -236,20 +246,20 @@ impl SourceFile {
236246
///
237247
/// [`is_real`]: #method.is_real
238248
pub fn path(&self) -> PathBuf {
239-
self.0.path()
249+
self.inner.path()
240250
}
241251

242252
/// Returns `true` if this source file is a real source file, and not
243253
/// generated by an external macro's expansion.
244254
pub fn is_real(&self) -> bool {
245-
self.0.is_real()
255+
self.inner.is_real()
246256
}
247257
}
248258

249259
#[cfg(procmacro2_semver_exempt)]
250260
impl fmt::Debug for SourceFile {
251261
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
252-
self.0.fmt(f)
262+
self.inner.fmt(f)
253263
}
254264
}
255265

@@ -335,7 +345,7 @@ impl Span {
335345
/// This method is semver exempt and not exposed by default.
336346
#[cfg(procmacro2_semver_exempt)]
337347
pub fn source_file(&self) -> SourceFile {
338-
SourceFile(self.inner.source_file())
348+
SourceFile::_new(self.inner.source_file())
339349
}
340350

341351
/// Get the starting line/column in the source file for this span.

tests/marker.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
extern crate proc_macro2;
2+
3+
use proc_macro2::*;
4+
5+
macro_rules! assert_impl {
6+
($ty:ident is $($marker:ident) and +) => {
7+
#[test]
8+
#[allow(non_snake_case)]
9+
fn $ty() {
10+
fn assert_implemented<T: $($marker +)+>() {}
11+
assert_implemented::<$ty>();
12+
}
13+
};
14+
15+
($ty:ident is not $($marker:ident) or +) => {
16+
#[test]
17+
#[allow(non_snake_case)]
18+
fn $ty() {
19+
$(
20+
{
21+
// Implemented for types that implement $marker.
22+
trait IsNotImplemented {
23+
fn assert_not_implemented() {}
24+
}
25+
impl<T: $marker> IsNotImplemented for T {}
26+
27+
// Implemented for the type being tested.
28+
trait IsImplemented {
29+
fn assert_not_implemented() {}
30+
}
31+
impl IsImplemented for $ty {}
32+
33+
// If $ty does not implement $marker, there is no ambiguity
34+
// in the following trait method call.
35+
<$ty>::assert_not_implemented();
36+
}
37+
)+
38+
}
39+
};
40+
}
41+
42+
assert_impl!(Delimiter is Send and Sync);
43+
assert_impl!(Spacing is Send and Sync);
44+
45+
assert_impl!(Group is not Send or Sync);
46+
assert_impl!(Ident is not Send or Sync);
47+
assert_impl!(LexError is not Send or Sync);
48+
assert_impl!(Literal is not Send or Sync);
49+
assert_impl!(Punct is not Send or Sync);
50+
assert_impl!(Span is not Send or Sync);
51+
assert_impl!(TokenStream is not Send or Sync);
52+
assert_impl!(TokenTree is not Send or Sync);
53+
54+
#[cfg(procmacro2_semver_exempt)]
55+
mod semver_exempt {
56+
use super::*;
57+
58+
assert_impl!(LineColumn is Send and Sync);
59+
60+
assert_impl!(SourceFile is not Send or Sync);
61+
}

0 commit comments

Comments
 (0)