[Migrated] Can not call function with sub-slice as argument
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Rust
- Sterne
- 3.4k
- Forks
- 125
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das kleine Rust-Beispiel im Issue zu reproduzieren, und vergleiche das Verhalten mit Issue 329. Erledigt ist es, wenn der Aufruf von t2 mit &main[10..13] ohne die gemeldeten Fehler zu Pointer-Casts und Pointer-Offsets kompiliert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100