From 2793f10f1d5af73cf036e2dc5ddc2dfb607f19a9 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 3 Jul 2025 18:47:20 -0400 Subject: [PATCH 1/2] Add diagnostics to unknown buffer types Signed-off-by: Alex Saveau --- src/buffer.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/buffer.rs b/src/buffer.rs index 6c86826f0..eed7c2642 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -94,6 +94,12 @@ use core::slice; /// "captured variable cannot escape `FnMut` closure body", /// use an explicit loop instead of `retry_on_intr`, assuming you're using /// that. See `error_retry_closure_uninit` in examples/buffer_errors.rs. +#[diagnostic::on_unimplemented( + message = "rustix does not accept `{Self}` buffers", + label = "Unsupported buffer type", + note = "only (potentially uninitialized) byte arrays, slices, and Vecs are supported", + note = "please read the docs: https://docs.rs/rustix/latest/rustix/buffer/trait.Buffer.html" +)] pub trait Buffer: private::Sealed {} // Implement `Buffer` for all the types that implement `Sealed`. From 15bbe5fb54504b7186f97f0875e21e8cb7ae88a2 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sun, 13 Jul 2025 12:16:56 -0400 Subject: [PATCH 2/2] Fix diagnostics breaking older Rust support Signed-off-by: Alex Saveau --- Cargo.toml | 1 + build.rs | 4 ++++ src/buffer.rs | 13 ++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9630e7a1..2c20303bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -259,6 +259,7 @@ check-cfg = [ 'cfg(lower_upper_exp_for_non_zero)', 'cfg(netbsdlike)', 'cfg(rustc_attrs)', + 'cfg(rustc_diagnostics)', 'cfg(solarish)', 'cfg(staged_api)', 'cfg(static_assertions)', diff --git a/build.rs b/build.rs index 981e82612..ce9c85b9b 100644 --- a/build.rs +++ b/build.rs @@ -84,6 +84,10 @@ fn main() { use_feature("lower_upper_exp_for_non_zero"); } + if can_compile("#[diagnostic::on_unimplemented()] trait Foo {}") { + use_feature("rustc_diagnostics") + } + // WASI support can utilize wasi_ext if present. if os == "wasi" { use_feature_or_nothing("wasi_ext"); diff --git a/src/buffer.rs b/src/buffer.rs index eed7c2642..3584c5b39 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -94,11 +94,14 @@ use core::slice; /// "captured variable cannot escape `FnMut` closure body", /// use an explicit loop instead of `retry_on_intr`, assuming you're using /// that. See `error_retry_closure_uninit` in examples/buffer_errors.rs. -#[diagnostic::on_unimplemented( - message = "rustix does not accept `{Self}` buffers", - label = "Unsupported buffer type", - note = "only (potentially uninitialized) byte arrays, slices, and Vecs are supported", - note = "please read the docs: https://docs.rs/rustix/latest/rustix/buffer/trait.Buffer.html" +#[cfg_attr( + rustc_diagnostics, + diagnostic::on_unimplemented( + message = "rustix does not accept `{Self}` buffers", + label = "Unsupported buffer type", + note = "only (potentially uninitialized) byte arrays, slices, and Vecs are supported", + note = "please read the docs: https://docs.rs/rustix/latest/rustix/buffer/trait.Buffer.html" + ) )] pub trait Buffer: private::Sealed {}