Title: `ArrayView` should be covariant over lifetime · Issue #1332 · rust-ndarray/ndarray · GitHub
Open Graph Title: `ArrayView` should be covariant over lifetime · Issue #1332 · rust-ndarray/ndarray
X Title: `ArrayView` should be covariant over lifetime · Issue #1332 · rust-ndarray/ndarray
Description: Take a look at the following example: fn reference_covariant<'a>(x: &'static f64) -> &'a f64 { x } fn arrayview_covariant<'a>(x: ArrayView1<'static, f64>) -> ArrayView1<'a, f64> { x } The first compiles fine, the second one does not comp...
Open Graph Description: Take a look at the following example: fn reference_covariant<'a>(x: &'static f64) -> &'a f64 { x } fn arrayview_covariant<'a>(x: ArrayView1<'static, f64>) -> ArrayView1<'a, f64> { x } The first com...
X Description: Take a look at the following example: fn reference_covariant<'a>(x: &'static f64) -> &'a f64 { x } fn arrayview_covariant<'a>(x: ArrayView1<'static, f6...
Opengraph URL: https://github.com/rust-ndarray/ndarray/issues/1332
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ArrayView` should be covariant over lifetime","articleBody":"Take a look at the following example:\r\n```rust\r\nfn reference_covariant\u003c'a>(x: &'static f64) -> &'a f64 {\r\n x\r\n}\r\n\r\nfn arrayview_covariant\u003c'a>(x: ArrayView1\u003c'static, f64>) -> ArrayView1\u003c'a, f64> {\r\n x\r\n}\r\n```\r\n\r\nThe first compiles fine, the second one does not compile and give the following error message:\r\n```\r\nfn arrayview_covariant\u003c'a>(x: ArrayView1\u003c'static, f64>) -> ArrayView1\u003c'a, f64> {\r\n -- lifetime `'a` defined here\r\n x\r\n ^ returning this value requires that `'a` must outlive `'static`\r\n\r\nnote: requirement occurs because of the type `ArrayBase\u003cViewRepr\u003c&f64>, Dim\u003c[usize; 1]>>`, which makes the generic argument `ViewRepr\u003c&f64>` invariant\r\nnote: the struct `ArrayBase\u003cS, D>` is invariant over the parameter `S`\r\n```\r\n\r\nThe problem is caused by the usage of `S::Elem` inside the definition of `ArrayBase`.\r\n\r\nI stumbled across this problem, since I used `ArrayView` deep inside a data structure which should be covariant.\r\nAs a user of ndarray I would assume that `ArrayView`s behave the same as Rust references, but I see fixing this bug is hard without interface changes.\r\nIs there an easy work-around for such problems? I currently do not know of any...","author":{"url":"https://github.com/patengel","@type":"Person","name":"patengel"},"datePublished":"2023-10-05T14:09:49Z","url":"https://github.com/rust-ndarray/ndarray/issues/1332"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:afbd6bff-100b-e983-a69d-b4be4e5b1139 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9618:2AABF1:252A0AC:340E09D:6AFD453D |
| html-safe-nonce | 18e6d4384b0146f896ac1312736cbe8441b254d6bbf0f48c550bf26651d1b917 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjE4OjJBQUJGMToyNTJBMEFDOjM0MEUwOUQ6NkFGRDQ1M0QiLCJ2aXNpdG9yX2lkIjoiNjQ0NDAzMzI3NjE3MTMzOTA3MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 53b2f47c6a04a1128474199a00f3131a4feabaff63dd6c8402edc195a47c274d |
| hovercard-subject-tag | issue:1928394153 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/rust-ndarray/ndarray/1332/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7640aae97e55b72d31cc037ac271d48b2b813d6c319e10e9ab7798b6360787b2/rust-ndarray/ndarray/issues/1332 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7640aae97e55b72d31cc037ac271d48b2b813d6c319e10e9ab7798b6360787b2/rust-ndarray/ndarray/issues/1332 |
| og:image:alt | Take a look at the following example: fn reference_covariant<'a>(x: &'static f64) -> &'a f64 { x } fn arrayview_covariant<'a>(x: ArrayView1<'static, f64>) -> ArrayView1<'a, f64> { x } The first com... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | patengel |
| hostname | github.com |
| expected-hostname | github.com |
| None | bdbacc25b921224ff0befcb9e629560a1255be51aec9991d6e3f95b5e9151474 |
| turbo-cache-control | no-preview |
| go-import | github.com/rust-ndarray/ndarray git https://github.com/rust-ndarray/ndarray.git |
| octolytics-dimension-user_id | 44419403 |
| octolytics-dimension-user_login | rust-ndarray |
| octolytics-dimension-repository_id | 22598813 |
| octolytics-dimension-repository_nwo | rust-ndarray/ndarray |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22598813 |
| octolytics-dimension-repository_network_root_nwo | rust-ndarray/ndarray |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 556dd37bb0aceffb25724e151b5d858b3265b40b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width