Skip to content

Commit 1edd1b9

Browse files
authored
Merge pull request dtolnay#436 from dtolnay/autotraits
Transpose ProcMacroAutoTraits struct and PhantomData
2 parents ea778eb + 43bc011 commit 1edd1b9

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

src/extra.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::fallback;
55
use crate::imp;
6-
use crate::marker::Marker;
6+
use crate::marker::{ProcMacroAutoTraits, MARKER};
77
use crate::Span;
88
use core::fmt::{self, Debug};
99

@@ -14,7 +14,7 @@ use core::fmt::{self, Debug};
1414
#[derive(Copy, Clone)]
1515
pub struct DelimSpan {
1616
inner: DelimSpanEnum,
17-
_marker: Marker,
17+
_marker: ProcMacroAutoTraits,
1818
}
1919

2020
#[derive(Copy, Clone)]
@@ -45,7 +45,7 @@ impl DelimSpan {
4545

4646
DelimSpan {
4747
inner,
48-
_marker: Marker,
48+
_marker: MARKER,
4949
}
5050
}
5151

src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod imp;
160160
mod location;
161161

162162
use crate::extra::DelimSpan;
163-
use crate::marker::Marker;
163+
use crate::marker::{ProcMacroAutoTraits, MARKER};
164164
use core::cmp::Ordering;
165165
use core::fmt::{self, Debug, Display};
166166
use core::hash::{Hash, Hasher};
@@ -184,27 +184,27 @@ pub use crate::location::LineColumn;
184184
#[derive(Clone)]
185185
pub struct TokenStream {
186186
inner: imp::TokenStream,
187-
_marker: Marker,
187+
_marker: ProcMacroAutoTraits,
188188
}
189189

190190
/// Error returned from `TokenStream::from_str`.
191191
pub struct LexError {
192192
inner: imp::LexError,
193-
_marker: Marker,
193+
_marker: ProcMacroAutoTraits,
194194
}
195195

