Skip to content

Commit 8111706

Browse files
authored
Rollup merge of #78523 - estebank:fix-return-type-parse-regression, r=dtolnay
Revert invalid `fn` return type parsing change Revert one of the changes in #78379. Fix #78507.
2 parents 02a4b58 + 9ae7130 commit 8111706

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

compiler/rustc_parse/src/parser/item.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -1666,19 +1666,10 @@ impl<'a> Parser<'a> {
16661666
req_name: ReqName,
16671667
ret_allow_plus: AllowPlus,
16681668
) -> PResult<'a, P<FnDecl>> {
1669-
let inputs = self.parse_fn_params(req_name)?;
1670-
let output = self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?;
1671-
1672-
if let ast::FnRetTy::Ty(ty) = &output {
1673-
if let TyKind::Path(_, Path { segments, .. }) = &ty.kind {
1674-
if let [.., last] = &segments[..] {
1675-
// Detect and recover `fn foo() -> Vec<i32>> {}`
1676-
self.check_trailing_angle_brackets(last, &[&token::OpenDelim(token::Brace)]);
1677-
}
1678-
}
1679-
}
1680-
1681-
Ok(P(FnDecl { inputs, output }))
1669+
Ok(P(FnDecl {
1670+
inputs: self.parse_fn_params(req_name)?,
1671+
output: self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?,
1672+
}))
16821673
}
16831674

16841675
/// Parses the parameter list of a function, including the `(` and `)` delimiters.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-pass
2+
// Regression test for #78507.
3+
fn foo() -> Option<fn() -> Option<bool>> {
4+
Some(|| Some(true))
5+
}
6+
fn main() {}

src/test/ui/parser/issue-24780.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Verify that '>' is not both expected and found at the same time, as it used
22
// to happen in #24780. For example, following should be an error:
3-
// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
3+
// expected one of ..., `>`, ... found `>`.
44

5-
fn foo() -> Vec<usize>> { //~ ERROR unmatched angle bracket
5+
fn foo() -> Vec<usize>> { //~ ERROR expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
66
Vec::new()
77
}
88

src/test/ui/parser/issue-24780.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unmatched angle bracket
1+
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
22
--> $DIR/issue-24780.rs:5:23
33
|
44
LL | fn foo() -> Vec<usize>> {
5-
| ^^ help: remove extra angle bracket
5+
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)