Skip to content

Conversation

@linbingquan
Copy link
Contributor

Update to Rust 1.76

If this PR has any problem, please tell me.

cli/napi/util.rs Outdated
use deno_runtime::deno_napi::*;
use std::cell::Cell;

#[allow(invalid_reference_casting)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually invalid code.

Does this compile?

unsafe fn get_backing_store_slice(
  backing_store: &mut v8::SharedRef<v8::BackingStore>,
  byte_offset: usize,
  byte_length: usize,
) -> &mut [u8] {
  let cells: *mut [Cell<u8>] =
    &mut backing_store[byte_offset..byte_offset + byte_length];
  let mut bytes = cells as *mut [u8];
  &mut *bytes
}

Copy link
Contributor Author

@linbingquan linbingquan Feb 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reply.

Does this compile?

I think it was compile, maybe I miss something.

I think this is actually invalid code.

I try to remove #[allow(invalid_reference_casting)] code, I got this warning

warning: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
  --> cli\napi\util.rs:14:3
   |
13 |   let mut bytes = cells as *mut [u8];
   |                   ------------------ casting happend here
14 |   &mut *bytes
   |   ^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
   = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
   = note: `#[warn(invalid_reference_casting)]` on by default

warning: `deno` (bin "deno") generated 1 warning
warning: `deno` (bin "deno" test) generated 1 warning (1 duplicate)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try replacing this code with the code I put above and see if that fixes the warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try replacing this code with the code I put above and see if that fixes the warning?

I got this error

error[E0596]: cannot borrow data in dereference of `deno_core::v8::BackingStore` as mutable
  --> cli\napi\util.rs:12:10
   |
12 |     &mut backing_store[byte_offset..byte_offset + byte_length];
   |          ^^^^^^^^^^^^^ cannot borrow as mutable
   |
   = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `deno_core::v8::BackingStore`

For more information about this error, try `rustc --explain E0596`.
error: could not compile `deno` (bin "deno") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `deno` (bin "deno" test) due to 1 previous error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll push a change to this PR to fix it. I think I know what to do here.

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmastrac mmastrac enabled auto-merge (squash) February 12, 2024 02:29
@mmastrac mmastrac merged commit 80d5ffb into denoland:main Feb 12, 2024
littledivy pushed a commit that referenced this pull request Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants