Type covariance absent when used in struct
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Rust
- Stars
- 4.3k
- Forks
- 391
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-ndarray/ndarray
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-ndarray/ndarray#1612 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
rust-ndarray/ndarray#1617 · 1 comment ·
-
bug good first issue
Difficulty 3/5 1-2 days Newbie friendliness 68/100
rust-ndarray/ndarray#1615 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
rust-ndarray/ndarray#1609 ·
-
breaking-change enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
rust-ndarray/ndarray#1591 · 2 comments ·
All issues in rust-ndarray/ndarray
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100