Given the following code:
fn main() {
let mut buf = [0u8; 50];
let mut bref = buf.as_slice();
foo(&mut bref);
}
fn foo(_: &mut impl std::io::Write) {}
The current output is:
error[E0277]: the trait bound `&[u8]: std::io::Write` is not satisfied
--> src/main.rs:4:9
|
4 | foo(&mut bref);
| --- ^^^^^^^^^ the trait `std::io::Write` is not implemented for `&[u8]`
| |
| required by a bound introduced by this call
|
= help: the trait `std::io::Write` is implemented for `&mut [u8]`
note: required by a bound in `foo`
--> src/main.rs:7:21
|
7 | fn foo(_: &mut impl std::io::Write) {}
| ^^^^^^^^^^^^^^ required by this bound in `foo`
help: consider changing this borrow's mutability
|
4 | foo(&mut mut bref);
| ~~~~
Notice that the suggestion is to write foo(&mut mut bref), which is both invalid syntax and not where the problem is located — as_slice() returns an & reference, so that call must be changed and no local syntax change can work.
Occurs on stable 1.65.0 and 1.68.0-nightly (2022-12-11 bdb07a8)
Given the following code:
The current output is:
Notice that the suggestion is to write
foo(&mut mut bref), which is both invalid syntax and not where the problem is located —as_slice()returns an&reference, so that call must be changed and no local syntax change can work.Occurs on stable 1.65.0 and 1.68.0-nightly (2022-12-11 bdb07a8)