Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert invalid fn return type parsing change #78523

Merged
merged 2 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,19 +1666,10 @@ impl<'a> Parser<'a> {
req_name: ReqName,
ret_allow_plus: AllowPlus,
) -> PResult<'a, P<FnDecl>> {
let inputs = self.parse_fn_params(req_name)?;
let output = self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?;

if let ast::FnRetTy::Ty(ty) = &output {
if let TyKind::Path(_, Path { segments, .. }) = &ty.kind {
if let [.., last] = &segments[..] {
// Detect and recover `fn foo() -> Vec<i32>> {}`
self.check_trailing_angle_brackets(last, &[&token::OpenDelim(token::Brace)]);
}
}
}

Ok(P(FnDecl { inputs, output }))
Ok(P(FnDecl {
inputs: self.parse_fn_params(req_name)?,
output: self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?,
}))
}

/// Parses the parameter list of a function, including the `(` and `)` delimiters.
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/parser/fn-returns-fn-pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-pass
// Regression test for #78507.
fn foo() -> Option<fn() -> Option<bool>> {
Some(|| Some(true))
}
fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-24780.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Verify that '>' is not both expected and found at the same time, as it used
// to happen in #24780. For example, following should be an error:
// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
// expected one of ..., `>`, ... found `>`.

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-24780.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unmatched angle bracket
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
--> $DIR/issue-24780.rs:5:23
|
LL | fn foo() -> Vec<usize>> {
| ^^ help: remove extra angle bracket
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`

error: aborting due to previous error