mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Tests
This commit is contained in:
parent
2731dc169c
commit
180d6b55ca
@ -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 => {
|
||||
|
@ -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.
|
||||
//
|
||||
@ -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
src/test/compile-fail/issue-31804.rs
Normal file
16
src/test/compile-fail/issue-31804.rs
Normal file
@ -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
src/test/compile-fail/token-error-correct-2.rs
Normal file
17
src/test/compile-fail/token-error-correct-2.rs
Normal file
@ -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
src/test/compile-fail/token-error-correct-3.rs
Normal file
33
src/test/compile-fail/token-error-correct-3.rs
Normal file
@ -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
src/test/compile-fail/token-error-correct.rs
Normal file
20
src/test/compile-fail/token-error-correct.rs
Normal file
@ -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: `}`
|
@ -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:
|
||||
|
@ -14,4 +14,4 @@ fn main() {
|
||||
foo! (
|
||||
bar, "baz", 1, 2.0
|
||||
} //~ ERROR incorrect close delimiter
|
||||
}
|
||||
} //~ ERROR unexpected close delimiter: `}`
|
||||
|
Loading…
Reference in New Issue
Block a user