Type covariance absent when used in struct
還沒有人認領這個 Issue。
評估
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Rust
- 星號
- 4.3k
- 分支
- 391
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rust-ndarray/ndarray 的其他 Issue
-
.is_all_nan() returns true for an all-finite array可能已有人在做 @youdie006 於 54 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
rust-ndarray/ndarray#1612 · 1 則留言 · 1 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 48/100
rust-ndarray/ndarray#1617 · 1 則留言 ·
-
Stack overflow in `triu`可能已有人在做 @cestercian 於 28 天前認領。 未關閉bug good first issue
難度 3/5 1-2 天 新手友好度 68/100
rust-ndarray/ndarray#1615 · 1 則留言 ·
-
Empty Array lead to "The strides must not allow any element to be referenced by two different indices"可能已有人在做 @Guflly 於 66 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 72/100
rust-ndarray/ndarray#1609 ·
-
Accept owned arrays in `concatenate` and `stack`可能已有人在做 @watsaig 於 159 天前認領。 未關閉breaking-change enhancement
難度 3/5 1-2 天 新手友好度 45/100
rust-ndarray/ndarray#1591 · 2 則留言 ·
查看 rust-ndarray/ndarray 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 4 天內回覆
-
Update dusk-bls12_381 to 0.16可能已有人在做 @HDauven 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 72/100
googlefonts/fontquant#43 ·
-
bot:ai-assisted status:untriaged
難度 2/5 1-3 小時 新手友好度 68/100
midnightntwrk/midnight-zk#561 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 74/100
rubys/roundhouse#571 ·
維護者通常 1 天內回覆