Skip to content

Commit ce0cb14

Browse files
committed
Auto merge of #50453 - alexcrichton:proc-macro-not-send, r=eddyb
proc_macro: Explicitly make everything !Send/Sync This commit adds explicit imp blocks to ensure that all publicly exported types (except simple enums) are not `Send` nor `Sync` in the `proc_macro` crate. cc #38356
2 parents 2c31547 + 3e0ed2f commit ce0cb14

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/libproc_macro/lib.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,23 @@ use syntax_pos::hygiene::Mark;
7474
#[derive(Clone)]
7575
pub struct TokenStream(tokenstream::TokenStream);
7676

77+
#[unstable(feature = "proc_macro", issue = "38356")]
78+
impl !Send for TokenStream {}
79+
#[unstable(feature = "proc_macro", issue = "38356")]
80+
impl !Sync for TokenStream {}
81+
7782
/// Error returned from `TokenStream::from_str`.
7883
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
7984
#[derive(Debug)]
8085
pub struct LexError {
8186
_inner: (),
8287
}
8388

89+
#[unstable(feature = "proc_macro", issue = "38356")]
90+
impl !Send for LexError {}
91+
#[unstable(feature = "proc_macro", issue = "38356")]
92+
impl !Sync for LexError {}
93+
8494
impl TokenStream {
8595
/// Returns an empty `TokenStream`.
8696
#[unstable(feature = "proc_macro", issue = "38356")]
@@ -231,6 +241,11 @@ pub fn quote_span(span: Span) -> TokenStream {
231241
#[derive(Copy, Clone)]
232242
pub struct Span(syntax_pos::Span);
233243

244+
#[unstable(feature = "proc_macro", issue = "38356")]
245+
impl !Send for Span {}
246+
#[unstable(feature = "proc_macro", issue = "38356")]
247+
impl !Sync for Span {}
248+
234249
macro_rules! diagnostic_method {
235250
($name:ident, $level:expr) => (
236251
/// Create a new `Diagnostic` with the given `message` at the span
@@ -363,6 +378,11 @@ pub struct LineColumn {
363378
pub column: usize
364379
}
365380

381+
#[unstable(feature = "proc_macro", issue = "38356")]
382+
impl !Send for LineColumn {}
383+
#[unstable(feature = "proc_macro", issue = "38356")]
384+
impl !Sync for LineColumn {}
385+
366386
/// The source file of a given `Span`.
367387
#[unstable(feature = "proc_macro", issue = "38356")]
368388
#[derive(Clone)]
@@ -393,7 +413,7 @@ impl SourceFile {
393413

394414
/// Returns `true` if this source file is a real source file, and not generated by an external
395415
/// macro's expansion.
396-
# [unstable(feature = "proc_macro", issue = "38356")]
416+
#[unstable(feature = "proc_macro", issue = "38356")]
397417
pub fn is_real(&self) -> bool {
398418
// This is a hack until intercrate spans are implemented and we can have real source files
399419
// for spans generated in external macros.
@@ -450,6 +470,11 @@ pub enum TokenTree {
450470
Literal(Literal),
451471
}
452472

473+
#[unstable(feature = "proc_macro", issue = "38356")]
474+
impl !Send for TokenTree {}
475+
#[unstable(feature = "proc_macro", issue = "38356")]
476+
impl !Sync for TokenTree {}
477+
453478
impl TokenTree {
454479
/// Returns the span of this token, accessing the `span` method of each of
455480
/// the internal tokens.
@@ -546,6 +571,11 @@ pub struct Group {
546571
span: Span,
547572
}
548573

574+
#[unstable(feature = "proc_macro", issue = "38356")]
575+
impl !Send for Group {}
576+
#[unstable(feature = "proc_macro", issue = "38356")]
577+
impl !Sync for Group {}
578+
549579
/// Describes how a sequence of token trees is delimited.
550580
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
551581
#[unstable(feature = "proc_macro", issue = "38356")]
@@ -628,6 +658,11 @@ pub struct Op {
628658
span: Span,
629659
}
630660

661+
#[unstable(feature = "proc_macro", issue = "38356")]
662+
impl !Send for Op {}
663+
#[unstable(feature = "proc_macro", issue = "38356")]
664+
impl !Sync for Op {}
665+
631666
/// Whether an `Op` is either followed immediately by another `Op` or followed by whitespace.
632667
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
633668
#[unstable(feature = "proc_macro", issue = "38356")]
@@ -694,6 +729,11 @@ pub struct Term {
694729
span: Span,
695730
}
696731

732+
#[unstable(feature = "proc_macro", issue = "38356")]
733+
impl !Send for Term {}
734+
#[unstable(feature = "proc_macro", issue = "38356")]
735+
impl !Sync for Term {}
736+
697737
impl Term {
698738
/// Creates a new `Term` with the given `string` as well as the specified
699739
/// `span`.
@@ -752,6 +792,11 @@ pub struct Literal {
752792
span: Span,
753793
}
754794

795+
#[unstable(feature = "proc_macro", issue = "38356")]
796+
impl !Send for Literal {}
797+
#[unstable(feature = "proc_macro", issue = "38356")]
798+
impl !Sync for Literal {}
799+
755800
macro_rules! suffixed_int_literals {
756801
($($name:ident => $kind:ident,)*) => ($(
757802
/// Creates a new suffixed integer literal with the specified value.

0 commit comments

Comments
 (0)