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

Conversation

SUPERCILEX
Copy link
Contributor

Recently discovered this was a thing, pretty cool!

error[E0277]: rustix does not accept `String` buffers
   --> src/buffer.rs:436:34
    |
436 |         let nread = read(&input, String::new()).unwrap();
    |                     ----         ^^^^^^^^^^^^^ Unsupported buffer type
    |                     |
    |                     required by a bound introduced by this call
    |
    = help: the trait `Buffer<u8>` is not implemented for `String`
    = 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
    = help: the following other types implement trait `Buffer<T>`:
              &mut [MaybeUninit<T>; N]
              &mut [MaybeUninit<T>]
              &mut [T; N]
              &mut [T]
              &mut std::vec::Vec<MaybeUninit<T>>
              &mut std::vec::Vec<T>
              SpareCapacity<'a, T>
note: required by a bound in `read_write::read`
   --> src/io/read_write.rs:39:28
    |
39  | pub fn read<Fd: AsFd, Buf: Buffer<u8>>(fd: Fd, mut buf: Buf) -> io::Result<Buf::Output> {
    |                            ^^^^^^^^^^ required by this bound in `read`

error[E0277]: the trait bound `String: buffer::private::Sealed<u8>` is not satisfied
   --> src/buffer.rs:436:21
    |
436 |         let nread = read(&input, String::new()).unwrap();
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `buffer::private::Sealed<u8>` is not implemented for `String`
    |
    = help: the following other types implement trait `buffer::private::Sealed<T>`:
              &'a mut [MaybeUninit<T>; N]
              &'a mut [MaybeUninit<T>]
              &'a mut std::vec::Vec<MaybeUninit<T>>
              &mut [T; N]
              &mut [T]
              &mut std::vec::Vec<T>
              SpareCapacity<'a, T>

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustix` (lib test) due to 2 previous errors

@sunfishcode
Copy link
Member

That's a fun feature! We'll need to make it conditional on the compiler though to support our MSRV.

@SUPERCILEX
Copy link
Contributor Author

Whoops, didn't notice the CI failure. I'll take a look tomorrow.

@SUPERCILEX
Copy link
Contributor Author

Looks like the freebsd failure is unrelated.

@sunfishcode sunfishcode merged commit 1b40a77 into bytecodealliance:main Jul 14, 2025
49 of 51 checks passed
@sunfishcode
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants