rust-lang / rust-lang/rust-clippy
clippy::borrowed_box shouldn't warn on return type
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
This function should be fine as the return type not only derefs to &[Item] but also allow more operations than just &[Item]:
fn inner(&self) -> &'_ Box<[Item]> {
&self.0
}
Lint Name
borrowed_box
Reproducer
I tried this code:
fn inner(&self) -> &'_ Box<[Item]> {
&self.0
}
I saw this happen:
you seem to be trying to use `&Box<T>`. Consider using just `&T`
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
`#[warn(clippy::borrowed_box)]` on by default
I expected to see this happen:
No warnings
Version
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
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 locating the borrowed_box lint and its existing test coverage, then reproduce the reported return-type example. Check the lint's handling of borrowed Box<[Item]> return types and verify that the example produces no warning when the change is complete.
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