third_party_rust_syn/tests/macros/mod.rs
David Tolnay 189c60c649
Ignore unused_macro_rules warning in test macros
warning: 2nd rule of macro `snapshot_impl` is never used
      --> tests/macros/mod.rs:44:5
       |
    44 |     (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(unused_macro_rules)]` on by default

    warning: 1st rule of macro `snapshot_impl` is never used
      --> tests/macros/mod.rs:37:5
       |
    37 |     (($expr:ident) as $t:ty, @$snapshot:literal) => {
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: 3rd rule of macro `snapshot_impl` is never used
      --> tests/macros/mod.rs:52:5
       |
    52 |     (($($expr:tt)*) , @$snapshot:literal) => {{
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: 2nd rule of macro `spanless_eq_enum` is never used
       --> tests/common/eq.rs:225:5
        |
    225 | /     {
    226 | |         $($name:ident)::+;
    227 | |         $([$($variant:ident)::+; $($fields:tt)*])*
    228 | |         $next:ident [$([$($named:tt)*])* $(![$ignore:tt])*] (!$i:tt $($field:tt)*)
    229 | |         $($rest:tt)*
    230 | |     } => {
        | |_____^
        |
        = note: `#[warn(unused_macro_rules)]` on by default
2022-05-12 21:45:06 -07:00

80 lines
1.9 KiB
Rust

#![allow(unused_macros, unused_macro_rules)]
#[path = "../debug/mod.rs"]
pub mod debug;
use syn::parse::{Parse, Result};
macro_rules! errorf {
($($tt:tt)*) => {{
use ::std::io::Write;
let stderr = ::std::io::stderr();
write!(stderr.lock(), $($tt)*).unwrap();
}};
}
macro_rules! punctuated {
($($e:expr,)+) => {{
let mut seq = ::syn::punctuated::Punctuated::new();
$(
seq.push($e);
)+
seq
}};
($($e:expr),+) => {
punctuated!($($e,)+)
};
}
macro_rules! snapshot {
($($args:tt)*) => {
snapshot_impl!(() $($args)*)
};
}
macro_rules! snapshot_impl {
(($expr:ident) as $t:ty, @$snapshot:literal) => {
let $expr = crate::macros::Tokens::parse::<$t>($expr).unwrap();
let debug = crate::macros::debug::Lite(&$expr);
if !cfg!(miri) {
insta::assert_debug_snapshot!(debug, @$snapshot);
}
};
(($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{
let syntax_tree = crate::macros::Tokens::parse::<$t>($($expr)*).unwrap();
let debug = crate::macros::debug::Lite(&syntax_tree);
if !cfg!(miri) {
insta::assert_debug_snapshot!(debug, @$snapshot);
}
syntax_tree
}};
(($($expr:tt)*) , @$snapshot:literal) => {{
let syntax_tree = $($expr)*;
let debug = crate::macros::debug::Lite(&syntax_tree);
if !cfg!(miri) {
insta::assert_debug_snapshot!(debug, @$snapshot);
}
syntax_tree
}};
(($($expr:tt)*) $next:tt $($rest:tt)*) => {
snapshot_impl!(($($expr)* $next) $($rest)*)
};
}
pub trait Tokens {
fn parse<T: Parse>(self) -> Result<T>;
}
impl<'a> Tokens for &'a str {
fn parse<T: Parse>(self) -> Result<T> {
syn::parse_str(self)
}
}
impl Tokens for proc_macro2::TokenStream {
fn parse<T: Parse>(self) -> Result<T> {
syn::parse2(self)
}
}