Move tests from test/run-fail to UI

This commit is contained in:
Yuki Okushi 2020-04-16 15:50:32 +09:00
parent 43271a39ad
commit e69748ba4f
No known key found for this signature in database
GPG key ID: B0986C85C0E2DAA1
160 changed files with 404 additions and 125 deletions

View file

@ -0,0 +1,10 @@
// run-fail
// error-pattern:index out of bounds
use std::usize;
use std::mem::size_of;
fn main() {
let xs = [1, 2, 3];
xs[usize::MAX / size_of::<isize>() + 1];
}

View file

@ -0,0 +1,11 @@
// Test bounds checking for DST raw slices
// run-fail
// error-pattern:index out of bounds
#[allow(unconditional_panic)]
fn main() {
let a: *const [_] = &[1, 2, 3];
unsafe {
let _b = (*a)[3];
}
}

View file

@ -0,0 +1,10 @@
// run-fail
// error-pattern:quux
fn foo() -> ! {
panic!("quux");
}
fn main() {
foo() == foo(); // these types wind up being defaulted to ()
}

View file

@ -0,0 +1,11 @@
// run-fail
// error-pattern:quux
fn my_err(s: String) -> ! {
println!("{}", s);
panic!("quux");
}
fn main() {
3_usize == my_err("bye".to_string());
}

View file

