Skip to content

Commit 1b40a77

Browse files
authored
Add diagnostics to unknown buffer types (#1488)
* Add diagnostics to unknown buffer types Signed-off-by: Alex Saveau <[email protected]> * Fix diagnostics breaking older Rust support Signed-off-by: Alex Saveau <[email protected]> --------- Signed-off-by: Alex Saveau <[email protected]>
1 parent 9113d68 commit 1b40a77

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ check-cfg = [
264264
'cfg(lower_upper_exp_for_non_zero)',
265265
'cfg(netbsdlike)',
266266
'cfg(rustc_attrs)',
267+
'cfg(rustc_diagnostics)',
267268
'cfg(solarish)',
268269
'cfg(staged_api)',
269270
'cfg(static_assertions)',

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ fn main() {
8888
use_feature("lower_upper_exp_for_non_zero");
8989
}
9090

91+
if can_compile("#[diagnostic::on_unimplemented()] trait Foo {}") {
92+
use_feature("rustc_diagnostics")
93+
}
94+
9195
// WASI support can utilize wasi_ext if present.
9296
if os == "wasi" {
9397
use_feature_or_nothing("wasi_ext");

src/buffer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ use core::slice;
9494
/// "captured variable cannot escape `FnMut` closure body",
9595
/// use an explicit loop instead of `retry_on_intr`, assuming you're using
9696
/// that. See `error_retry_closure_uninit` in examples/buffer_errors.rs.
97+
#[cfg_attr(
98+
rustc_diagnostics,
99+
diagnostic::on_unimplemented(
100+
message = "rustix does not accept `{Self}` buffers",
101+
label = "Unsupported buffer type",
102+
note = "only (potentially uninitialized) byte arrays, slices, and Vecs are supported",
103+
note = "please read the docs: https://docs.rs/rustix/latest/rustix/buffer/trait.Buffer.html"
104+
)
105+
)]
97106
pub trait Buffer<T>: private::Sealed<T> {}
98107

99108
// Implement `Buffer` for all the types that implement `Sealed`.

0 commit comments

Comments
 (0)