Type covariance absent when used in struct
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Start with the reported Test struct and the covariant and invariant function examples in this issue. Compare variance behavior for Array2 fields with Box, tuples, and Rust arrays; done means identifying and correcting the discrepancy and adding a regression test for the lifetime conversion.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Arrays are covariant, but structs containing them don't seem to be. If I create a struct
struct Test<T> (ndarray::Array2<T>);
then, even though Array2 is covariant over T, my struct isn't:
// works
pub fn covariant<'long: 'short, 'short>(input: Box<ndarray::Array2<&'long u8>>) -> Box<ndarray::Array2<&'short u8>> {
input
}
// compiler error
pub fn invariant<'long: 'short, 'short>(input: Box<Test<&'long u8>>) -> Box<Test<&'short u8>> {
input
}
This doesn't make sense to me. From the rust reference, I would expect Test's variance to depend only on the types of its field, but it doesn't. Moreover, only structs that internally contain Array2 are affected: structs that take the array as a parameter (like the Box above) are fine, as are tuples and rust arrays. This is also unaffected by the complexity of the type inside the array, as long as it references a lifetime.
- Vorherrschende Sprache
- Rust
- Sterne
- 4.3k
- Forks
- 391
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Die Einrichtungsdateien dieses Projekts haben wir noch nicht geprüft. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rust-ndarray/ndarray
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
rust-ndarray/ndarray#1612 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
rust-ndarray/ndarray#1617 · 1 Kommentar ·
-
Stack overflow in `triu`Offenbug good first issue
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
rust-ndarray/ndarray#1615 · 1 Kommentar ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
rust-ndarray/ndarray#1609 ·
-
breaking-change enhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
rust-ndarray/ndarray#1591 · 2 Kommentare ·
Alle Issues in rust-ndarray/ndarray
Ähnliche Issues
-
type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
stackabletech/kafka-operator#1033 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug good first issue needs testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 3 Tagen
-
docs: release notes v3.7.0–v3.8.0 footer links to README/CHANGELOG are broken after docs reorgOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
farion1231/cc-switch#7744 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
datafusion
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
apache/iceberg-rust#3297 ·
Maintainer antworten meist innerhalb von 1 Tag