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

Add expected closing delimiter to diagnostic #51099

Merged
merged 5 commits into from
Jun 9, 2018
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
9 changes: 7 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ impl<'a> Parser<'a> {
Err(err)
}
} else {
self.expect_one_of(unsafe { slice::from_raw_parts(t, 1) }, &[])
self.expect_one_of(slice::from_ref(t), &[])
}
}

Expand Down Expand Up @@ -1107,7 +1107,12 @@ impl<'a> Parser<'a> {
{
let mut first: bool = true;
let mut v = vec![];
while !kets.contains(&&self.token) {
while !kets.iter().any(|k| {
match expect {
TokenExpectType::Expect => self.check(k),
TokenExpectType::NoExpect => self.token == **k,
}
}) {
match self.token {
token::CloseDelim(..) | token::Eof => break,
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-39616.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

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

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/resolve/token-error-correct-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ note: unclosed delimiter
LL | callback(path.as_ref(); //~ ERROR expected one of
| ^

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

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
--> $DIR/token-error-correct-3.rs:30:9
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/similar-tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ mod x {
}

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

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/similar-tokens.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `,`, `::`, or `as`, found `.`
error: expected one of `,`, `::`, `as`, or `}`, found `.`
--> $DIR/similar-tokens.rs:17:10
|
LL | use x::{A. B}; //~ ERROR expected one of `,`, `::`, or `as`, found `.`
| ^ expected one of `,`, `::`, or `as` here
LL | use x::{A. B}; //~ ERROR expected one of `,`, `::`, `as`, or `}`, found `.`
| ^ expected one of `,`, `::`, `as`, or `}` here

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/token/issue-10636-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ note: unclosed delimiter
LL | option.map(|some| 42;
| ^

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

error: expected expression, found `)`
--> $DIR/issue-10636-2.rs:18:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ mod foo {
type T = ();
struct S1(pub(in foo) (), pub(T), pub(crate) (), pub(((), T)));
struct S2(pub((foo)) ());
//~^ ERROR expected `,`, found `(`
//~^ ERROR expected one of `)` or `,`, found `(`
//~| ERROR cannot find type `foo` in this scope
}
20 changes: 20 additions & 0 deletions src/test/ui/tuple-struct-fields/test.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: expected one of `)` or `,`, found `(`
--> $DIR/test.rs:14:26
|
LL | struct S2(pub((foo)) ());
| ^ expected one of `)` or `,` here

error[E0412]: cannot find type `foo` in this scope
--> $DIR/test.rs:14:20
|
LL | struct S2(pub((foo)) ());
| ^^^ not found in this scope

error[E0601]: `main` function not found in crate `test`
|
= note: consider adding a `main` function to `$DIR/test.rs`

error: aborting due to 3 previous errors

Some errors occurred: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! define_struct {
struct S1(pub $t);
struct S2(pub (in foo) ());
struct S3(pub $t ());
//~^ ERROR expected `,`, found `(`
//~^ ERROR expected one of `)` or `,`, found `(`
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/tuple-struct-fields/test2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: expected one of `)` or `,`, found `(`
--> $DIR/test2.rs:15:26
|
LL | struct S3(pub $t ());
| ^ expected one of `)` or `,` here
...
LL | define_struct! { (foo) }
| ------------------------ in this macro invocation

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! define_struct {
struct S1(pub($t));
struct S2(pub (in foo) ());
struct S3(pub($t) ());
//~^ ERROR expected `,`, found `(`
//~^ ERROR expected one of `)` or `,`, found `(`
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/tuple-struct-fields/test3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: expected one of `)` or `,`, found `(`
--> $DIR/test3.rs:15:27
|
LL | struct S3(pub($t) ());
| ^ expected one of `)` or `,` here
...
LL | define_struct! { foo }
| ---------------------- in this macro invocation

error: aborting due to previous error