Skip to content

Commit c2cb238

Browse files
committed
test/compile-fail: clarify bad-for-loop
There are two distinct kinds of bad-for-loops to check for with two distinct error messages. The current bad-for-loop.rs does not make this clear, so rewrite it into bad-for-loop{,-2}.rs. The two failing prototypes are: fn quux(_: &fn(&int) -> int) -> bool { true } fn quux(_: &fn(&int) -> bool) -> () { } Note that the second one runs fine in rust-0.6 (the latest release), and only fails with a rust built from `incoming`. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
1 parent 7ce700a commit c2cb238

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
fn main() {
12+
fn quux(_: &fn(&int) -> bool) -> () { }
13+
for quux |_| { } //~ ERROR expected `for` closure to return
14+
// `bool`, but found `()`
15+
}

src/test/compile-fail/bad-for-loop.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
fn baz(_x: &fn(y: int) -> int) {}
13-
for baz |_e| { } //~ ERROR A `for` loop iterator should expect a closure that returns `bool`
14-
//~^ ERROR expected `for` closure to return `bool`
12+
fn quux(_: &fn(&int) -> int) -> bool { true }
13+
for quux |_| { } //~ ERROR A `for` loop iterator should expect a
14+
// closure that returns `bool`. This iterator
15+
// expects a closure that returns `int`.
1516
}

0 commit comments

Comments
 (0)