@ -0,0 +1,11 @@
// run-fail
// error-pattern:panic 1
// revisions: migrate mir
//[mir]compile-flags: -Z borrowck=mir
fn main() {
let x = 2;
let y = &x;
panic!("panic 1");
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:oops
fn main() {
let func = || -> ! {
panic!("oops");
};
func();
}

View file

@ -0,0 +1,8 @@
#![allow(unconditional_panic, const_err)]
// run-fail
// error-pattern: attempt to divide by zero
fn main() {
let x = &(1 / (1 - 1));
}

View file

@ -0,0 +1,10 @@
// run-fail
// error-pattern:explicit panic
fn f() -> ! {
panic!()
}
fn main() {
f();
}

View file

@ -0,0 +1,23 @@
// run-fail
// error-pattern:generator resumed after panicking
// Test that we get the correct message for resuming a panicked generator.
#![feature(generators, generator_trait)]
use std::{
ops::Generator,
pin::Pin,
panic,
};
fn main() {
let mut g = || {
panic!();
yield;
};
panic::catch_unwind(panic::AssertUnwindSafe(|| {
let x = Pin::new(&mut g).resume(());
}));
Pin::new(&mut g).resume(());
}

View file

@ -0,0 +1,12 @@
// run-fail
// error-pattern:capacity overflow
use std::collections::hash_map::HashMap;
use std::usize;
use std::mem::size_of;
fn main() {
let threshold = usize::MAX / size_of::<(u64, u64, u64)>();
let mut h = HashMap::<u64, u64>::with_capacity(threshold + 100);
h.insert(0, 0);
}

View file

@ -0,0 +1,19 @@
// run-fail
// error-pattern:explicit panic
fn f() -> ! {
panic!()
}
fn g() -> isize {
let x = if true {
f()
} else {
10
};
return x;
}
fn main() {
g();
}

View file

@ -0,0 +1,12 @@
// run-fail
// error-pattern:explicit panic
fn main() {
let _x = if false {
0
} else if true {
panic!()
} else {
10
};
}

View file

@ -0,0 +1,24 @@
// run-fail
// error-pattern:Number is odd
fn even(x: usize) -> bool {
if x < 2 {
return false;
} else if x == 2 {
return true;
} else {
return even(x - 2);
}
}
fn foo(x: usize) {
if even(x) {
println!("{}", x);
} else {
panic!("Number is odd");
}
}
fn main() {
foo(3);
}

View file

@ -0,0 +1,12 @@
// run-fail
// error-pattern:quux
fn my_err(s: String) -> ! {
println!("{}", s);
panic!("quux");
}
fn main() {
if my_err("bye".to_string()) {
}
}

View file

@ -0,0 +1,10 @@
// Issue #7580
// run-fail
// error-pattern:panic works
use std::*;
fn main() {
panic!("panic works")
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:explicit panic
pub fn main() {
panic!();
println!("{}", 1);
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:bad input
fn main() {
Some("foo").unwrap_or(panic!("bad input")).to_string();
}

View file

@ -0,0 +1,15 @@
// run-fail
// error-pattern:stop
// #18576
// Make sure that calling an extern function pointer in an unreachable
// context doesn't cause an LLVM assertion
#[allow(unreachable_code)]
fn main() {
panic!("stop");
let pointer = other;
pointer();
}
extern "C" fn other() {}

View file

@ -0,0 +1,22 @@
// Regression test for Issue #20971.
// run-fail
// error-pattern:Hello, world!
pub trait Parser {
type Input;
fn parse(&mut self, input: <Self as Parser>::Input);
}
impl Parser for () {
type Input = ();
fn parse(&mut self, input: ()) {}
}
pub fn many() -> Box<dyn Parser<Input = <() as Parser>::Input> + 'static> {
panic!("Hello, world!")
}
fn main() {
many().parse(());
}

View file

@ -0,0 +1,8 @@
// run-fail
// error-pattern:panic evaluated
#[allow(unused_variables)]
fn main() {
// This used to trigger an LLVM assertion during compilation
let x = [panic!("panic evaluated"); 2];
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:panic evaluated
#[allow(unused_variables)]
fn main() {
let x = [panic!("panic evaluated"); 0];
}

View file

@ -0,0 +1,16 @@
// run-fail
// error-pattern:explicit panic
use std::sync::Arc;
enum Err<T> {
Errr(Arc<T>),
}
fn foo() -> Err<isize> {
panic!();
}
fn main() {
let _f = foo();
}

View file

@ -0,0 +1,26 @@
// run-fail
// error-pattern:index out of bounds
use std::mem;
fn main() {
// This should cause a bounds-check panic, but may not if we do our
// bounds checking by comparing the scaled index to the vector's
// address-bounds, since we've scaled the index to wrap around to the
// address of the 0th cell in the array (even though the index is
// huge).
let x = vec![1_usize, 2_usize, 3_usize];
let base = x.as_ptr() as usize;
let idx = base / mem::size_of::<usize>();
println!("ov1 base = 0x{:x}", base);
println!("ov1 idx = 0x{:x}", idx);
println!("ov1 sizeof::<usize>() = 0x{:x}", mem::size_of::<usize>());
println!("ov1 idx * sizeof::<usize>() = 0x{:x}",
idx * mem::size_of::<usize>());
// This should panic.
println!("ov1 0x{:x}", x[idx]);
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:custom message
fn main() {
assert!(false, "custom message");
}

View file

@ -0,0 +1,24 @@
// Regression test: issue had to do with "givens" in region inference,
// which were not being considered during the contraction phase.
// run-fail
// error-pattern:explicit panic
struct Parser<'i: 't, 't>(&'i u8, &'t u8);
impl<'i, 't> Parser<'i, 't> {
fn parse_nested_block<F, T>(&mut self, parse: F) -> Result<T, ()>
where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> T
{
panic!()
}
fn expect_exhausted(&mut self) -> Result<(), ()> {
Ok(())
}
}
fn main() {
let x = 0u8;
Parser(&x, &x).parse_nested_block(|input| input.expect_exhausted()).unwrap();
}

View file

@ -0,0 +1,10 @@
// run-fail
// error-pattern:index out of bounds: the len is 5 but the index is 5
const fn test(x: usize) -> i32 {
[42;5][x]
}
fn main () {
let _ = test(5);
}

View file

@ -0,0 +1,13 @@
// run-fail
// error-pattern:so long
#![allow(unused_allocation)]
#![allow(unreachable_code)]
#![allow(unused_variables)]
fn main() {
let mut x = Vec::new();
let y = vec![3];
panic!("so long");
x.extend(y.into_iter());
}

View file

@ -0,0 +1,35 @@
// check that panics in destructors during assignment do not leave
// destroyed values lying around for other destructors to observe.
// run-fail
// error-pattern:panicking destructors ftw!
struct Observer<'a>(&'a mut FilledOnDrop);
struct FilledOnDrop(u32);
impl Drop for FilledOnDrop {
fn drop(&mut self) {
if self.0 == 0 {
// this is only set during the destructor - safe
// code should not be able to observe this.
self.0 = 0x1c1c1c1c;
panic!("panicking destructors ftw!");
}
}
}
impl<'a> Drop for Observer<'a> {
fn drop(&mut self) {
assert_eq!(self.0 .0, 1);
}
}
fn foo(b: &mut Observer) {
*b.0 = FilledOnDrop(1);
}
fn main() {
let mut bomb = FilledOnDrop(0);
let mut observer = Observer(&mut bomb);
foo(&mut observer);
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:overflow
use std::time::{Instant, Duration};
fn main() {
let now = Instant::now();
let _ = now + Duration::from_secs(u64::max_value());
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:overflow
use std::time::{Duration, SystemTime};
fn main() {
let now = SystemTime::now();
let _ = now + Duration::from_secs(u64::max_value());
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:overflow
use std::time::{Instant, Duration};
fn main() {
let now = Instant::now();
let _ = now - Duration::from_secs(u64::max_value());
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:overflow
use std::time::{Duration, SystemTime};
fn main() {
let now = SystemTime::now();
let _ = now - Duration::from_secs(u64::max_value());
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern: thread 'main' panicked at 'explicit panic'
fn main() {
let mut vec = vec![];
vec.push((vec.len(), panic!()));
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:explicit panic
fn foo<T>(t: T) {}
fn main() {
foo(panic!())
}

View file

@ -0,0 +1,25 @@
// run-fail
// error-pattern:quux
use std::marker::PhantomData;
fn test00_start(ch: Chan<isize>, message: isize) {
send(ch, message);
}
type TaskId = isize;
type PortId = isize;
struct Chan<T> {
task: TaskId,
port: PortId,
marker: PhantomData<*mut T>,
}
fn send<T: Send>(_ch: Chan<T>, _data: T) {
panic!();
}
fn main() {
panic!("quux");
}

View file

@ -0,0 +1,14 @@
// run-fail
// error-pattern:beep boop
#![allow(unused_variables)]
struct Point {
x: isize,
y: isize,
}
fn main() {
let origin = Point { x: 0, y: 0 };
let f: Point = Point { x: (panic!("beep boop")), ..origin };
}

View file

@ -0,0 +1,8 @@
// run-fail
// error-pattern:moop
fn main() {
for _ in 0_usize..10_usize {
panic!("moop");
}
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:assertion failed: 1 == 2
fn main() {
assert!(1 == 2);
}

View file

@ -0,0 +1,8 @@
// run-fail
// error-pattern:assertion failed: `(left == right)`
// error-pattern: left: `14`
// error-pattern:right: `15`
fn main() {
assert_eq!(14, 15);
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:panicked at 'assertion failed: false'
fn main() {
assert!(false);
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:panicked at 'test-assert-fmt 42 rust'
fn main() {
assert!(false, "test-assert-fmt {} {}", 42, "rust");
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:panicked at 'test-assert-owned'
fn main() {
assert!(false, "test-assert-owned".to_string());
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:panicked at 'test-assert-static'
fn main() {
assert!(false, "test-assert-static");
}

View file

@ -0,0 +1,8 @@
// run-fail
// error-pattern:assertion failed: `(left != right)`
// error-pattern: left: `14`
// error-pattern:right: `14`
fn main() {
assert_ne!(14, 14);
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:test
fn main() {
panic!("test");
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:test
fn main() {
let __isize: isize = panic!("test");
}

View file

@ -0,0 +1,10 @@
// run-fail
// error-pattern:test
fn f() {
panic!("test");
}
fn main() {
f();
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:not implemented
fn main() {
unimplemented!()
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:internal error: entered unreachable code: 6 is not prime
fn main() {
unreachable!("{} is not {}", 6u32, "prime");
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:internal error: entered unreachable code
fn main() {
unreachable!()
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:internal error: entered unreachable code: uhoh
fn main() {
unreachable!("uhoh")
}

View file

@ -0,0 +1,6 @@
// run-fail
// error-pattern:internal error: entered unreachable code
fn main() {
unreachable!()
}

View file

@ -0,0 +1,18 @@
// run-fail
// error-pattern:explicit panic
fn f() -> ! {
panic!()
}
fn g() -> isize {
let x = match true {
true => f(),
false => 10,
};
return x;
}
fn main() {
g();
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:explicit panic
fn main() {
let _x = match true {
false => 0,
true => panic!(),
};
}

View file

@ -0,0 +1,15 @@
// run-fail
// error-pattern:explicit panic
#![allow(unreachable_code)]
#![allow(unused_variables)]
fn foo(s: String) {}
fn main() {
let i = match Some::<isize>(3) {
None::<isize> => panic!(),
Some::<isize>(_) => panic!(),
};
foo(i);
}

View file

@ -0,0 +1,15 @@
// run-fail
// error-pattern:quux
fn f() -> ! {
panic!("quux")
}
fn g() -> isize {
match f() {
true => 1,
false => 0,
}
}
fn main() {
g();
}

View file

@ -0,0 +1,20 @@
// run-fail
// error-pattern:squirrelcupcake
fn cmp() -> isize {
match (Some('a'), None::<char>) {
(Some(_), _) => {
panic!("squirrelcupcake");
}
(_, Some(_)) => {
panic!();
}
_ => {
panic!("wat");
}
}
}
fn main() {
println!("{}", cmp());
}

View file

@ -0,0 +1,21 @@
// Meta test for compiletest: check that when we give the wrong error
// patterns, the test fails.
// run-fail
// revisions: foo bar
// should-fail
//[foo] error-pattern:bar
//[bar] error-pattern:foo
#[cfg(foo)]
fn die() {
panic!("foo");
}
#[cfg(bar)]
fn die() {
panic!("bar");
}
fn main() {
die();
}

View file

@ -0,0 +1,20 @@
// Meta test for compiletest: check that when we give the right error
// patterns, the test passes. See all `meta-revision-bad.rs`.
// run-fail
// revisions: foo bar
//[foo] error-pattern:foo
//[bar] error-pattern:bar
#[cfg(foo)]
fn die() {
panic!("foo");
}
#[cfg(bar)]
fn die() {
panic!("bar");
}
fn main() {
die();
}

View file

@ -0,0 +1,25 @@
// run-fail
// error-pattern:converging_fn called
// error-pattern:0 dropped
// error-pattern:exit
struct Droppable(u8);
impl Drop for Droppable {
fn drop(&mut self) {
eprintln!("{} dropped", self.0);
}
}
fn converging_fn() {
eprintln!("converging_fn called");
}
fn mir(d: Droppable) {
converging_fn();
}
fn main() {
let d = Droppable(0);
mir(d);
panic!("exit");
}

View file

@ -0,0 +1,29 @@
// run-fail
// error-pattern:complex called
// error-pattern:dropped
// error-pattern:exit
struct Droppable;
impl Drop for Droppable {
fn drop(&mut self) {
eprintln!("dropped");
}
}
// return value of this function is copied into the return slot
fn complex() -> u64 {
eprintln!("complex called");
42
}
fn mir() -> u64 {
let x = Droppable;
return complex();
drop(x);
}
pub fn main() {
assert_eq!(mir(), 42);
panic!("exit");
}

View file

@ -0,0 +1,14 @@
// run-fail
// error-pattern:diverging_fn called
fn diverging_fn() -> ! {
panic!("diverging_fn called")
}
fn mir() {
diverging_fn();
}
fn main() {
mir();
}

View file

@ -0,0 +1,23 @@
// run-fail
// error-pattern:diverging_fn called
// error-pattern:0 dropped
struct Droppable(u8);
impl Drop for Droppable {
fn drop(&mut self) {
eprintln!("{} dropped", self.0);
}
}
fn diverging_fn() -> ! {
panic!("diverging_fn called")
}
fn mir(d: Droppable) {
diverging_fn();
}
fn main() {
let d = Droppable(0);
mir(d);
}

View file

@ -0,0 +1,23 @@
// run-fail
// error-pattern:panic 1
// error-pattern:drop 2
struct Droppable(u32);
impl Drop for Droppable {
fn drop(&mut self) {
if self.0 == 1 {
panic!("panic 1");
} else {
eprintln!("drop {}", self.0);
}
}
}
fn mir() {
let x = Droppable(2);
let y = Droppable(1);
}
fn main() {
mir();
}

View file

@ -0,0 +1,31 @@
// run-fail
// error-pattern:drop 1
// error-pattern:drop 2
// ignore-cloudabi no std::process
/// Structure which will not allow to be dropped twice.
struct Droppable<'a>(&'a mut bool, u32);
impl<'a> Drop for Droppable<'a> {
fn drop(&mut self) {
if *self.0 {
eprintln!("{} dropped twice", self.1);
::std::process::exit(1);
}
eprintln!("drop {}", self.1);
*self.0 = true;
}
}
fn mir() {
let (mut xv, mut yv) = (false, false);
let x = Droppable(&mut xv, 1);
let y = Droppable(&mut yv, 2);
let mut z = x;
let k = y;
z = k;
}
fn main() {
mir();
panic!();
}

View file

@ -0,0 +1,29 @@
// run-fail
// error-pattern:drop 1
// ignore-cloudabi no std::process
/// Structure which will not allow to be dropped twice.
struct Droppable<'a>(&'a mut bool, u32);
impl<'a> Drop for Droppable<'a> {
fn drop(&mut self) {
if *self.0 {
eprintln!("{} dropped twice", self.1);
::std::process::exit(1);
}
eprintln!("drop {}", self.1);
*self.0 = true;
}
}
fn mir<'a>(d: Droppable<'a>) {
loop {
let x = d;
break;
}
}
fn main() {
let mut xv = false;
mir(Droppable(&mut xv, 1));
panic!();
}

View file

@ -0,0 +1,34 @@
// run-fail
// error-pattern:unwind happens
// error-pattern:drop 3
// error-pattern:drop 2
// error-pattern:drop 1
// ignore-cloudabi no std::process
/// Structure which will not allow to be dropped twice.
struct Droppable<'a>(&'a mut bool, u32);
impl<'a> Drop for Droppable<'a> {
fn drop(&mut self) {
if *self.0 {
eprintln!("{} dropped twice", self.1);
::std::process::exit(1);
}
eprintln!("drop {}", self.1);
*self.0 = true;
}
}
fn may_panic<'a>() -> Droppable<'a> {
panic!("unwind happens");
}
fn mir<'a>(d: Droppable<'a>) {
let (mut a, mut b) = (false, false);
let y = Droppable(&mut a, 2);
let x = [Droppable(&mut b, 1), y, d, may_panic()];
}
fn main() {
let mut c = false;
mir(Droppable(&mut c, 3));
}

View file

@ -0,0 +1,13 @@
// run-fail
// error-pattern:index out of bounds: the len is 5 but the index is 10
const C: [u32; 5] = [0; 5];
#[allow(unconditional_panic)]
fn test() -> u32 {
C[10]
}
fn main() {
test();
}

View file

@ -0,0 +1,13 @@
// run-fail
// error-pattern:index out of bounds: the len is 5 but the index is 10
const C: &'static [u8; 5] = b"hello";
#[allow(unconditional_panic)]
fn test() -> u8 {
C[10]
}
fn main() {
test();
}

View file

@ -0,0 +1,13 @@
// run-fail
// error-pattern:index out of bounds: the len is 5 but the index is 10
const C: &'static [u8; 5] = b"hello";
#[allow(unconditional_panic)]
fn mir() -> u8 {
C[10]
}
fn main() {
mir();
}

View file

@ -0,0 +1,17 @@
// Test that ! coerces to other types.
// run-fail
// error-pattern:aah!
fn call_another_fn<T, F: FnOnce() -> T>(f: F) -> T {
f()
}
fn wub() -> ! {
panic!("aah!");
}
fn main() {
let x: i32 = call_another_fn(wub);
let y: u32 = wub();
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:attempt to divide by zero
#[allow(unconditional_panic)]
fn main() {
let y = 0;
let _z = 1 / y;
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:attempt to calculate the remainder with a divisor of zero
#[allow(unconditional_panic)]
fn main() {
let y = 0;
let _z = 1 % y;
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:thread 'main' panicked at 'attempt to add with overflow'
// compile-flags: -C debug-assertions
#![allow(arithmetic_overflow)]
fn main() {
let _x = 200u8 + 200u8 + 200u8;
}

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = 1_i32 << 32;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-lsh-1.rs:7:14
|
LL | let _x = 1_i32 << 32;
| ^^^^^^^^^^^ attempt to shift left with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-lsh-1.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = 1 << -1;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-lsh-2.rs:7:14
|
LL | let _x = 1 << -1;
| ^^^^^^^ attempt to shift left with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-lsh-2.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = 1_u64 << 64;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-lsh-3.rs:7:14
|
LL | let _x = 1_u64 << 64;
| ^^^^^^^^^^^ attempt to shift left with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-lsh-3.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,24 @@
// build-fail
// compile-flags: -C debug-assertions
// This function is checking that our automatic truncation does not
// sidestep the overflow checking.
#![deny(arithmetic_overflow, const_err)]
fn main() {
// this signals overflow when checking is on
let x = 1_i8 << 17;
//~^ ERROR: this arithmetic operation will overflow
// ... but when checking is off, the fallback will truncate the
// input to its lower three bits (= 1). Note that this is *not*
// the behavior of the x86 processor for 8- and 16-bit types,
// but it is necessary to avoid undefined behavior from LLVM.
//
// We check that here, by ensuring the result has only been
// shifted by one place; if overflow checking is turned off, then
// this assertion will pass (and the compiletest driver will
// report that the test did not produce the error expected above).
assert_eq!(x, 2_i8);
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-lsh-4.rs:11:13
|
LL | let x = 1_i8 << 17;
| ^^^^^^^^^^ attempt to shift left with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-lsh-4.rs:7:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:thread 'main' panicked at 'attempt to multiply with overflow'
// compile-flags: -C debug-assertions
#![allow(arithmetic_overflow)]
fn main() {
let x = 200u8 * 4;
}

View file

@ -0,0 +1,9 @@
// run-fail
// error-pattern:thread 'main' panicked at 'attempt to negate with overflow'
// compile-flags: -C debug-assertions
#![allow(arithmetic_overflow)]
fn main() {
let _x = -std::i8::MIN;
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:thread 'main' panicked at 'attempt to multiply with overflow'
// compile-flags: -C debug-assertions
fn main() {
let _x = 2i32.pow(1024);
}

View file

@ -0,0 +1,7 @@
// run-fail
// error-pattern:thread 'main' panicked at 'attempt to multiply with overflow'
// compile-flags: -C debug-assertions
fn main() {
let _x = 2u32.pow(1024);
}

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = -1_i32 >> 32;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-rsh-1.rs:7:14
|
LL | let _x = -1_i32 >> 32;
| ^^^^^^^^^^^^ attempt to shift right with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-rsh-1.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = -1_i32 >> -1;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-rsh-2.rs:7:14
|
LL | let _x = -1_i32 >> -1;
| ^^^^^^^^^^^^ attempt to shift right with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-rsh-2.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// build-fail
// compile-flags: -C debug-assertions
#![deny(arithmetic_overflow, const_err)]
fn main() {
let _x = -1_i64 >> 64;
//~^ ERROR: this arithmetic operation will overflow
}

View file

@ -0,0 +1,14 @@
error: this arithmetic operation will overflow
--> $DIR/overflowing-rsh-3.rs:7:14
|
LL | let _x = -1_i64 >> 64;
| ^^^^^^^^^^^^ attempt to shift right with overflow
|
note: the lint level is defined here
--> $DIR/overflowing-rsh-3.rs:4:9
|
LL | #![deny(arithmetic_overflow, const_err)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,24 @@
// build-fail
// compile-flags: -C debug-assertions
// This function is checking that our (type-based) automatic
// truncation does not sidestep the overflow checking.
#![deny(arithmetic_overflow, const_err)]
fn main() {
// this signals overflow when checking is on
let x = 2_i8 >> 17;
//~^ ERROR: this arithmetic operation will overflow
// ... but when checking is off, the fallback will truncate the
// input to its lower three bits (= 1). Note that this is *not*
// the behavior of the x86 processor for 8- and 16-bit types,
// but it is necessary to avoid undefined behavior from LLVM.
//
// We check that here, by ensuring the result is not zero; if
// overflow checking is turned off, then this assertion will pass
// (and the compiletest driver will report that the test did not
// produce the error expected above).
assert_eq!(x, 1_i8);
}

Some files were not shown because too many files have changed in this diff Show more