mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add some tests for closures that return !
This commit is contained in:
parent
b220db03bd
commit
e5bbbbe274
@ -13,5 +13,8 @@ fn foo(f: || -> !) {}
|
|||||||
fn main() {
|
fn main() {
|
||||||
// Type inference didn't use to be able to handle this:
|
// Type inference didn't use to be able to handle this:
|
||||||
foo(|| fail!());
|
foo(|| fail!());
|
||||||
|
foo(|| -> ! fail!());
|
||||||
foo(|| 22); //~ ERROR mismatched types
|
foo(|| 22); //~ ERROR mismatched types
|
||||||
|
foo(|| -> ! 22); //~ ERROR mismatched types
|
||||||
|
let x = || -> ! 1; //~ ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
17
src/test/compile-fail/dead-code-closure-bang.rs
Normal file
17
src/test/compile-fail/dead-code-closure-bang.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![deny(unreachable_code)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: || -> ! = || fail!();
|
||||||
|
x();
|
||||||
|
println!("Foo bar"); //~ ERROR: unreachable statement
|
||||||
|
}
|
20
src/test/run-pass/closure-return-bang.rs
Normal file
20
src/test/run-pass/closure-return-bang.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
fn f(x: || -> !) -> ! {
|
||||||
|
x();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: || -> ! = || fail!();
|
||||||
|
let _y: || -> ! = || x();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user