rust-lang / rust-lang/rust-clippy
Breaking change suggestion for trait requirements on `&[u8]`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
(Feel free to change the title to a more descriptive one)
Clippy instructed me to open up this issue. Please see its output:
$ cargo clippy --fix --allow-dirty 21:50:16
Checking notesock v0.1.3 (/home/chris/src/repos/notesock)
warning: failed to automatically apply fixes suggested by rustc to crate `notesock`
after fixes were automatically applied the compiler reported errors within these files:
* src/main.rs
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error[E0277]: the trait bound `[u8]: bytes::buf::buf_impl::Buf` is not satisfied
--> src/main.rs:202:46
|
202 | match proxy_protocol::parse(&mut buf) {
| --------------------- ^^^ the trait `bytes::buf::buf_impl::Buf` is not implemented for `[u8]`
| |
| required by a bound introduced by this call
|
= help: the trait `bytes::buf::buf_impl::Buf` is implemented for `&[u8]`
= note: required for `&mut [u8]` to implement `bytes::buf::buf_impl::Buf`
note: required by a bound in `proxy_protocol::parse`
--> /home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proxy-protocol-0.5.0/src/lib.rs:127:29
|
127 | pub fn parse(buf: &mut impl Buf) -> Result<ProxyHeader, ParseError> {
| ^^^ required by this bound in `parse`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
Original diagnostics will follow.
warning: redundant slicing of the whole range
--> src/main.rs:201:27
|
201 | let mut buf = &buf.as_mut_slice()[..];
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the original value instead: `buf.as_mut_slice()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
= note: `#[warn(clippy::redundant_slicing)]` on by default
warning: `notesock` (bin "notesock" test) generated 1 warning (run `cargo clippy --fix --bin "notesock" --tests` to apply 1 suggestion)
warning: `notesock` (bin "notesock") generated 1 warning (1 duplicate)
Finished dev [unoptimized + debuginfo] target(s) in 0.59s
Reproducer
You can refer to my repository: https://github.com/Sir-Photch/notesock/blob/7fa7e2ba1720bb3949d987e118af488ae55f666e/src/main.rs#L201
Version
rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer at src/main.rs lines 201-202 and the proxy_protocol::parse signature shown in the report, using rustc 1.74.1 and cargo clippy --fix. Confirm why the suggested change produces E0277; done means the lint no longer applies a fix that leaves the crate failing to compile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100