Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Mar 24, 2016
1 parent 2731dc1 commit 180d6b5
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,12 @@ impl<'a> Parser<'a> {
maybe_whole!(deref self, NtTT);
match self.token {
token::CloseDelim(_) => {
panic!("should have been caught above");
// An unexpected closing delimiter (i.e., there is no
// matching opening delimiter).
let token_str = self.this_token_to_string();
let err = self.diagnostic().struct_span_err(self.span,
&format!("unexpected close delimiter: `{}`", token_str));
Err(err)
},
/* we ought to allow different depths of unquotation */
token::Dollar | token::SubstNt(..) if self.quote_depth > 0 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -11,11 +11,9 @@
// FIXME(31528) we emit a bunch of silly errors here due to continuing past the
// first one. This would be easy-ish to address by better recovery in tokenisation.

// compile-flags: -Z parse-only

pub fn trace_option(option: Option<isize>) { //~ HELP did you mean to close this delimiter?
pub fn trace_option(option: Option<isize>) {
option.map(|some| 42; //~ NOTE: unclosed delimiter
//~^ ERROR: expected one of
//~^^ ERROR: mismatched types
} //~ ERROR: incorrect close delimiter
//~^ ERROR: expected one of
//~ ERROR: this file contains an un-closed delimiter
16 changes: 16 additions & 0 deletions src/test/compile-fail/issue-31804.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that error recovery in the parser to an EOF does not give an infinite
// spew of errors.

fn main() {
let
} //~ ERROR unexpected token: `}`
17 changes: 17 additions & 0 deletions src/test/compile-fail/token-error-correct-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that we do some basic error correcton in the tokeniser (and don't ICE).

fn main() {
if foo { //~ NOTE: unclosed delimiter
//~^ ERROR: unresolved name `foo`
) //~ ERROR: incorrect close delimiter: `)`
}
33 changes: 33 additions & 0 deletions src/test/compile-fail/token-error-correct-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that we do some basic error correcton in the tokeniser (and don't spew
// too many bogus errors).

pub mod raw {
use std::{io, fs};
use std::path::Path;

pub fn ensure_dir_exists<P: AsRef<Path>, F: FnOnce(&Path)>(path: P,
callback: F)
-> io::Result<bool> {
if !is_directory(path.as_ref()) { //~ ERROR: unresolved name `is_directory`
callback(path.as_ref(); //~ NOTE: unclosed delimiter
//~^ ERROR: expected one of
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: expected one of
} else { //~ ERROR: incorrect close delimiter: `}`
Ok(false);
}

panic!();
}
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/compile-fail/token-error-correct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that we do some basic error correcton in the tokeniser.

fn main() {
foo(bar(; //~ NOTE: unclosed delimiter
//~^ NOTE: unclosed delimiter
//~^^ ERROR: unexpected token: `;`
//~^^^ ERROR: unresolved name `bar`
//~^^^^ ERROR: unresolved name `foo`
} //~ ERROR: incorrect close delimiter: `}`
//~^ ERROR: incorrect close delimiter: `}`
2 changes: 1 addition & 1 deletion src/test/parse-fail/issue-2354-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

// compile-flags: -Z parse-only

static foo: isize = 2; } //~ ERROR incorrect close delimiter:
static foo: isize = 2; } //~ ERROR unexpected close delimiter:
2 changes: 1 addition & 1 deletion src/test/parse-fail/macro-mismatched-delim-paren-brace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ fn main() {
foo! (
bar, "baz", 1, 2.0
} //~ ERROR incorrect close delimiter
}
} //~ ERROR unexpected close delimiter: `}`

0 comments on commit 180d6b5

Please sign in to comment.