Skip to content

Commit

Permalink
Merge pull request #1459 from dtolnay/wasm
Browse files Browse the repository at this point in the history
Extern crate proc_macro available on all wasm targets
  • Loading branch information
dtolnay committed May 25, 2023
2 parents 4e97063 + ee29399 commit ab19415
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -35,8 +35,8 @@ proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"]
test = ["syn-test-suite/all-features"]

[dependencies]
proc-macro2 = { version = "1.0.55", default-features = false }
quote = { version = "1.0.25", optional = true, default-features = false }
proc-macro2 = { version = "1.0.59", default-features = false }
quote = { version = "1.0.28", optional = true, default-features = false }
unicode-ident = "1"

[dev-dependencies]
Expand Down
10 changes: 2 additions & 8 deletions src/buffer.rs
Expand Up @@ -5,10 +5,7 @@
// Syn, and caution should be used when editing it. The public-facing interface
// is 100% safe but the implementation is fragile internally.

#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
use crate::proc_macro as pm;
use crate::Lifetime;
use proc_macro2::extra::DelimSpan;
Expand Down Expand Up @@ -60,10 +57,7 @@ impl TokenBuffer {

/// Creates a `TokenBuffer` containing all the tokens from the input
/// `proc_macro::TokenStream`.
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
pub fn new(stream: pm::TokenStream) -> Self {
Self::new2(stream.into())
Expand Down
5 changes: 1 addition & 4 deletions src/export.rs
Expand Up @@ -28,10 +28,7 @@ pub use crate::token::parsing::{peek_punct, punct as parse_punct};
#[cfg(feature = "printing")]
pub use crate::token::printing::punct as print_punct;

#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
pub use proc_macro::TokenStream;

#[cfg(feature = "printing")]
Expand Down
17 changes: 3 additions & 14 deletions src/lib.rs
Expand Up @@ -296,10 +296,7 @@
clippy::wildcard_imports,
)]

#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
extern crate proc_macro;

#[macro_use]
Expand Down Expand Up @@ -422,11 +419,7 @@ pub use crate::op::{BinOp, UnOp};
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
pub mod parse;

#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "parsing",
feature = "proc-macro"
))]
#[cfg(all(feature = "parsing", feature = "proc-macro"))]
mod parse_macro_input;

#[cfg(all(feature = "parsing", feature = "printing"))]
Expand Down Expand Up @@ -860,11 +853,7 @@ pub mod __private;
/// expanded.into()
/// }
/// ```
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "parsing",
feature = "proc-macro"
))]
#[cfg(all(feature = "parsing", feature = "proc-macro"))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "parsing", feature = "proc-macro"))))]
pub fn parse<T: parse::Parse>(tokens: proc_macro::TokenStream) -> Result<T> {
parse::Parser::parse(T::parse, tokens)
Expand Down
10 changes: 2 additions & 8 deletions src/parse.rs
Expand Up @@ -185,10 +185,7 @@ pub mod discouraged;
use crate::buffer::{Cursor, TokenBuffer};
use crate::error;
use crate::lookahead;
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
use crate::proc_macro;
use crate::punctuated::Punctuated;
use crate::token::Token;
Expand Down Expand Up @@ -1198,10 +1195,7 @@ pub trait Parser: Sized {
///
/// This function will check that the input is fully parsed. If there are
/// any unparsed tokens at the end of the stream, an error is returned.
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[cfg(feature = "proc-macro")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "proc-macro")))]
fn parse(self, tokens: proc_macro::TokenStream) -> Result<Self::Output> {
self.parse2(proc_macro2::TokenStream::from(tokens))
Expand Down

0 comments on commit ab19415

Please sign in to comment.