Skip to content

Commit b8342ad

Browse files
BennoLossinojeda
authored andcommitted
rust: macros: fix usage of #[allow] in quote!
When using `quote!` as part of an expression that was not the last one in a function, the `#[allow(clippy::vec_init_then_push)]` attribute would be present on an expression, which is not allowed. This patch refactors that part of the macro to use a statement instead. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 6883b29 commit b8342ad

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

rust/macros/quote.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ impl ToTokens for TokenStream {
3939
/// [`quote_spanned!`](https://docs.rs/quote/latest/quote/macro.quote_spanned.html) macro from the
4040
/// `quote` crate but provides only just enough functionality needed by the current `macros` crate.
4141
macro_rules! quote_spanned {
42-
($span:expr => $($tt:tt)*) => {
43-
#[allow(clippy::vec_init_then_push)]
44-
{
45-
let mut tokens = ::std::vec::Vec::new();
46-
let span = $span;
47-
quote_spanned!(@proc tokens span $($tt)*);
42+
($span:expr => $($tt:tt)*) => {{
43+
let mut tokens;
44+
#[allow(clippy::vec_init_then_push)]
45+
{
46+
tokens = ::std::vec::Vec::new();
47+
let span = $span;
48+
quote_spanned!(@proc tokens span $($tt)*);
49+
}
4850
::proc_macro::TokenStream::from_iter(tokens)
4951
}};
5052
(@proc $v:ident $span:ident) => {};

0 commit comments

Comments
 (0)