failed Send inference with ndarray v0.17 and uom 0.38

Aperta
#1,617 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
data

Direzione di ricerca

Reproduce the minimal example in src/main.rs with Rust 1.98.1, uom 0.38, and ndarray 0.17.2, then compare the result with ndarray 0.16. Read the reported rust-lang/rust issue #162558 alongside ndarray's async and Send-related behavior; done means identifying whether the regression belongs to ndarray or rustc and documenting or fixing the confirmed cause.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I'm running into a compile error using an Array2uom::si::f64::Length from inside an async function.
Please note this did work with ndarray v0.16.

  • rust 1.98.1
  • uom v0.38
  • ndarray v0.17.2 (NOTE - v0.16 seems to work)

The problem can be isolated into the following minimal example, which I would expect to compile:

use uom::si::f64::Length;
use uom::ConstZero;
use ndarray::Array2;

fn assert_send<T: Send>(_t: T) {}

fn main() {
    assert_send(check());
}

async fn check() {
    let lengths: Array2<Length> = Array2::from_elem((2, 3), Length::ZERO);
    std::future::pending::<()>().await;
    println!("{}", lengths[(0, 0)].get::<uom::si::length::meter>());
}

This produces the following compiler error message:

error[E0308]: mismatched types
 --> src/main.rs:8:5
  |
8 |     assert_send(check());
  |     ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected struct `Quantity<..., ..., f64>`
             found struct `Quantity<..., ..., f64>`
note: the lifetime requirement is introduced here
 --> src/main.rs:5:19
  |
5 | fn assert_send<T: Send>(_t: T) {}
  |                   ^^^^

Since it is not clear to me if the problem is on the ndarray or the rustc side I also reported it to rust-lang/rust (#162558).
I have a workaround wrapping the Array2 into a newtype with a at(&self,usize,usize)->Length fn and using that to obtain Length quantities inside the async fn. This comes from a bigger project though (https://github.com/ODIN-fire/odin-rs) where such workarounds are clearly suboptimal since it is highly async.

Lingua principale
Rust
Stelle
4.3k
Fork
391
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-ndarray/ndarray

Tutte le issue di rust-ndarray/ndarray

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.