Skip to content

Commit 00a71ea

Browse files
committed
Add tests for ! type
1 parent 2eff282 commit 00a71ea

10 files changed

+259
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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(never_type)]
12+
13+
fn foo(x: !) -> ! {
14+
x
15+
}
16+
17+
fn main() {
18+
foo("wow"); //~ ERROR mismatched types
19+
}
20+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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(never_type)]
12+
#![deny(unused, unreachable_code)]
13+
14+
fn main() {
15+
let x: ! = panic!("aah"); //~ ERROR unused
16+
drop(x); //~ ERROR unreachable
17+
}
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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(never_type)]
12+
13+
fn main() {
14+
let x: ! = "hello"; //~ ERROR mismatched types
15+
}
16+
17+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2012 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+
trait Foo {
12+
type Wub;
13+
}
14+
15+
type Ma = (u32, !, i32); //~ ERROR type is experimental
16+
type Meeshka = Vec<!>; //~ ERROR type is experimental
17+
type Mow = &fn(!) -> !; //~ ERROR type is experimental
18+
type Skwoz = &mut !; //~ ERROR type is experimental
19+
20+
impl Foo for Meeshka {
21+
type Wub = !; //~ ERROR type is experimental
22+
}
23+
24+
fn main() {
25+
}
26+
Lines changed: 37 additions & 0 deletions
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+
11+
#![feature(never_type)]
12+
13+
trait Balls: Sized {
14+
fn smeg() -> Result<Self, ()>;
15+
}
16+
17+
impl Balls for () {
18+
fn smeg() -> Result<(), ()> { Ok(()) }
19+
}
20+
21+
struct Flah;
22+
23+
impl Flah {
24+
fn flah<T: Balls>(&self) -> Result<T, ()> {
25+
T::smeg()
26+
}
27+
}
28+
29+
fn doit() -> Result<(), ()> {
30+
let _ = try!(Flah.flah()); //~ ERROR the trait bound
31+
Ok(())
32+
}
33+
34+
fn main() {
35+
let _ = doit();
36+
}
37+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2012 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:wowzers!
12+
13+
#![feature(never_type)]
14+
#![allow(unreachable_code)]
15+
16+
fn foo(x: !) -> ! {
17+
x
18+
}
19+
20+
fn main() {
21+
foo(panic!("wowzers!"))
22+
}
23+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2012 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(never_type)]
12+
13+
// error-pattern:kapow!
14+
15+
trait Foo {
16+
type Wow;
17+
18+
fn smeg(&self) -> Self::Wow;
19+
}
20+
21+
struct Blah;
22+
impl Foo for Blah {
23+
type Wow = !;
24+
fn smeg(&self) -> ! {
25+
panic!("kapow!");
26+
}
27+
}
28+
29+
fn main() {
30+
Blah.smeg();
31+
}
32+

src/test/run-fail/never-type-arg.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2012 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:oh no!
12+
13+
#![feature(never_type)]
14+
15+
struct Wub;
16+
17+
impl PartialEq<!> for Wub {
18+
fn eq(&self, other: &!) -> bool {
19+
*other
20+
}
21+
}
22+
23+
fn main() {
24+
let _ = Wub == panic!("oh no!");
25+
}
26+

src/test/run-pass/never-result.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(never_type)]
12+
13+
fn main() {
14+
let x: Result<u32, !> = Ok(123);
15+
match x {
16+
Ok(z) => (),
17+
Err(y) => {
18+
let q: u32 = y;
19+
let w: i32 = y;
20+
let e: String = y;
21+
y
22+
},
23+
}
24+
}
25+

src/test/run-pass/unit-fallback.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
trait Balls: Sized {
12+
fn smeg() -> Result<Self, ()>;
13+
}
14+
15+
impl Balls for () {
16+
fn smeg() -> Result<(), ()> { Ok(()) }
17+
}
18+
19+
struct Flah;
20+
21+
impl Flah {
22+
fn flah<T: Balls>(&self) -> Result<T, ()> {
23+
T::smeg()
24+
}
25+
}
26+
27+
fn doit() -> Result<(), ()> {
28+
let _ = try!(Flah.flah());
29+
Ok(())
30+
}
31+
32+
fn main() {
33+
let _ = doit();
34+
}
35+

0 commit comments

Comments
 (0)