Skip to content

Commit f56c8f6

Browse files
committed
Fix another case
1 parent 5b3b6b8 commit f56c8f6

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

src/libsyntax/parse/parser.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -7670,8 +7670,9 @@ impl<'a> Parser<'a> {
76707670
let ret = f(self);
76717671
let last_token = if self.token_cursor.stack.len() == prev {
76727672
&mut self.token_cursor.frame.last_token
7673-
} else if self.token_cursor.stack.is_empty() {//&& !self.unclosed_delims.is_empty() {
7674-
// This can happen with mismatched delimiters (#62881)
7673+
} else if self.token_cursor.stack.get(prev).is_none() {
7674+
// This can happen due to a bad interaction of two unrelated recovery mechanisms with
7675+
// mismatched delimiters *and* recovery lookahead on `pub ident(` likely typo (#62881)
76757676
return Ok((ret?, TokenStream::new(vec![])));
76767677
} else {
76777678
&mut self.token_cursor.stack[prev].last_token
@@ -7680,7 +7681,15 @@ impl<'a> Parser<'a> {
76807681
// Pull out the tokens that we've collected from the call to `f` above.
76817682
let mut collected_tokens = match *last_token {
76827683
LastToken::Collecting(ref mut v) => mem::take(v),
7683-
LastToken::Was(_) => panic!("our vector went away?"),
7684+
LastToken::Was(ref was) => {
7685+
let msg = format!("our vector went away? - found Was({:?})", was);
7686+
debug!("collect_tokens: {}", msg);
7687+
self.sess.span_diagnostic.delay_span_bug(self.token.span, &msg);
7688+
// This can happen due to a bad interaction of two unrelated recovery mechanisms
7689+
// with mismatched delimiters *and* recovery lookahead on `pub ident(` likely typo
7690+
// (#62895, different but similar to the case above)
7691+
return Ok((ret?, TokenStream::new(vec![])));
7692+
}
76847693
};
76857694

76867695
// If we're not at EOF our current token wasn't actually consumed by

src/test/ui/issues/issue-62895.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {}
2+
3+
fn v() -> isize { //~ ERROR mismatched types
4+
mod _ { //~ ERROR expected identifier
5+
pub fn g() -> isizee { //~ ERROR cannot find type `isizee` in this scope
6+
mod _ { //~ ERROR expected identifier
7+
pub g() -> is //~ ERROR missing `fn` for function definition
8+
(), w20);
9+
}
10+
(), w20); //~ ERROR expected item, found `;`
11+
}

src/test/ui/issues/issue-62895.stderr

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error: expected identifier, found reserved identifier `_`
2+
--> $DIR/issue-62895.rs:4:5
3+
|
4+
LL | mod _ {
5+
| ^ expected identifier, found reserved identifier
6+
7+
error: expected identifier, found reserved identifier `_`
8+
--> $DIR/issue-62895.rs:6:5
9+
|
10+
LL | mod _ {
11+
| ^ expected identifier, found reserved identifier
12+
13+
error: missing `fn` for function definition
14+
--> $DIR/issue-62895.rs:7:4
15+
|
16+
LL | pub g() -> is
17+
| ^^^^
18+
help: add `fn` here to parse `g` as a public function
19+
|
20+
LL | pub fn g() -> is
21+
| ^^
22+
23+
error: expected item, found `;`
24+
--> $DIR/issue-62895.rs:10:9
25+
|
26+
LL | (), w20);
27+
| ^ help: remove this semicolon
28+
29+
error[E0412]: cannot find type `isizee` in this scope
30+
--> $DIR/issue-62895.rs:5:15
31+
|
32+
LL | pub fn g() -> isizee {
33+
| ^^^^^^ help: a builtin type with a similar name exists: `isize`
34+
35+
error[E0308]: mismatched types
36+
--> $DIR/issue-62895.rs:3:11
37+
|
38+
LL | fn v() -> isize {
39+
| - ^^^^^ expected isize, found ()
40+
| |
41+
| this function's body doesn't return
42+
|
43+
= note: expected type `isize`
44+
found type `()`
45+
46+
error: aborting due to 6 previous errors
47+
48+
Some errors have detailed explanations: E0308, E0412.
49+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)