Skip to content

Commit e5bbbbe

Browse files
committed
Add some tests for closures that return !
1 parent b220db0 commit e5bbbbe

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/test/compile-fail/closure-that-fails.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ fn foo(f: || -> !) {}
1313
fn main() {
1414
// Type inference didn't use to be able to handle this:
1515
foo(|| fail!());
16+
foo(|| -> ! fail!());
1617
foo(|| 22); //~ ERROR mismatched types
18+
foo(|| -> ! 22); //~ ERROR mismatched types
19+
let x = || -> ! 1; //~ ERROR mismatched types
1720
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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+
#![deny(unreachable_code)]
12+
13+
fn main() {
14+
let x: || -> ! = || fail!();
15+
x();
16+
println!("Foo bar"); //~ ERROR: unreachable statement
17+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 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+
#![allow(dead_code)]
12+
13+
fn f(x: || -> !) -> ! {
14+
x();
15+
}
16+
17+
fn main() {
18+
let x: || -> ! = || fail!();
19+
let _y: || -> ! = || x();
20+
}

0 commit comments

Comments
 (0)