Skip to content

Add diagnostics to unknown buffer types #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: private::Sealed<T> {}

// Implement `Buffer` for all the types that implement `Sealed`.
Expand Down
Loading