Skip to content

Commit 69dbe66

Browse files
committed
Auto merge of #43425 - matklad:lambda-restrictions, r=eddyb
Lambda expressions honor no struct literal restriction This is a fix for #43412 if we decide that it is indeed a bug :) closes #43412
2 parents 97b01ab + 7054fe3 commit 69dbe66

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/libsyntax/parse/parser.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3025,7 +3025,10 @@ impl<'a> Parser<'a> {
30253025
let decl = self.parse_fn_block_decl()?;
30263026
let decl_hi = self.prev_span;
30273027
let body = match decl.output {
3028-
FunctionRetTy::Default(_) => self.parse_expr()?,
3028+
FunctionRetTy::Default(_) => {
3029+
let restrictions = self.restrictions - RESTRICTION_STMT_EXPR;
3030+
self.parse_expr_res(restrictions, None)?
3031+
},
30293032
_ => {
30303033
// If an explicit return type is given, require a
30313034
// block to appear (RFC 968).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2017 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+
// compile-flags: -Z parse-only
12+
13+
struct Foo {
14+
x: isize,
15+
}
16+
17+
impl Foo {
18+
fn hi(&self) -> bool {
19+
true
20+
}
21+
}
22+
23+
fn main() {
24+
while || Foo {
25+
x: 3 //~ ERROR expected type, found `3`
26+
}.hi() { //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `{`
27+
println!("yo");
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 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+
12+
pub fn main() {
13+
// Test that lambdas behave as unary expressions with block-like expressions
14+
-if true { 1 } else { 2 } * 3;
15+
|| if true { 1 } else { 2 } * 3;
16+
17+
// The following is invalid and parses as `if true { 1 } else { 2 }; *3`
18+
// if true { 1 } else { 2 } * 3
19+
}

0 commit comments

Comments
 (0)