rust-lang / rust-lang/rust-clippy
suggestions for `or_fun_call` can cause a borrowck error:
Open
Nobody has claimed this yet.
C-bug
E-hard
I-suggestion-causes-error
L-suggestion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
error[E0500]: closure requires unique access to `this` but it is already borrowed
--> src/simple_api/mod.rs:1150:55
|
1147 | unsafe fn get_last_buffer(this: &mut Key) -> &mut Vec<u8> {
| - let's call the lifetime of this reference `'1`
...
1150 | this.subscripts.last_mut().unwrap_or_else(|| this.variable.as_mut_vec())
| ------------------------------------------^^----------------------------
| | | |
| | | second borrow occurs due to use of `this` in closure
| | closure construction occurs here
| borrow occurs here
| returning this value requires that `this.subscripts` is borrowed for `'1`
Originally posted by @jyn514 in https://github.com/rust-lang/rust-clippy/issues/6675#issuecomment-773585764
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 or_fun_call lint and reproduce the reported case at src/simple_api/mod.rs:1150. Check the generated suggestion against Rust's borrow checker; done means the lint no longer proposes code that fails with the reported E0500 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100