From: Benno Lossin <benno.lossin@proton.me>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev, Benno Lossin <benno.lossin@proton.me>
Subject: [PATCH 1/4] rust: macros: fix usage of `#[allow]` in `quote!`
Date: Mon, 24 Apr 2023 08:11:33 +0000 [thread overview]
Message-ID: <20230424081112.99890-1-benno.lossin@proton.me> (raw)
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 <benno.lossin@proton.me>
---
rust/macros/quote.rs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/rust/macros/quote.rs b/rust/macros/quote.rs
index c8e08b3c1e4c..dddbb4e6f4cb 100644
--- a/rust/macros/quote.rs
+++ b/rust/macros/quote.rs
@@ -39,12 +39,14 @@ impl ToTokens for TokenStream {
/// [`quote_spanned!`](https://docs.rs/quote/latest/quote/macro.quote_spanned.html) macro from the
/// `quote` crate but provides only just enough functionality needed by the current `macros` crate.
macro_rules! quote_spanned {
- ($span:expr => $($tt:tt)*) => {
- #[allow(clippy::vec_init_then_push)]
- {
- let mut tokens = ::std::vec::Vec::new();
- let span = $span;
- quote_spanned!(@proc tokens span $($tt)*);
+ ($span:expr => $($tt:tt)*) => {{
+ let mut tokens;
+ #[allow(clippy::vec_init_then_push)]
+ {
+ tokens = ::std::vec::Vec::new();
+ let span = $span;
+ quote_spanned!(@proc tokens span $($tt)*);
+ }
::proc_macro::TokenStream::from_iter(tokens)
}};
(@proc $v:ident $span:ident) => {};
base-commit: ea76e08f4d901a450619831a255e9e0a4c0ed162
--
2.40.0
next reply other threads:[~2023-04-24 8:11 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 8:11 Benno Lossin [this message]
2023-04-24 8:11 ` [PATCH 2/4] rust: macros: refactor generics parsing of `#[pin_data]` into its own function Benno Lossin
2023-04-24 13:01 ` Martin Rodriguez Reboredo
2023-05-17 20:44 ` Alice Ryhl
2023-05-23 16:04 ` Gary Guo
2023-04-24 8:11 ` [PATCH 3/4] rust: macros: replace Self with the concrete type in #[pin_data] Benno Lossin
2023-04-24 14:21 ` Martin Rodriguez Reboredo
2023-05-17 20:46 ` Alice Ryhl
2023-05-23 16:12 ` Gary Guo
2023-04-24 8:11 ` [PATCH 4/4] rust: init: update macro expansion example in docs Benno Lossin
2023-04-24 14:24 ` Martin Rodriguez Reboredo
2023-05-17 20:48 ` Alice Ryhl
2023-05-23 16:15 ` Gary Guo
2023-04-24 12:59 ` [PATCH 1/4] rust: macros: fix usage of `#[allow]` in `quote!` Martin Rodriguez Reboredo
2023-05-17 20:41 ` Alice Ryhl
2023-05-23 16:02 ` Gary Guo
2023-05-31 17:07 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230424081112.99890-1-benno.lossin@proton.me \
--to=benno.lossin@proton.me \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).