From: Gary Guo <gary@garyguo.net>
To: "Benno Lossin" <lossin@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 10/10] rust: pin-init: internal: turn `PhantomPinned` error into warnings
Date: Tue, 28 Apr 2026 14:10:59 +0100 [thread overview]
Message-ID: <20260428-pin-init-sync-v1-10-07f9bd3859fb@garyguo.net> (raw)
In-Reply-To: <20260428-pin-init-sync-v1-0-07f9bd3859fb@garyguo.net>
The `PhantomPinned` detection is just a lint, and is emitted as an error
because there is no `compile_warning!()` macro, and
`proc-macro-diagnostics` is not stable.
Use of `#[deprecated = ""]` attribute to approximate custom proc-macro
warnings. A new line is added before message for visual clarity.
An example warning with this trick looks like this:
warning: use of deprecated function `_::warn`:
The field `pin` of type `PhantomPinned` only has an effect if it has the `#[pin]` attribute
--> test.rs:9:5
|
9 | pin: marker::PhantomPinned,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Suggested-by: Benno Lossin <lossin@kernel.org>
Link: https://github.com/Rust-for-Linux/pin-init/issues/51
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/pin-init/internal/src/diagnostics.rs | 14 ++++++++++++++
rust/pin-init/internal/src/pin_data.rs | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/rust/pin-init/internal/src/diagnostics.rs b/rust/pin-init/internal/src/diagnostics.rs
index 3bdb477c2f2b..c7d9b3e624fc 100644
--- a/rust/pin-init/internal/src/diagnostics.rs
+++ b/rust/pin-init/internal/src/diagnostics.rs
@@ -3,6 +3,7 @@
use std::fmt::Display;
use proc_macro2::TokenStream;
+use quote::quote_spanned;
use syn::{spanned::Spanned, Error};
pub(crate) struct DiagCtxt(TokenStream);
@@ -15,6 +16,19 @@ pub(crate) fn error(&mut self, span: impl Spanned, msg: impl Display) -> ErrorGu
ErrorGuaranteed(())
}
+ pub(crate) fn warn(&mut self, span: impl Spanned, msg: impl Display) {
+ // Have the message start on a new line for visual clarity.
+ let msg = format!("\n{}", msg);
+ self.0.extend(quote_spanned!(span.span() =>
+ // Approximate using deprecated warning while `proc_macro_diagnostic` is unstable.
+ const _: () = {
+ #[deprecated = #msg]
+ const fn warn() {}
+ warn();
+ };
+ ));
+ }
+
pub(crate) fn with(
fun: impl FnOnce(&mut DiagCtxt) -> Result<TokenStream, ErrorGuaranteed>,
) -> TokenStream {
diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
index 76cd11bf28eb..163a31ed1556 100644
--- a/rust/pin-init/internal/src/pin_data.rs
+++ b/rust/pin-init/internal/src/pin_data.rs
@@ -85,7 +85,7 @@ pub(crate) fn pin_data(
for (pinned, field) in &fields {
if !pinned && is_phantom_pinned(&field.ty) {
- dcx.error(
+ dcx.warn(
field,
format!(
"The field `{}` of type `PhantomPinned` only has an effect \
--
2.51.2
next prev parent reply other threads:[~2026-04-28 13:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 13:10 [PATCH 00/10] rust: pin-init upstream sync for v7.2 (round 1) Gary Guo
2026-04-28 13:10 ` [PATCH 01/10] rust: pin-init: examples: mark as `#[inline]` all `From::from()`s for `Error` Gary Guo
2026-04-28 13:10 ` [PATCH 02/10] rust: pin-init: bump minimum Rust version to 1.82 Gary Guo
2026-04-28 13:10 ` [PATCH 03/10] rust: pin-init: cleanup `Zeroable` and `ZeroableOptions` Gary Guo
2026-04-28 13:10 ` [PATCH 04/10] rust: pin-init: extend `impl_zeroable_option` macro to handle generics Gary Guo
2026-04-28 13:10 ` [PATCH 05/10] rust: pin-init: internal: add missing where clause to projection types Gary Guo
2026-04-28 13:10 ` [PATCH 06/10] rust: pin-init: internal: remove redundant `#[pin]` filtering Gary Guo
2026-04-28 13:10 ` [PATCH 07/10] rust: pin-init: internal: adjust license identifier of `zeroable.rs` Gary Guo
2026-04-28 13:10 ` [PATCH 08/10] rust: pin-init: fix badge URL in README Gary Guo
2026-04-28 13:10 ` [PATCH 09/10] rust: pin-init: cleanup workaround for old Rust compiler Gary Guo
2026-04-28 13:10 ` Gary Guo [this message]
2026-05-01 13:44 ` [PATCH 11/11] rust: pin-init: internal: remove `collect_tuple` polyfill after MSRV bump Gary Guo
2026-05-10 22:05 ` [PATCH 00/10] rust: pin-init upstream sync for v7.2 (round 1) Gary Guo
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=20260428-pin-init-sync-v1-10-07f9bd3859fb@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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