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 6c86826f0..3584c5b39 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -94,6 +94,15 @@ 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. +#[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 {} // Implement `Buffer` for all the types that implement `Sealed`.