rust-lang / rust-lang/rust-clippy
useless_asref dosent understand ` &mut &'a`.
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 is saying to remove the "useless_asref" even though it does not work without it.
Lint Name
useless_asref
Reproducer
I tried this code:
fn test_fn<'a>(data: &mut &'a [u8], take: usize) -> &'a [u8] {
let (val, remaining) = data.split_at(take);
*data = remaining;
val
}
fn main(){
let data : &[u8] = &[0u8,1,2,3,4,5];
test_fn(&mut data.as_ref(), 2);
}
I saw this happen:
this call to `as_ref` does nothing
I expected to see this happen:
Should not show lint as it does not work without it.
Version
rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-pc-windows-msvc
release: 1.68.2
LLVM version: 15.0.6
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 with the useless_asref lint and the Rust reproducer in this issue, then run Clippy against it to confirm the warning. Trace why the lint treats &mut &'a [u8] and as_ref() as equivalent; done means the valid call no longer produces a false warning and the reproducer is covered by a regression test.
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
- 45/100