-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
or_fun_call doesn't trigger on unsafe blocks #6675
Comments
Also the suggestion causes a borrowck error:
|
@jyn514 Can I ask a favor? In the future, it would be nice to have multiple issues reported in separate github issues, even if they are related. It makes it easier to track as they can be fixed separately. Also each bug may have a different difficulty level (which I believe is the case here) and it's nice to have "good first issues". |
Sure thing, I can open a new issue. |
@rustbot claim |
This is a complicated fix. Here are the things it does: - Calculate the `ydb_buffer_t` references for the variable and subscripts on every loop iteration, not once per call. This is what avoids the unsoundness in #40, since the `buf_addr` will be updated if the variable is reallocated. - Drop `t` before calling `ydb_subscript_next`. This avoids the following borrow-check errors: ``` error[E0502]: cannot borrow `*self` as immutable because it is also borrowed as mutable --> src/simple_api/mod.rs:1163:41 | 1149 | let t = self.subscripts.last_mut().unwrap_or(unsafe { self.variable.as_mut_vec() }); | --------------- mutable borrow occurs here ... 1163 | let (varname, subscripts) = self.get_buffers(); | ^^^^ immutable borrow occurs here ... 1183 | t.reserve(last_self_buffer.len_used as usize - t.len()); | - mutable borrow later used here ``` See code comments for details. It's possible in theory that this could be avoided by using raw pointers instead of a `&mut`, but I don't feel confident enough in my knowledge of unsafe Rust to do that. I would feel more confident if [Miri](https://github.com/rust-lang/miri/) worked on YDBRust, but unfortunately it [doesn't support external FFI calls](rust-lang/miri#11). - Add a test for the previous undefined behavior. - Make `get_last_buffer` an unsafe function It is used correctly, but knowing that requires non-local reasoning. This found a clippy bug: rust-lang/rust-clippy#6675
I tried this code (playground):
I expected to see this happen: Clippy warns on both
f
andg
.Instead, this happened: Clippy only warns on
f
.Meta
cargo clippy -V
: 0.1.51 (2021-02-03 e708cbd)The text was updated successfully, but these errors were encountered: