Skip to content

Commit 5010703

Browse files
committed
Add tests
1 parent cef6aee commit 5010703

12 files changed

+351
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:index out of bounds: the len is 5 but the index is 10
12+
#![feature(rustc_attrs)]
13+
14+
const C: [u32; 5] = [0; 5];
15+
16+
#[rustc_mir]
17+
fn test() -> u32 {
18+
C[10]
19+
}
20+
21+
fn main() {
22+
test();
23+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:index out of bounds: the len is 5 but the index is 10
12+
#![feature(rustc_attrs)]
13+
14+
const C: &'static [u8; 5] = b"hello";
15+
16+
#[rustc_mir]
17+
fn test() -> u8 {
18+
C[10]
19+
}
20+
21+
fn main() {
22+
test();
23+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:index out of bounds: the len is 5 but the index is 10
12+
#![feature(rustc_attrs)]
13+
14+
const C: &'static [u8; 5] = b"hello";
15+
16+
#[rustc_mir]
17+
fn mir() -> u8 {
18+
C[10]
19+
}
20+
21+
fn main() {
22+
mir();
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:converging_fn called
12+
// error-pattern:0 dropped
13+
// error-pattern:exit
14+
15+
use std::io::{self, Write};
16+
17+
struct Droppable(u8);
18+
impl Drop for Droppable {
19+
fn drop(&mut self) {
20+
write!(io::stderr(), "{} dropped\n", self.0);
21+
}
22+
}
23+
24+
fn converging_fn() {
25+
write!(io::stderr(), "converging_fn called\n");
26+
}
27+
28+
#[rustc_mir]
29+
fn mir(d: Droppable) {
30+
converging_fn();
31+
}
32+
33+
fn main() {
34+
let d = Droppable(0);
35+
mir(d);
36+
panic!("exit");
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:complex called
12+
// error-pattern:dropped
13+
// error-pattern:exit
14+
15+
use std::io::{self, Write};
16+
17+
struct Droppable;
18+
impl Drop for Droppable {
19+
fn drop(&mut self) {
20+
write!(io::stderr(), "dropped\n");
21+
}
22+
}
23+
24+
// return value of this function is copied into the return slot
25+
fn complex() -> u64 {
26+
write!(io::stderr(), "complex called\n");
27+
42
28+
}
29+
30+
31+
#[rustc_mir]
32+
fn mir() -> u64 {
33+
let x = Droppable;
34+
return complex();
35+
drop(x);
36+
}
37+
38+
pub fn main() {
39+
assert_eq!(mir(), 42);
40+
panic!("exit");
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:diverging_fn called
12+
13+
fn diverging_fn() -> ! {
14+
panic!("diverging_fn called")
15+
}
16+
17+
#[rustc_mir]
18+
fn mir() {
19+
diverging_fn();
20+
}
21+
22+
fn main() {
23+
mir();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:diverging_fn called
12+
// error-pattern:0 dropped
13+
use std::io::{self, Write};
14+
15+
struct Droppable(u8);
16+
impl Drop for Droppable {
17+
fn drop(&mut self) {
18+
write!(io::stderr(), "{} dropped", self.0);
19+
}
20+
}
21+
22+
fn diverging_fn() -> ! {
23+
panic!("diverging_fn called")
24+
}
25+
26+
#[rustc_mir]
27+
fn mir(d: Droppable) {
28+
diverging_fn();
29+
}
30+
31+
fn main() {
32+
let d = Droppable(0);
33+
mir(d);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// compile-flags: -Z no-landing-pads
12+
// error-pattern:converging_fn called
13+
use std::io::{self, Write};
14+
15+
struct Droppable;
16+
impl Drop for Droppable {
17+
fn drop(&mut self) {
18+
::std::process::exit(1)
19+
}
20+
}
21+
22+
fn converging_fn() {
23+
panic!("converging_fn called")
24+
}
25+
26+
#[rustc_mir]
27+
fn mir(d: Droppable) {
28+
let x = Droppable;
29+
converging_fn();
30+
drop(x);
31+
drop(d);
32+
}
33+
34+
fn main() {
35+
mir(Droppable);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// compile-flags: -Z no-landing-pads
12+
// error-pattern:diverging_fn called
13+
use std::io::{self, Write};
14+
15+
struct Droppable;
16+
impl Drop for Droppable {
17+
fn drop(&mut self) {
18+
::std::process::exit(1)
19+
}
20+
}
21+
22+
fn diverging_fn() -> ! {
23+
panic!("diverging_fn called")
24+
}
25+
26+
#[rustc_mir]
27+
fn mir(d: Droppable) {
28+
let x = Droppable;
29+
diverging_fn();
30+
drop(x);
31+
drop(d);
32+
}
33+
34+
fn main() {
35+
mir(Droppable);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
12+
fn converging_fn() -> u64 {
13+
43
14+
}
15+
16+
#[rustc_mir]
17+
fn mir() -> u64 {
18+
let x;
19+
loop {
20+
x = converging_fn();
21+
break;
22+
}
23+
x
24+
}
25+
26+
fn main() {
27+
assert_eq!(mir(), 43);
28+
}

src/test/run-pass/mir_void_return.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
13+
#[rustc_mir]
14+
fn mir() -> (){
15+
let x = 1;
16+
let mut y = 0;
17+
while y < x {
18+
y += 1
19+
}
20+
}
21+
22+
pub fn main() {
23+
mir();
24+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
13+
fn nil() {}
14+
15+
#[rustc_mir]
16+
fn mir(){
17+
nil()
18+
}
19+
20+
pub fn main() {
21+
mir();
22+
}

0 commit comments

Comments
 (0)