You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #59148 - lcnr:unchecked_maths, r=eddyb
add support for unchecked math
add compiler support for
```rust
/// Returns the result of an unchecked addition, resulting in
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
pub fn unchecked_add<T>(x: T, y: T) -> T;
/// Returns the result of an unchecked substraction, resulting in
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
pub fn unchecked_sub<T>(x: T, y: T) -> T;
/// Returns the result of an unchecked multiplication, resulting in
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
pub fn unchecked_mul<T>(x: T, y: T) -> T;
```
cc rust-lang/rfcs#2508
error[E0658]: use of unstable library feature 'core_intrinsics': intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
2
+
--> $DIR/unchecked_math_unstable.rs:4:19
3
+
|
4
+
LL | let add = std::intrinsics::unchecked_add(x, y);
5
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
+
|
7
+
= help: add #![feature(core_intrinsics)] to the crate attributes to enable
8
+
9
+
error[E0658]: use of unstable library feature 'core_intrinsics': intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
10
+
--> $DIR/unchecked_math_unstable.rs:5:19
11
+
|
12
+
LL | let sub = std::intrinsics::unchecked_sub(x, y);
13
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14
+
|
15
+
= help: add #![feature(core_intrinsics)] to the crate attributes to enable
16
+
17
+
error[E0658]: use of unstable library feature 'core_intrinsics': intrinsics are unlikely to ever be stabilized, instead they should be used through stabilized interfaces in the rest of the standard library
18
+
--> $DIR/unchecked_math_unstable.rs:6:19
19
+
|
20
+
LL | let mul = std::intrinsics::unchecked_mul(x, y);
21
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22
+
|
23
+
= help: add #![feature(core_intrinsics)] to the crate attributes to enable
24
+
25
+
error: aborting due to 3 previous errors
26
+
27
+
For more information about this error, try `rustc --explain E0658`.
0 commit comments