Rust-GPU / Rust-GPU/rust-gpu

[Migrated] Can not call function with sub-slice as argument

オープン
#121 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Rust
スター
3.4k
フォーク
126
PR マージ指標
30日以内にマージされた PR はありません

説明

Issue automatically imported from old repo: https://github.com/EmbarkStudios/rust-gpu/issues/752
Old labels: t: enhancement,s: qptr may fix
Originally creatd by SiebenCorgie on 2021-09-13T18:50:11Z


When calling a function with a sub-slice of some other slice, the compiler throws a strange error:

Small example:

pub fn t1(main: &[f32]){
    let a = t2(&main[10..13]);
}

fn t2(sub: &[f32]) -> u32{
    1
}

throws

  error: Cannot cast between pointer types
    --> /.../rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/const_ptr.rs:49:6
     |
  49 |     }
     |      ^
     |
     = note: from: *f32
     = note: to: *struct () {  }

  error: Cannot cast between pointer types
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/metadata.rs:117:14
      |
  117 |     unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[u8; 8]
      = note: to: *struct core::ptr::metadata::PtrComponents<[f32]> { *struct () {  }, u32 }

  error: Cannot cast between pointer types
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/metadata.rs:117:14
      |
  117 |     unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: from: *[u8; 8]
      = note: to: *struct *const [f32] { *[f32], u32 }

  error: Cannot offset a pointer to an arbitrary element
     --> /.../.rustup/toolchains/nightly-2021-08-27-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/const_ptr.rs:235:18
      |
  235 |         unsafe { intrinsics::offset(self, count) }
      |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is probably a similar problem like this, however, under different circumstances. If this is viewed as a duplicate, just close the Issue please.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、issue の小さな Rust 例を再現し、issue 329 と動作を比較します。&main[10..13] を指定した t2 の呼び出しが、報告されているポインターキャストとポインターオフセットのエラーなしにコンパイルできれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。