Skip to content

Commit

Permalink
add ui tests for unchecked math
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Jun 3, 2019
1 parent 8a25fdb commit d7e0834
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/ui/intrinsics/unchecked_math_unsafe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(core_intrinsics)]

fn main() {
let (x, y) = (1u32, 2u32);
let add = std::intrinsics::unchecked_add(x, y); //~ ERROR call to unsafe function
let sub = std::intrinsics::unchecked_sub(x, y); //~ ERROR call to unsafe function
let mul = std::intrinsics::unchecked_mul(x, y); //~ ERROR call to unsafe function
}
27 changes: 27 additions & 0 deletions src/test/ui/intrinsics/unchecked_math_unsafe.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/unchecked_math_unsafe.rs:5:15
|
LL | let add = std::intrinsics::unchecked_add(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/unchecked_math_unsafe.rs:6:15
|
LL | let sub = std::intrinsics::unchecked_sub(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/unchecked_math_unsafe.rs:7:15
|
LL | let mul = std::intrinsics::unchecked_mul(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0133`.
8 changes: 8 additions & 0 deletions src/test/ui/intrinsics/unchecked_math_unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let (x, y) = (1u32, 2u32);
unsafe {
let add = std::intrinsics::unchecked_add(x, y); //~ ERROR use of unstable library feature
let sub = std::intrinsics::unchecked_sub(x, y); //~ ERROR use of unstable library feature
let mul = std::intrinsics::unchecked_mul(x, y); //~ ERROR use of unstable library feature
}
}
27 changes: 27 additions & 0 deletions src/test/ui/intrinsics/unchecked_math_unstable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
--> $DIR/unchecked_math_unstable.rs:4:19
|
LL | let add = std::intrinsics::unchecked_add(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(core_intrinsics)] to the crate attributes to enable

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
--> $DIR/unchecked_math_unstable.rs:5:19
|
LL | let sub = std::intrinsics::unchecked_sub(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(core_intrinsics)] to the crate attributes to enable

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
--> $DIR/unchecked_math_unstable.rs:6:19
|
LL | let mul = std::intrinsics::unchecked_mul(x, y);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(core_intrinsics)] to the crate attributes to enable

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.

0 comments on commit d7e0834

Please sign in to comment.