196196
impl TokenStream {
197197
fn _new(inner: imp::TokenStream) -> Self {
198198
TokenStream {
199199
inner,
200-
_marker: Marker,
200+
_marker: MARKER,
201201
}
202202
}
203203

204204
fn _new_fallback(inner: fallback::TokenStream) -> Self {
205205
TokenStream {
206206
inner: inner.into(),
207-
_marker: Marker,
207+
_marker: MARKER,
208208
}
209209
}
210210

@@ -241,7 +241,7 @@ impl FromStr for TokenStream {
241241
fn from_str(src: &str) -> Result<TokenStream, LexError> {
242242
let e = src.parse().map_err(|e| LexError {
243243
inner: e,
244-
_marker: Marker,
244+
_marker: MARKER,
245245
})?;
246246
Ok(TokenStream::_new(e))
247247
}
@@ -339,15 +339,15 @@ impl Error for LexError {}
339339
#[derive(Clone, PartialEq, Eq)]
340340
pub struct SourceFile {
341341
inner: imp::SourceFile,
342-
_marker: Marker,
342+
_marker: ProcMacroAutoTraits,
343343
}
344344

345345
#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))]
346346
impl SourceFile {
347347
fn _new(inner: imp::SourceFile) -> Self {
348348
SourceFile {
349349
inner,
350-
_marker: Marker,
350+
_marker: MARKER,
351351
}
352352
}
353353

@@ -386,21 +386,21 @@ impl Debug for SourceFile {
386386
#[derive(Copy, Clone)]
387387
pub struct Span {
388388
inner: imp::Span,
389-
_marker: Marker,
389+
_marker: ProcMacroAutoTraits,
390390
}
391391

392392
impl Span {
393393
fn _new(inner: imp::Span) -> Self {
394394
Span {
395395
inner,
396-
_marker: Marker,
396+
_marker: MARKER,
397397
}
398398
}
399399

400400
fn _new_fallback(inner: fallback::Span) -> Self {
401401
Span {
402402
inner: inner.into(),
403-
_marker: Marker,
403+
_marker: MARKER,
404404
}
405405
}
406406

@@ -919,14 +919,14 @@ impl Debug for Punct {
919919
#[derive(Clone)]
920920
pub struct Ident {
921921
inner: imp::Ident,
922-
_marker: Marker,
922+
_marker: ProcMacroAutoTraits,
923923
}
924924

925925
impl Ident {
926926
fn _new(inner: imp::Ident) -> Self {
927927
Ident {
928928
inner,
929-
_marker: Marker,
929+
_marker: MARKER,
930930
}
931931
}
932932

@@ -1046,7 +1046,7 @@ impl Debug for Ident {
10461046
#[derive(Clone)]
10471047
pub struct Literal {
10481048
inner: imp::Literal,
1049-
_marker: Marker,
1049+
_marker: ProcMacroAutoTraits,
10501050
}
10511051

10521052
macro_rules! suffixed_int_literals {
@@ -1093,14 +1093,14 @@ impl Literal {
10931093
fn _new(inner: imp::Literal) -> Self {
10941094
Literal {
10951095
inner,
1096-
_marker: Marker,
1096+
_marker: MARKER,
10971097
}
10981098
}
10991099

11001100
fn _new_fallback(inner: fallback::Literal) -> Self {
11011101
Literal {
11021102
inner: inner.into(),
1103-
_marker: Marker,
1103+
_marker: MARKER,
11041104
}
11051105
}
11061106

@@ -1260,7 +1260,7 @@ impl FromStr for Literal {
12601260
fn from_str(repr: &str) -> Result<Self, LexError> {
12611261
repr.parse().map(Literal::_new).map_err(|inner| LexError {
12621262
inner,
1263-
_marker: Marker,
1263+
_marker: MARKER,
12641264
})
12651265
}
12661266
}
@@ -1279,7 +1279,7 @@ impl Display for Literal {
12791279

12801280
/// Public implementation details for the `TokenStream` type, such as iterators.
12811281
pub mod token_stream {
1282-
use crate::marker::Marker;
1282+
use crate::marker::{ProcMacroAutoTraits, MARKER};
12831283
use crate::{imp, TokenTree};
12841284
use core::fmt::{self, Debug};
12851285

@@ -1292,7 +1292,7 @@ pub mod token_stream {
12921292
#[derive(Clone)]
12931293
pub struct IntoIter {
12941294
inner: imp::TokenTreeIter,
1295-
_marker: Marker,
1295+
_marker: ProcMacroAutoTraits,
12961296
}
12971297

12981298
impl Iterator for IntoIter {
@@ -1321,7 +1321,7 @@ pub mod token_stream {
13211321
fn into_iter(self) -> IntoIter {
13221322
IntoIter {
13231323
inner: self.inner.into_iter(),
1324-
_marker: Marker,
1324+
_marker: MARKER,
13251325
}
13261326
}
13271327
}

src/marker.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
44

55
// Zero sized marker with the correct set of autotrait impls we want all proc
66
// macro types to have.
7-
pub(crate) type Marker = PhantomData<ProcMacroAutoTraits>;
7+
#[derive(Copy, Clone)]
8+
#[cfg_attr(
9+
all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)),
10+
derive(PartialEq, Eq)
11+
)]
12+
pub(crate) struct ProcMacroAutoTraits(PhantomData<Rc<()>>);
813

9-
pub(crate) use self::value::*;
10-
11-
mod value {
12-
pub(crate) use core::marker::PhantomData as Marker;
13-
}
14-
15-
pub(crate) struct ProcMacroAutoTraits(
16-
#[allow(dead_code)] // https://github.com/rust-lang/rust/issues/119645
17-
Rc<()>,
18-
);
14+
pub(crate) const MARKER: ProcMacroAutoTraits = ProcMacroAutoTraits(PhantomData);
1915

2016
impl UnwindSafe for ProcMacroAutoTraits {}
2117
impl RefUnwindSafe for ProcMacroAutoTraits {}

tests/ui/test-not-send.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ error[E0277]: `Rc<()>` cannot be sent between threads safely
2828
| ^^^^ `Rc<()>` cannot be sent between threads safely
2929
|
3030
= help: within `Span`, the trait `Send` is not implemented for `Rc<()>`
31-
note: required because it appears within the type `proc_macro2::marker::ProcMacroAutoTraits`
32-
--> $WORKSPACE/src/marker.rs
33-
|
34-
| pub(crate) struct ProcMacroAutoTraits(
35-
| ^^^^^^^^^^^^^^^^^^^
36-
note: required because it appears within the type `PhantomData<proc_macro2::marker::ProcMacroAutoTraits>`
31+
note: required because it appears within the type `PhantomData<Rc<()>>`
3732
--> $RUST/core/src/marker.rs
3833
|
3934
| pub struct PhantomData<T: ?Sized>;
4035
| ^^^^^^^^^^^
36+
note: required because it appears within the type `proc_macro2::marker::ProcMacroAutoTraits`
37+
--> $WORKSPACE/src/marker.rs
38+
|
39+
| pub(crate) struct ProcMacroAutoTraits(PhantomData<Rc<()>>);
40+
| ^^^^^^^^^^^^^^^^^^^
4141
note: required because it appears within the type `Span`
4242
--> $WORKSPACE/src/lib.rs
4343
|

0 commit comments

Comments
 (0)