Skip to content

Commit

Permalink
auto merge of rust-lang#16836 : P1start/rust/closure_ret_bang, r=alex…
Browse files Browse the repository at this point in the history
…crichton

Fixes rust-lang#13490.
bors committed Sep 17, 2014
2 parents ad9ed40 + e5bbbbe commit 4d2af38
Showing 5 changed files with 54 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
@@ -4143,20 +4143,20 @@ impl<'a> Parser<'a> {
(optional_unboxed_closure_kind, args)
}
};
let output = if self.eat(&token::RARROW) {
self.parse_ty(true)
let (style, output) = if self.token == token::RARROW {
self.parse_ret_ty()
} else {
P(Ty {
(Return, P(Ty {
id: ast::DUMMY_NODE_ID,
node: TyInfer,
span: self.span,
})
}))
};

(P(FnDecl {
inputs: inputs_captures,
output: output,
cf: Return,
cf: style,
variadic: false
}), optional_unboxed_closure_kind)
}
@@ -4169,20 +4169,20 @@ impl<'a> Parser<'a> {
seq_sep_trailing_allowed(token::COMMA),
|p| p.parse_fn_block_arg());

let output = if self.eat(&token::RARROW) {
self.parse_ty(true)
let (style, output) = if self.token == token::RARROW {
self.parse_ret_ty()
} else {
P(Ty {
(Return, P(Ty {
id: ast::DUMMY_NODE_ID,
node: TyInfer,
span: self.span,
})
}))
};

P(FnDecl {
inputs: inputs,
output: output,
cf: Return,
cf: style,
variadic: false
})
}
3 changes: 3 additions & 0 deletions src/test/compile-fail/closure-that-fails.rs
Original file line number Diff line number Diff line change
@@ -13,5 +13,8 @@ fn foo(f: || -> !) {}
fn main() {
// Type inference didn't use to be able to handle this:
foo(|| fail!());
foo(|| -> ! fail!());
foo(|| 22); //~ ERROR mismatched types
foo(|| -> ! 22); //~ ERROR mismatched types
let x = || -> ! 1; //~ ERROR mismatched types
}
17 changes: 17 additions & 0 deletions src/test/compile-fail/dead-code-closure-bang.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions src/test/run-pass/closure-return-bang.rs
Original file line number Diff line number Diff line change
@@ -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();
}
4 changes: 4 additions & 0 deletions src/test/run-pass/closure-syntax.rs
Original file line number Diff line number Diff line change
@@ -78,6 +78,10 @@ fn bar<'b>() {

let a = A;
a.foo::<<'a>||>();

// issue #13490
let _ = || -> ! loop {};
let _ = proc() -> ! loop {};
}

struct B<T>;

0 comments on commit 4d2af38

Please sign in to comment.