Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quantity types aren't Unpin #204

Closed
Michael-F-Bryan opened this issue Sep 3, 2020 · 1 comment
Closed

Quantity types aren't Unpin #204

Michael-F-Bryan opened this issue Sep 3, 2020 · 1 comment

Comments

@Michael-F-Bryan
Copy link

I'm trying to use uom types in an async context and found that quantities are !Unpin.

Types like uom::si::f64::Velocity are meant to be identical to a normal float, so it should be perfectly fine for them to be Unpin. I'm guessing the offending part is the use of dyn trait objects that don't have + Unpin in their trait bounds.

This was found on uom 0.29.0 and rustc version 1.48.0-nightly (397b390cc 2020-08-27).

Here's a minimal test case:

#[test]
fn velocity_should_be_unpin() {
    fn assert_unpin<T: Unpin>() {}

    assert_unpin::<uom::si::f64::Velocity>();
}

And it fails with this compilation error:

error[E0277]: `(dyn uom::si::Dimension<T = uom::typenum::NInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, I = uom::typenum::Z0, N = uom::typenum::Z0, L = uom::typenum::PInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, Kind = (dyn uom::Kind + 'static), M = uom::typenum::Z0, J = uom::typenum::Z0, Th = uom::typenum::Z0> + 'static)` cannot be unpinned
  --> indexer\src\systems\motion\manual_mode.rs:94:9
   |
92 |         fn assert_unpin<T: Unpin>() {}
   |                            ----- required by this bound in `systems::motion::manual_mode::tests::velocity_should_be_unpin::assert_unpin`
93 |
94 |         assert_unpin::<uom::si::f64::Velocity>();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `uom::si::Quantity<(dyn uom::si::Dimension<T = uom::typenum::NInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, I = uom::typenum::Z0, N = uom::typenum::Z0, L = uom::typenum::PInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, Kind = (dyn uom::Kind + 'static), M = uom::typenum::Z0, J = uom::typenum::Z0, Th = uom::typenum::Z0> + 'static), (dyn uom::si::Units<f64, thermodynamic_temperature = uom::si::thermodynamic_temperature::kelvin, mass = uom::si::mass::kilogram, amount_of_substance = uom::si::amount_of_substance::mole, electric_current = uom::si::electric_current::ampere, length = uom::si::length::meter, luminous_intensity = uom::si::luminous_intensity::candela, time = uom::si::time::second> + 'static), f64>`, the trait `std::marker::Unpin` is not implemented for `(dyn uom::si::Dimension<T = uom::typenum::NInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, I = uom::typenum::Z0, N = uom::typenum::Z0, L = uom::typenum::PInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, Kind = (dyn uom::Kind + 'static), M = uom::typenum::Z0, J = uom::typenum::Z0, Th = uom::typenum::Z0> + 'static)`
   |
   = note: required because it appears within the type `std::marker::PhantomData<(dyn uom::si::Dimension<T = uom::typenum::NInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, I = uom::typenum::Z0, N = uom::typenum::Z0, L = uom::typenum::PInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, Kind = (dyn uom::Kind + 'static), M = uom::typenum::Z0, J = uom::typenum::Z0, Th = uom::typenum::Z0> + 'static)>`
   = note: required because it appears within the type `uom::si::Quantity<(dyn uom::si::Dimension<T = uom::typenum::NInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, I = uom::typenum::Z0, N = uom::typenum::Z0, L = uom::typenum::PInt<uom::typenum::UInt<uom::typenum::UTerm, uom::typenum::B1>>, Kind = (dyn uom::Kind + 'static), M = uom::typenum::Z0, J = uom::typenum::Z0, Th = uom::typenum::Z0> + 'static), (dyn uom::si::Units<f64, thermodynamic_temperature = uom::si::thermodynamic_temperature::kelvin, mass = uom::si::mass::kilogram, amount_of_substance = uom::si::amount_of_substance::mole, electric_current = uom::si::electric_current::ampere, length = uom::si::length::meter, luminous_intensity = uom::si::luminous_intensity::candela, time = uom::si::time::second> + 'static), f64>`

In my real code, the compiler suggests using #![feature(trivial_bounds)] (rust-lang/rust#48214).

    = note: required because it appears within the type `systems::motion::manual_mode::ManualMode`
    = help: see issue #48214
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
@iliekturtles
Copy link
Owner

Completed by #205. Had to manually merge the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants