Skip to content

Commit

Permalink
Add #![feature(generic_const_exprs)] to doctests
Browse files Browse the repository at this point in the history
Some of them were missing this feature annotation but used to compile
and pass for some inexplicable reason. Now this missing feature gate
causes an ICE (rust-lang/rust#133199). This
adds the feature gates in all the doctests, but does not yet address the
fact that this ICE also occurs in calling crates that don't have
`#![feature(generic_const_exprs)]` set. Maybe a workaround could be to
check for this feature explicitly and throw a helpful error message in
diman.
  • Loading branch information
Tehforsch committed Jan 8, 2025
1 parent 86ddeb2 commit 47c6bae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
//! ## Arithmetics and math
//! Addition and subtraction of two quantities is allowed if the dimensions match:
//! ```
//! # #![feature(generic_const_exprs)]
//! # use diman::si::dimensions::{Length};
//! # use diman::si::units::{kilometers, meters};
//! let l = 5.0 * meters + 10.0 * kilometers;
Expand Down Expand Up @@ -94,6 +95,7 @@
//! ```
//! Exponentiation and related operations are supported via `squared`, `cubed`, `powi`, `sqrt`, `cbrt`:
//! ```
//! # #![feature(generic_const_exprs)]
//! # use diman::si::dimensions::{Length};
//! # use diman::si::units::{meters, cubic_meters, square_meters};
//! let length = 2.0f64 * meters;
Expand Down Expand Up @@ -139,6 +141,7 @@
//!
//! Conversion into the underlying storage type can be done using the `value_in` function:
//! ```
//! # #![feature(generic_const_exprs)]
//! # use diman::si::units::{kilometers, meters};
//! let length = 2.0f64 * kilometers;
//! assert_eq!(format!("{} m", length.value_in(meters)), "2000 m");
Expand Down Expand Up @@ -181,6 +184,7 @@
//! ```
//! The combination of `value_unchecked` and `new_unchecked` comes in handy when using third party libraries that only takes the raw storage type as argument. As an example, suppose we have a function `foo` that takes a `Vec<f64>` and returns a `Vec<f64>`, and suppose it sorts the numbers or does some other unit safe operation. Then we could reasonably write:
//! ```
//! # #![feature(generic_const_exprs)]
//! # use diman::si::dimensions::{Length};
//! # use diman::si::units::{meters, kilometers};
//! # fn foo(x: Vec<f64>) -> Vec<f64> {
Expand Down Expand Up @@ -312,6 +316,7 @@
//! not needed too many times. Having to add a definition to the unit system for this case can be cumbersome.
//! This is why the `Product` and `Quotient` types are provided:
//! ```
//! # #![feature(generic_const_exprs)]
//! use diman::si::dimensions::{Length, Time};
//! use diman::{Product, Quotient};
//!
Expand Down

0 comments on commit 47c6bae

Please sign in to comment.