Skip to content

Commit d954246

Browse files
estebankpietroalbini
authored andcommitted
Do not panic on missing close paren
Fix rust-lang#58856.
1 parent 363024d commit d954246

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

src/libsyntax/parse/parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6321,8 +6321,10 @@ impl<'a> Parser<'a> {
63216321
&token::CloseDelim(token::Paren), sep, parse_arg_fn)?;
63226322
fn_inputs.append(&mut input);
63236323
(fn_inputs, recovered)
6324+
} else if let Err(err) = self.expect_one_of(&[], &[]) {
6325+
return Err(err);
63246326
} else {
6325-
return self.unexpected();
6327+
(vec![self_arg], true)
63266328
}
63276329
} else {
63286330
self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn)?

src/test/ui/issues/issue-58856-1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl A {
2+
//~^ ERROR cannot find type `A` in this scope
3+
fn b(self>
4+
//~^ ERROR expected one of `)`, `,`, or `:`, found `>`
5+
//~| ERROR expected one of `->`, `where`, or `{`, found `>`
6+
//~| ERROR expected one of `->`, `async`, `const`, `crate`, `default`, `existential`,
7+
}
8+
9+
fn main() {}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error: expected one of `)`, `,`, or `:`, found `>`
2+
--> $DIR/issue-58856-1.rs:3:14
3+
|
4+
LL | fn b(self>
5+
| - ^
6+
| | |
7+
| | help: `)` may belong here
8+
| unclosed delimiter
9+
10+
error: expected one of `->`, `where`, or `{`, found `>`
11+
--> $DIR/issue-58856-1.rs:3:14
12+
|
13+
LL | fn b(self>
14+
| ^ expected one of `->`, `where`, or `{` here
15+
16+
error: expected one of `->`, `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, `where`, or `}`, found `>`
17+
--> $DIR/issue-58856-1.rs:3:14
18+
|
19+
LL | fn b(self>
20+
| ^ expected one of 13 possible tokens here
21+
22+
error[E0412]: cannot find type `A` in this scope
23+
--> $DIR/issue-58856-1.rs:1:6
24+
|
25+
LL | impl A {
26+
| ^ not found in this scope
27+
28+
error: aborting due to 4 previous errors
29+
30+
For more information about this error, try `rustc --explain E0412`.

src/test/ui/issues/issue-58856-2.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Howness {}
2+
impl Howness for () {
3+
fn how_are_you(&self -> Empty {
4+
//~^ ERROR expected one of `)` or `,`, found `->`
5+
//~| ERROR method `how_are_you` is not a member of trait `Howness`
6+
//~| ERROR cannot find type `Empty` in this scope
7+
Empty
8+
//~^ ERROR cannot find value `Empty` in this scope
9+
}
10+
}
11+
//~^ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`,
12+
13+
fn main() {}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: expected one of `)` or `,`, found `->`
2+
--> $DIR/issue-58856-2.rs:3:26
3+
|
4+
LL | fn how_are_you(&self -> Empty {
5+
| - -^^
6+
| | |
7+
| | help: `)` may belong here
8+
| unclosed delimiter
9+
10+
error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)`
11+
--> $DIR/issue-58856-2.rs:10:1
12+
|
13+
LL | }
14+
| - expected one of 11 possible tokens here
15+
LL | }
16+
| ^ unexpected token
17+
18+
error[E0407]: method `how_are_you` is not a member of trait `Howness`
19+
--> $DIR/issue-58856-2.rs:3:5
20+
|
21+
LL | / fn how_are_you(&self -> Empty {
22+
LL | | //~^ ERROR expected one of `)` or `,`, found `->`
23+
LL | | //~| ERROR method `how_are_you` is not a member of trait `Howness`
24+
LL | | //~| ERROR cannot find type `Empty` in this scope
25+
LL | | Empty
26+
LL | | //~^ ERROR cannot find value `Empty` in this scope
27+
LL | | }
28+
| |_____^ not a member of trait `Howness`
29+
30+
error[E0412]: cannot find type `Empty` in this scope
31+
--> $DIR/issue-58856-2.rs:3:29
32+
|
33+
LL | fn how_are_you(&self -> Empty {
34+
| ^^^^^ not found in this scope
35+
help: possible candidates are found in other modules, you can import them into scope
36+
|
37+
LL | use std::io::Empty;
38+
|
39+
LL | use std::iter::Empty;
40+
|
41+
42+
error[E0425]: cannot find value `Empty` in this scope
43+
--> $DIR/issue-58856-2.rs:7:9
44+
|
45+
LL | Empty
46+
| ^^^^^ not found in this scope
47+
help: possible candidate is found in another module, you can import it into scope
48+
|
49+
LL | use std::sync::mpsc::TryRecvError::Empty;
50+
|
51+
52+
error: aborting due to 5 previous errors
53+
54+
Some errors occurred: E0407, E0412, E0425.
55+
For more information about an error, try `rustc --explain E0407`.

0 commit comments

Comments
 (0)