Skip to content

Commit 71865fb

Browse files
Rollup merge of rust-lang#51099 - Crazycolorz5:expectedcloseparen, r=estebank
Fix Issue 38777 When looking through for a closing bracket in the loop condition, adds them to expecteds. rust-lang#38777
2 parents 91b6842 + df0c6a9 commit 71865fb

File tree

12 files changed

+61
-14
lines changed

12 files changed

+61
-14
lines changed

src/libsyntax/parse/parser.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'a> Parser<'a> {
652652
Err(err)
653653
}
654654
} else {
655-
self.expect_one_of(unsafe { slice::from_raw_parts(t, 1) }, &[])
655+
self.expect_one_of(slice::from_ref(t), &[])
656656
}
657657
}
658658

@@ -1108,7 +1108,12 @@ impl<'a> Parser<'a> {
11081108
{
11091109
let mut first: bool = true;
11101110
let mut v = vec![];
1111-
while !kets.contains(&&self.token) {
1111+
while !kets.iter().any(|k| {
1112+
match expect {
1113+
TokenExpectType::Expect => self.check(k),
1114+
TokenExpectType::NoExpect => self.token == **k,
1115+
}
1116+
}) {
11121117
match self.token {
11131118
token::CloseDelim(..) | token::Eof => break,
11141119
_ => {}

src/test/compile-fail/issue-39616.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
12-
//~| ERROR expected one of `->`, `where`, or `{`, found `]`
12+
//~| ERROR expected one of `)`, `,`, `->`, `where`, or `{`, found `]`
1313
// FIXME(jseyfried): avoid emitting the second error (preexisting)
1414

1515
fn main() {}

src/test/ui/resolve/token-error-correct-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ note: unclosed delimiter
1010
LL | callback(path.as_ref(); //~ ERROR expected one of
1111
| ^
1212

13-
error: expected one of `,`, `.`, `?`, or an operator, found `;`
13+
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
1414
--> $DIR/token-error-correct-3.rs:24:35
1515
|
1616
LL | callback(path.as_ref(); //~ ERROR expected one of
17-
| ^ expected one of `,`, `.`, `?`, or an operator here
17+
| ^ expected one of `)`, `,`, `.`, `?`, or an operator here
1818

1919
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
2020
--> $DIR/token-error-correct-3.rs:30:9

src/test/ui/similar-tokens.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ mod x {
1414
}
1515

1616
// `.` is similar to `,` so list parsing should continue to closing `}`
17-
use x::{A. B}; //~ ERROR expected one of `,`, `::`, or `as`, found `.`
17+
use x::{A. B}; //~ ERROR expected one of `,`, `::`, `as`, or `}`, found `.`
1818

1919
fn main() {}

src/test/ui/similar-tokens.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected one of `,`, `::`, or `as`, found `.`
1+
error: expected one of `,`, `::`, `as`, or `}`, found `.`
22
--> $DIR/similar-tokens.rs:17:10
33
|
4-
LL | use x::{A. B}; //~ ERROR expected one of `,`, `::`, or `as`, found `.`
5-
| ^ expected one of `,`, `::`, or `as` here
4+
LL | use x::{A. B}; //~ ERROR expected one of `,`, `::`, `as`, or `}`, found `.`
5+
| ^ expected one of `,`, `::`, `as`, or `}` here
66

77
error: aborting due to previous error
88

src/test/ui/token/issue-10636-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ note: unclosed delimiter
1010
LL | option.map(|some| 42;
1111
| ^
1212

13-
error: expected one of `,`, `.`, `?`, or an operator, found `;`
13+
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
1414
--> $DIR/issue-10636-2.rs:15:25
1515
|
1616
LL | option.map(|some| 42;
17-
| ^ expected one of `,`, `.`, `?`, or an operator here
17+
| ^ expected one of `)`, `,`, `.`, `?`, or an operator here
1818

1919
error: expected expression, found `)`
2020
--> $DIR/issue-10636-2.rs:18:1

src/test/compile-fail/privacy/restricted/tuple-struct-fields/test.rs renamed to src/test/ui/tuple-struct-fields/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ mod foo {
1212
type T = ();
1313
struct S1(pub(in foo) (), pub(T), pub(crate) (), pub(((), T)));
1414
struct S2(pub((foo)) ());
15-
//~^ ERROR expected `,`, found `(`
15+
//~^ ERROR expected one of `)` or `,`, found `(`
1616
//~| ERROR cannot find type `foo` in this scope
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: expected one of `)` or `,`, found `(`
2+
--> $DIR/test.rs:14:26
3+
|
4+
LL | struct S2(pub((foo)) ());
5+
| ^ expected one of `)` or `,` here
6+
7+
error[E0412]: cannot find type `foo` in this scope
8+
--> $DIR/test.rs:14:20
9+
|
10+
LL | struct S2(pub((foo)) ());
11+
| ^^^ not found in this scope
12+
13+
error[E0601]: `main` function not found in crate `test`
14+
|
15+
= note: consider adding a `main` function to `$DIR/test.rs`
16+
17+
error: aborting due to 3 previous errors
18+
19+
Some errors occurred: E0412, E0601.
20+
For more information about an error, try `rustc --explain E0412`.

src/test/compile-fail/privacy/restricted/tuple-struct-fields/test2.rs renamed to src/test/ui/tuple-struct-fields/test2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! define_struct {
1313
struct S1(pub $t);
1414
struct S2(pub (in foo) ());
1515
struct S3(pub $t ());
16-
//~^ ERROR expected `,`, found `(`
16+
//~^ ERROR expected one of `)` or `,`, found `(`
1717
}
1818
}
1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: expected one of `)` or `,`, found `(`
2+
--> $DIR/test2.rs:15:26
3+
|
4+
LL | struct S3(pub $t ());
5+
| ^ expected one of `)` or `,` here
6+
...
7+
LL | define_struct! { (foo) }
8+
| ------------------------ in this macro invocation
9+
10+
error: aborting due to previous error
11+

src/test/compile-fail/privacy/restricted/tuple-struct-fields/test3.rs renamed to src/test/ui/tuple-struct-fields/test3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! define_struct {
1313
struct S1(pub($t));
1414
struct S2(pub (in foo) ());
1515
struct S3(pub($t) ());
16-
//~^ ERROR expected `,`, found `(`
16+
//~^ ERROR expected one of `)` or `,`, found `(`
1717
}
1818
}
1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: expected one of `)` or `,`, found `(`
2+
--> $DIR/test3.rs:15:27
3+
|
4+
LL | struct S3(pub($t) ());
5+
| ^ expected one of `)` or `,` here
6+
...
7+
LL | define_struct! { foo }
8+
| ---------------------- in this macro invocation
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)