[Migrated] Can not call function with sub-slice as argument
Nessuno ha ancora preso questa issue.
- Lingua principale
- Rust
- Stelle
- 3.4k
- Fork
- 126
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il piccolo esempio Rust nell’issue e confronta il comportamento con l’issue 329. È completato quando la chiamata a t2 con &main[10..13] compila senza gli errori segnalati di cast del puntatore e offset del puntatore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100