From 857c40b22f90db6b3df7c49dd84f6c4caf0c5736 Mon Sep 17 00:00:00 2001 From: Iain McGinniss <309153+iainmcgin@users.noreply.github.com> Date: Fri, 29 May 2026 16:27:54 +0000 Subject: [PATCH] view: add #[diagnostic::on_unimplemented] hint to HasMessageView When a bound on HasMessageView fails - typically in downstream generated code such as connect-rust service stubs, where the user cannot annotate the call site - the compiler error now explains the cause and the fix: regenerate the defining crate with buffa 0.7.0 or newer and views enabled (generate_views(true) in buffa-build/buffa-codegen, views=true for protoc-gen-buffa), or enable the crate's views feature when the generated impls are feature-gated. Mirrors the existing ViewEncode diagnostic in the same module. --- CHANGELOG.md | 12 ++++++++++++ buffa/src/view.rs | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef4f636..8e30940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## [Unreleased] +### Changed + +- **`HasMessageView` carries a `#[diagnostic::on_unimplemented]` hint.** When a + type is used where the generated view family is required but its crate was + generated without one (buffa older than 0.7.0, or views disabled) or has it + behind a disabled feature, the compile error now explains the cause and how + to fix it — regenerate the defining crate with buffa ≥ 0.7.0 and views + enabled (`generate_views(true)` / `views=true`), or enable the crate's views + feature — instead of only naming the missing trait bound. Downstream + consumers such as connect-rust rely on this trait for their request + wrappers, so the notes land directly in the consumer's build output. + ## [0.7.0] - 2026-05-28 This release is a minor bump under the diff --git a/buffa/src/view.rs b/buffa/src/view.rs index 045c0bc..7ecefa3 100644 --- a/buffa/src/view.rs +++ b/buffa/src/view.rs @@ -241,6 +241,15 @@ pub trait ViewReborrow: MessageView<'static> { /// Implementations are generated alongside the view and owned-view wrapper /// (and are therefore gated with them). Hand-written implementations are only /// needed for hand-written view types and must follow the same shape. +#[diagnostic::on_unimplemented( + message = "`{Self}` does not implement `HasMessageView` — its message-view family was not generated or is not enabled", + note = "the `HasMessageView` impl is emitted next to each message's view types: \ + regenerate the crate that defines `{Self}` with buffa 0.7.0 or newer and \ + views enabled — `generate_views(true)` (on by default) in a buffa-build / \ + buffa-codegen config, or `views=true` for protoc-gen-buffa", + note = "if the defining crate feature-gates its generated impls, enabling its views \ + feature is enough — no regeneration needed" +)] pub trait HasMessageView: crate::Message + Sized { /// The zero-copy view of `Self`, borrowing from a buffer with lifetime /// `'a`.