mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: "Benno Lossin" <lossin@kernel.org>,
	"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>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Gary Guo <gary@garyguo.net>
Subject: [PATCH 4/5] rust: pin-init: internal: add custom diagnostic when `#[pin_data]` is not implemented
Date: Wed, 23 Sep 2026 19:20:17 +0100	[thread overview]
Message-ID: <20260923-dev-pin-data-diag-v1-4-e4d7193569e5@garyguo.net> (raw)
In-Reply-To: <20260923-dev-pin-data-diag-v1-0-e4d7193569e5@garyguo.net>

Produce a more helpful error message when `#[pin_data]` is omitted. The
error message changes from

    error[E0277]: the trait bound `Foo: pin_init::__internal::HasPinData` is not satisfied
     --> tests/ui/compile-fail/init/missing_pin_data.rs:9:19
      |
    9 |         pin_init!(Self { a: 42 })
      |                   ^^^^ unsatisfied trait bound
      |
    help: the trait `pin_init::__internal::HasPinData` is not implemented for `Foo`
     --> tests/ui/compile-fail/init/missing_pin_data.rs:3:1
      |
    3 | struct Foo {
      | ^^^^^^^^^^

to

    error[E0277]: `Foo` cannot be used with `pin_init!` macro
     --> tests/ui/compile-fail/init/missing_pin_data.rs:9:19
      |
    9 |         pin_init!(Self { a: 42 })
      |                   ^^^^ unsatisfied trait bound
      |
    help: the trait `pin_init::__internal::HasPinData` is not implemented for `Foo`
     --> tests/ui/compile-fail/init/missing_pin_data.rs:3:1
      |
    3 | struct Foo {
      | ^^^^^^^^^^
      = note: did you forget to add `#[pin_data]` attribute to the struct?

Signed-off-by: Gary Guo <gary@garyguo.net>
---
 rust/pin-init/src/__internal.rs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rust/pin-init/src/__internal.rs b/rust/pin-init/src/__internal.rs
index f236db47d18b..cb7a0c3066b6 100644
--- a/rust/pin-init/src/__internal.rs
+++ b/rust/pin-init/src/__internal.rs
@@ -83,6 +83,10 @@ pub unsafe fn new() -> Self {
 ///
 /// `pin-init` relies on the correctness of the helper functions defined on `PinData`.
 /// Thus, only the `#[pin_data]` can implement this trait.
+#[diagnostic::on_unimplemented(
+    message = "`{Self}` cannot be used with `pin_init!` macro",
+    note = "did you forget to add `#[pin_data]` attribute to the struct?"
+)]
 pub unsafe trait HasPinData {
     type PinData;
 

-- 
2.54.0


  parent reply	other threads:[~2026-09-23 18:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 18:20 [PATCH 0/5] rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]` Gary Guo
2026-09-23 18:20 ` [PATCH 1/5] rust: pin-init: internal: make `__init_data` and `__pin_data` safe Gary Guo
2026-09-23 18:20 ` [PATCH 2/5] rust: pin-init: internal: remove associated type of `HasInitData` Gary Guo
2026-09-23 18:20 ` [PATCH 3/5] rust: pin-init: internal: use `HasInitData` to provide inference help only Gary Guo
2026-09-23 18:20 ` Gary Guo [this message]
2026-09-23 18:20 ` [PATCH 5/5] rust: pin-init: add diagnostic attribute for `PinInit` and `Init` Gary Guo
2026-09-25 20:41 ` [PATCH 0/5] rust: pin-init: improve diagnostics of missing `#[pin_data]` and `#[pin]` 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=20260923-dev-pin-data-diag-v1-4-e4d7193569e5@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /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

all inboxes | Powered by JetHome®