Move tests from test/run-fail to UI
This commit is contained in:
parent
43271a39ad
commit
e69748ba4f
160 changed files with 404 additions and 125 deletions
10
src/test/ui/array-slice-vec/bounds-check-no-overflow.rs
Normal file
10
src/test/ui/array-slice-vec/bounds-check-no-overflow.rs
Normal 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];
|
||||
}
|
||||
11
src/test/ui/array-slice-vec/dst-raw-slice.rs
Normal file
11
src/test/ui/array-slice-vec/dst-raw-slice.rs
Normal 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];
|
||||
}
|
||||
}
|
||||
10
src/test/ui/binop/binop-fail-3.rs
Normal file
10
src/test/ui/binop/binop-fail-3.rs
Normal 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 ()
|
||||
}
|
||||
11
src/test/ui/binop/binop-panic.rs
Normal file
11
src/test/ui/binop/binop-panic.rs
Normal 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());
|
||||
}
|
||||
11
src/test/ui/borrowck/borrowck-local-borrow.rs
Normal file
11
src/test/ui/borrowck/borrowck-local-borrow.rs
Normal 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");
|
||||
}
|
||||
9
src/test/ui/closures/diverging-closure.rs
Normal file
9
src/test/ui/closures/diverging-closure.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// run-fail
|
||||
// error-pattern:oops
|
||||
|
||||
fn main() {
|
||||
let func = || -> ! {
|
||||
panic!("oops");
|
||||
};
|
||||
func();
|
||||
}
|
||||
8
src/test/ui/consts/promoted_div_by_zero.rs
Normal file
8
src/test/ui/consts/promoted_div_by_zero.rs
Normal 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));
|
||||
}
|
||||
10
src/test/ui/fn/expr-fn-panic.rs
Normal file
10
src/test/ui/fn/expr-fn-panic.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// run-fail
|
||||
// error-pattern:explicit panic
|
||||
|
||||
fn f() -> ! {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f();
|
||||
}
|
||||
23
src/test/ui/generator/generator-resume-after-panic.rs
Normal file
23
src/test/ui/generator/generator-resume-after-panic.rs
Normal 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(());
|
||||
}
|
||||
12
src/test/ui/hashmap/hashmap-capacity-overflow.rs
Normal file
12
src/test/ui/hashmap/hashmap-capacity-overflow.rs
Normal 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);
|
||||
}
|
||||
19
src/test/ui/if/expr-if-panic-fn.rs
Normal file
19
src/test/ui/if/expr-if-panic-fn.rs
Normal 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();
|
||||
}
|
||||
12
src/test/ui/if/expr-if-panic.rs
Normal file
12
src/test/ui/if/expr-if-panic.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// run-fail
|
||||
// error-pattern:explicit panic
|
||||
|
||||
fn main() {
|
||||
let _x = if false {
|
||||
0
|
||||
} else if true {
|
||||
panic!()
|
||||
} else {
|
||||
10
|
||||
};
|
||||
}
|
||||
24
src/test/ui/if/if-check-panic.rs
Normal file
24
src/test/ui/if/if-check-panic.rs
Normal 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);
|
||||
}
|
||||
12
src/test/ui/if/if-cond-bot.rs
Normal file
12
src/test/ui/if/if-cond-bot.rs
Normal 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()) {
|
||||
}
|
||||
}
|
||||
10
src/test/ui/imports/glob-use-std.rs
Normal file
10
src/test/ui/imports/glob-use-std.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Issue #7580
|
||||
|
||||
// run-fail
|
||||
// error-pattern:panic works
|
||||
|
||||
use std::*;
|
||||
|
||||
fn main() {
|
||||
panic!("panic works")
|
||||
}
|
||||
7
src/test/ui/issues/issue-12920.rs
Normal file
7
src/test/ui/issues/issue-12920.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// run-fail
|
||||
// error-pattern:explicit panic
|
||||
|
||||
pub fn main() {
|
||||
panic!();
|
||||
println!("{}", 1);
|
||||
}
|
||||
6
src/test/ui/issues/issue-13202.rs
Normal file
6
src/test/ui/issues/issue-13202.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:bad input
|
||||
|
||||
fn main() {
|
||||
Some("foo").unwrap_or(panic!("bad input")).to_string();
|
||||
}
|
||||
15
src/test/ui/issues/issue-18576.rs
Normal file
15
src/test/ui/issues/issue-18576.rs
Normal 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() {}
|
||||
22
src/test/ui/issues/issue-20971.rs
Normal file
22
src/test/ui/issues/issue-20971.rs
Normal 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(());
|
||||
}
|
||||
8
src/test/ui/issues/issue-23354-2.rs
Normal file
8
src/test/ui/issues/issue-23354-2.rs
Normal 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];
|
||||
}
|
||||
7
src/test/ui/issues/issue-23354.rs
Normal file
7
src/test/ui/issues/issue-23354.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// run-fail
|
||||
// error-pattern:panic evaluated
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn main() {
|
||||
let x = [panic!("panic evaluated"); 0];
|
||||
}
|
||||
16
src/test/ui/issues/issue-2444.rs
Normal file
16
src/test/ui/issues/issue-2444.rs
Normal 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();
|
||||
}
|
||||
26
src/test/ui/issues/issue-2470-bounds-check-overflow.rs
Normal file
26
src/test/ui/issues/issue-2470-bounds-check-overflow.rs
Normal 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]);
|
||||
}
|
||||
6
src/test/ui/issues/issue-2761.rs
Normal file
6
src/test/ui/issues/issue-2761.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:custom message
|
||||
|
||||
fn main() {
|
||||
assert!(false, "custom message");
|
||||
}
|
||||
24
src/test/ui/issues/issue-28934.rs
Normal file
24
src/test/ui/issues/issue-28934.rs
Normal 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();
|
||||
}
|
||||
10
src/test/ui/issues/issue-29798.rs
Normal file
10
src/test/ui/issues/issue-29798.rs
Normal 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);
|
||||
}
|
||||
13
src/test/ui/issues/issue-3029.rs
Normal file
13
src/test/ui/issues/issue-3029.rs
Normal 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());
|
||||
}
|
||||
35
src/test/ui/issues/issue-30380.rs
Normal file
35
src/test/ui/issues/issue-30380.rs
Normal 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);
|
||||
}
|
||||
9
src/test/ui/issues/issue-44216-add-instant.rs
Normal file
9
src/test/ui/issues/issue-44216-add-instant.rs
Normal 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());
|
||||
}
|
||||
9
src/test/ui/issues/issue-44216-add-system-time.rs
Normal file
9
src/test/ui/issues/issue-44216-add-system-time.rs
Normal 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());
|
||||
}
|
||||
9
src/test/ui/issues/issue-44216-sub-instant.rs
Normal file
9
src/test/ui/issues/issue-44216-sub-instant.rs
Normal 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());
|
||||
}
|
||||
9
src/test/ui/issues/issue-44216-sub-system-time.rs
Normal file
9
src/test/ui/issues/issue-44216-sub-system-time.rs
Normal 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());
|
||||
}
|
||||
7
src/test/ui/issues/issue-51345-2.rs
Normal file
7
src/test/ui/issues/issue-51345-2.rs
Normal 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!()));
|
||||
}
|
||||
7
src/test/ui/issues/issue-6458-1.rs
Normal file
7
src/test/ui/issues/issue-6458-1.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// run-fail
|
||||
// error-pattern:explicit panic
|
||||
|
||||
fn foo<T>(t: T) {}
|
||||
fn main() {
|
||||
foo(panic!())
|
||||
}
|
||||
25
src/test/ui/issues/issue-811.rs
Normal file
25
src/test/ui/issues/issue-811.rs
Normal 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");
|
||||
}
|
||||
14
src/test/ui/issues/issue-948.rs
Normal file
14
src/test/ui/issues/issue-948.rs
Normal 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 };
|
||||
}
|
||||
8
src/test/ui/loops/for-each-loop-panic.rs
Normal file
8
src/test/ui/loops/for-each-loop-panic.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// run-fail
|
||||
// error-pattern:moop
|
||||
|
||||
fn main() {
|
||||
for _ in 0_usize..10_usize {
|
||||
panic!("moop");
|
||||
}
|
||||
}
|
||||
6
src/test/ui/macros/assert-as-macro.rs
Normal file
6
src/test/ui/macros/assert-as-macro.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:assertion failed: 1 == 2
|
||||
|
||||
fn main() {
|
||||
assert!(1 == 2);
|
||||
}
|
||||
8
src/test/ui/macros/assert-eq-macro-panic.rs
Normal file
8
src/test/ui/macros/assert-eq-macro-panic.rs
Normal 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);
|
||||
}
|
||||
6
src/test/ui/macros/assert-macro-explicit.rs
Normal file
6
src/test/ui/macros/assert-macro-explicit.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:panicked at 'assertion failed: false'
|
||||
|
||||
fn main() {
|
||||
assert!(false);
|
||||
}
|
||||
6
src/test/ui/macros/assert-macro-fmt.rs
Normal file
6
src/test/ui/macros/assert-macro-fmt.rs
Normal 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");
|
||||
}
|
||||
6
src/test/ui/macros/assert-macro-owned.rs
Normal file
6
src/test/ui/macros/assert-macro-owned.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:panicked at 'test-assert-owned'
|
||||
|
||||
fn main() {
|
||||
assert!(false, "test-assert-owned".to_string());
|
||||
}
|
||||
6
src/test/ui/macros/assert-macro-static.rs
Normal file
6
src/test/ui/macros/assert-macro-static.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:panicked at 'test-assert-static'
|
||||
|
||||
fn main() {
|
||||
assert!(false, "test-assert-static");
|
||||
}
|
||||
8
src/test/ui/macros/assert-ne-macro-panic.rs
Normal file
8
src/test/ui/macros/assert-ne-macro-panic.rs
Normal 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);
|
||||
}
|
||||
6
src/test/ui/macros/die-macro-2.rs
Normal file
6
src/test/ui/macros/die-macro-2.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:test
|
||||
|
||||
fn main() {
|
||||
panic!("test");
|
||||
}
|
||||
6
src/test/ui/macros/die-macro-expr.rs
Normal file
6
src/test/ui/macros/die-macro-expr.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:test
|
||||
|
||||
fn main() {
|
||||
let __isize: isize = panic!("test");
|
||||
}
|
||||
10
src/test/ui/macros/die-macro-pure.rs
Normal file
10
src/test/ui/macros/die-macro-pure.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// run-fail
|
||||
// error-pattern:test
|
||||
|
||||
fn f() {
|
||||
panic!("test");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f();
|
||||
}
|
||||
6
src/test/ui/macros/unimplemented-macro-panic.rs
Normal file
6
src/test/ui/macros/unimplemented-macro-panic.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:not implemented
|
||||
|
||||
fn main() {
|
||||
unimplemented!()
|
||||
}
|
||||
6
src/test/ui/macros/unreachable-fmt-msg.rs
Normal file
6
src/test/ui/macros/unreachable-fmt-msg.rs
Normal 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");
|
||||
}
|
||||
6
src/test/ui/macros/unreachable-macro-panic.rs
Normal file
6
src/test/ui/macros/unreachable-macro-panic.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:internal error: entered unreachable code
|
||||
|
||||
fn main() {
|
||||
unreachable!()
|
||||
}
|
||||
6
src/test/ui/macros/unreachable-static-msg.rs
Normal file
6
src/test/ui/macros/unreachable-static-msg.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:internal error: entered unreachable code: uhoh
|
||||
|
||||
fn main() {
|
||||
unreachable!("uhoh")
|
||||
}
|
||||
6
src/test/ui/macros/unreachable.rs
Normal file
6
src/test/ui/macros/unreachable.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// run-fail
|
||||
// error-pattern:internal error: entered unreachable code
|
||||
|
||||
fn main() {
|
||||
unreachable!()
|
||||
}
|
||||
18
src/test/ui/match/expr-match-panic-fn.rs
Normal file
18
src/test/ui/match/expr-match-panic-fn.rs
Normal 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();
|
||||
}
|
||||
9
src/test/ui/match/expr-match-panic.rs
Normal file
9
src/test/ui/match/expr-match-panic.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// run-fail
|
||||
// error-pattern:explicit panic
|
||||
|
||||
fn main() {
|
||||
let _x = match true {
|
||||
false => 0,
|
||||
true => panic!(),
|
||||
};
|
||||
}
|
||||
15
src/test/ui/match/match-bot-panic.rs
Normal file
15
src/test/ui/match/match-bot-panic.rs
Normal 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);
|
||||
}
|
||||
15
src/test/ui/match/match-disc-bot.rs
Normal file
15
src/test/ui/match/match-disc-bot.rs
Normal 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();
|
||||
}
|
||||
20
src/test/ui/match/match-wildcards.rs
Normal file
20
src/test/ui/match/match-wildcards.rs
Normal 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());
|
||||
}
|
||||
21
src/test/ui/meta-revision-bad.rs
Normal file
21
src/test/ui/meta-revision-bad.rs
Normal 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();
|
||||
}
|
||||
20
src/test/ui/meta-revision-ok.rs
Normal file
20
src/test/ui/meta-revision-ok.rs
Normal 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();
|
||||
}
|
||||
25
src/test/ui/mir/mir_codegen_calls_converging_drops.rs
Normal file
25
src/test/ui/mir/mir_codegen_calls_converging_drops.rs
Normal 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");
|
||||
}
|
||||
29
src/test/ui/mir/mir_codegen_calls_converging_drops_2.rs
Normal file
29
src/test/ui/mir/mir_codegen_calls_converging_drops_2.rs
Normal 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");
|
||||
}
|
||||
14
src/test/ui/mir/mir_codegen_calls_diverging.rs
Normal file
14
src/test/ui/mir/mir_codegen_calls_diverging.rs
Normal 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();
|
||||
}
|
||||
23
src/test/ui/mir/mir_codegen_calls_diverging_drops.rs
Normal file
23
src/test/ui/mir/mir_codegen_calls_diverging_drops.rs
Normal 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);
|
||||
}
|
||||
23
src/test/ui/mir/mir_drop_panics.rs
Normal file
23
src/test/ui/mir/mir_drop_panics.rs
Normal 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();
|
||||
}
|
||||
31
src/test/ui/mir/mir_dynamic_drops_1.rs
Normal file
31
src/test/ui/mir/mir_dynamic_drops_1.rs
Normal 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!();
|
||||
}
|
||||
29
src/test/ui/mir/mir_dynamic_drops_2.rs
Normal file
29
src/test/ui/mir/mir_dynamic_drops_2.rs
Normal 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!();
|
||||
}
|
||||
34
src/test/ui/mir/mir_dynamic_drops_3.rs
Normal file
34
src/test/ui/mir/mir_dynamic_drops_3.rs
Normal 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));
|
||||
}
|
||||
13
src/test/ui/mir/mir_indexing_oob_1.rs
Normal file
13
src/test/ui/mir/mir_indexing_oob_1.rs
Normal 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();
|
||||
}
|
||||
13
src/test/ui/mir/mir_indexing_oob_2.rs
Normal file
13
src/test/ui/mir/mir_indexing_oob_2.rs
Normal 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();
|
||||
}
|
||||
13
src/test/ui/mir/mir_indexing_oob_3.rs
Normal file
13
src/test/ui/mir/mir_indexing_oob_3.rs
Normal 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();
|
||||
}
|
||||
17
src/test/ui/never_type/return-never-coerce.rs
Normal file
17
src/test/ui/never_type/return-never-coerce.rs
Normal 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();
|
||||
}
|
||||
7
src/test/ui/numbers-arithmetic/divide-by-zero.rs
Normal file
7
src/test/ui/numbers-arithmetic/divide-by-zero.rs
Normal 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;
|
||||
}
|
||||
7
src/test/ui/numbers-arithmetic/mod-zero.rs
Normal file
7
src/test/ui/numbers-arithmetic/mod-zero.rs
Normal 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;
|
||||
}
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-add.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-add.rs
Normal 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;
|
||||
}
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr
Normal 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
|
||||
|
||||
24
src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs
Normal file
24
src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs
Normal 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);
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-mul.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-mul.rs
Normal 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;
|
||||
}
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-neg.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-neg.rs
Normal 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;
|
||||
}
|
||||
7
src/test/ui/numbers-arithmetic/overflowing-pow-signed.rs
Normal file
7
src/test/ui/numbers-arithmetic/overflowing-pow-signed.rs
Normal 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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs
Normal file
9
src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs
Normal 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
|
||||
}
|
||||
14
src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr
Normal file
14
src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr
Normal 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
|
||||
|
||||
24
src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs
Normal file
24
src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs
Normal 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
Loading…
Add table
Add a link
Reference in a new issue