rust-lang / rust-lang/rust-clippy
useless_asref false positive on `&mut &[T]`
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Clippy complains about calling as_ref() on a mut slice when it shouldn't.
Lint Name
useless_asref
Reproducer
use std::{error::Error, io::BufRead};
fn main() {
let buf = get_buf();
// clippy complains with: "this call to `as_ref` does nothing"
test(&mut buf.as_ref()).unwrap();
// this is fine
test(&mut &*buf).unwrap();
}
fn get_buf<'a>() -> &'a mut [u8] {
todo!()
}
fn test<R>(_input: &mut R) -> Result<(), Box<dyn Error>>
where
R: BufRead + Send + Sync,
{
Ok(())
}
Version
rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0
Additional Labels
No response
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 by running the supplied Rust reproducer and locating the implementation and tests for the useless_asref lint. The fix is done when the &mut &[u8] case no longer produces a false positive while the existing valid-case behavior remains covered.
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
- Clearly specified
- Newbie friendliness
- 35/100