File tree 8 files changed +97
-8
lines changed
8 files changed +97
-8
lines changed Original file line number Diff line number Diff line change @@ -2841,7 +2841,12 @@ impl<'a> Parser<'a> {
2841
2841
maybe_whole ! ( deref self , NtTT ) ;
2842
2842
match self . token {
2843
2843
token:: CloseDelim ( _) => {
2844
- panic ! ( "should have been caught above" ) ;
2844
+ // An unexpected closing delimiter (i.e., there is no
2845
+ // matching opening delimiter).
2846
+ let token_str = self . this_token_to_string ( ) ;
2847
+ let err = self . diagnostic ( ) . struct_span_err ( self . span ,
2848
+ & format ! ( "unexpected close delimiter: `{}`" , token_str) ) ;
2849
+ Err ( err)
2845
2850
} ,
2846
2851
/* we ought to allow different depths of unquotation */
2847
2852
token:: Dollar | token:: SubstNt ( ..) if self . quote_depth > 0 => {
Original file line number Diff line number Diff line change 1
- // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2013-2016 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
11
11
// FIXME(31528) we emit a bunch of silly errors here due to continuing past the
12
12
// first one. This would be easy-ish to address by better recovery in tokenisation.
13
13
14
- // compile-flags: -Z parse-only
15
-
16
- pub fn trace_option ( option : Option < isize > ) { //~ HELP did you mean to close this delimiter?
14
+ pub fn trace_option ( option : Option < isize > ) {
17
15
option. map ( |some| 42 ; //~ NOTE: unclosed delimiter
18
16
//~^ ERROR: expected one of
17
+ //~^^ ERROR: mismatched types
19
18
} //~ ERROR: incorrect close delimiter
20
19
//~^ ERROR: expected one of
21
- //~ ERROR: this file contains an un-closed delimiter
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // Test that error recovery in the parser to an EOF does not give an infinite
12
+ // spew of errors.
13
+
14
+ fn main ( ) {
15
+ let
16
+ } //~ ERROR unexpected token: `}`
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // Test that we do some basic error correcton in the tokeniser (and don't ICE).
12
+
13
+ fn main( ) {
14
+ if foo { //~ NOTE: unclosed delimiter
15
+ //~^ ERROR: unresolved name `foo`
16
+ ) //~ ERROR: incorrect close delimiter: `)`
17
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // Test that we do some basic error correcton in the tokeniser (and don't spew
12
+ // too many bogus errors).
13
+
14
+ pub mod raw {
15
+ use std:: { io, fs} ;
16
+ use std:: path:: Path ;
17
+
18
+ pub fn ensure_dir_exists < P : AsRef < Path > , F : FnOnce ( & Path ) > ( path : P ,
19
+ callback : F )
20
+ -> io:: Result < bool > {
21
+ if !is_directory ( path. as_ref ( ) ) { //~ ERROR: unresolved name `is_directory`
22
+ callback ( path. as_ref ( ) ; //~ NOTE: unclosed delimiter
23
+ //~^ ERROR: expected one of
24
+ fs:: create_dir_all ( path. as_ref ( ) ) . map ( |( ) | true ) //~ ERROR: expected one of
25
+ } else { //~ ERROR: incorrect close delimiter: `}`
26
+ Ok ( false ) ;
27
+ }
28
+
29
+ panic ! ( ) ;
30
+ }
31
+ }
32
+
33
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // Test that we do some basic error correcton in the tokeniser.
12
+
13
+ fn main( ) {
14
+ foo( bar( ; //~ NOTE: unclosed delimiter
15
+ //~^ NOTE: unclosed delimiter
16
+ //~^^ ERROR: unexpected token: `;`
17
+ //~^^^ ERROR: unresolved name `bar`
18
+ //~^^^^ ERROR: unresolved name `foo`
19
+ } //~ ERROR: incorrect close delimiter: `}`
20
+ //~^ ERROR: incorrect close delimiter: `}`
Original file line number Diff line number Diff line change 10
10
11
11
// compile-flags: -Z parse-only
12
12
13
- static foo: isize = 2 ; } //~ ERROR incorrect close delimiter:
13
+ static foo: isize = 2 ; } //~ ERROR unexpected close delimiter:
Original file line number Diff line number Diff line change @@ -14,4 +14,4 @@ fn main() {
14
14
foo! (
15
15
bar, "baz" , 1 , 2.0
16
16
} //~ ERROR incorrect close delimiter
17
- }
17
+ } //~ ERROR unexpected close delimiter: `}`
You can’t perform that action at this time.
0 commit comments