about summary refs log tree commit diff
path: root/src/test/parse-fail
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-01-15 06:38:26 +0000
committerbors <bors@rust-lang.org>2016-01-15 06:38:26 +0000
commita70a60a02bca4c1fb75a0eb0ecf80acb73972f66 (patch)
tree655f37b860f26b2869bd04ff41cb5132893312e5 /src/test/parse-fail
parentd8869d3487a569b4a6b86c1b585cc15db48abc4a (diff)
parentacc9428c6a99d199f35032ec7f794385e4c9fd24 (diff)
downloadrust-a70a60a02bca4c1fb75a0eb0ecf80acb73972f66.tar.gz
rust-a70a60a02bca4c1fb75a0eb0ecf80acb73972f66.zip
Auto merge of #30763 - gchp:issue/30033, r=nagisa
This is achieved by adding the scan_back method. This method looks back
through the source_text of the StringReader until it finds the target
char, returning it's offset in the source. We use this method to find
the offset of the opening single quote, and use that offset as the start
of the error.

Given this code:

```rust
fn main() {
    let _ = 'abcd';
}
```

The compiler would give a message like:

```
error: character literal may only contain one codepoint: ';
let _ = 'abcd';
             ^~
```
With this change, the message now displays:

```
error: character literal may only contain one codepoint: 'abcd';
let _ = 'abcd';
        ^~~~~~~
```

Fixes #30033
Diffstat (limited to 'src/test/parse-fail')
-rw-r--r--src/test/parse-fail/lex-bad-char-literals-1.rs (renamed from src/test/parse-fail/lex-bad-char-literals.rs)7
-rw-r--r--src/test/parse-fail/lex-bad-char-literals-2.rs17
-rw-r--r--src/test/parse-fail/lex-bad-char-literals-3.rs16
-rw-r--r--src/test/parse-fail/lex-bad-char-literals-4.rs16
-rw-r--r--src/test/parse-fail/lex-bad-char-literals-5.rs16
5 files changed, 66 insertions, 6 deletions
diff --git a/src/test/parse-fail/lex-bad-char-literals.rs b/src/test/parse-fail/lex-bad-char-literals-1.rs
index 6335632455f..7e22a11ca97 100644
--- a/src/test/parse-fail/lex-bad-char-literals.rs
+++ b/src/test/parse-fail/lex-bad-char-literals-1.rs
@@ -1,4 +1,4 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// 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.
 //
@@ -25,8 +25,3 @@ static s: &'static str =
     "\●" //~ ERROR: unknown character escape
 ;
 
-// THIS MUST BE LAST, since it kills the lexer
-
-static c: char =
-    '●  //~ ERROR: character literal may only contain one codepoint
-;
diff --git a/src/test/parse-fail/lex-bad-char-literals-2.rs b/src/test/parse-fail/lex-bad-char-literals-2.rs
new file mode 100644
index 00000000000..8bd6808c5ff
--- /dev/null
+++ b/src/test/parse-fail/lex-bad-char-literals-2.rs
@@ -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.
+
+// compile-flags: -Z parse-only
+
+// This test needs to the last one appearing in this file as it kills the parser
+static c: char =
+    'nope' //~ ERROR: character literal may only contain one codepoint: 'nope'
+;
+
diff --git a/src/test/parse-fail/lex-bad-char-literals-3.rs b/src/test/parse-fail/lex-bad-char-literals-3.rs
new file mode 100644
index 00000000000..92432dc8b63
--- /dev/null
+++ b/src/test/parse-fail/lex-bad-char-literals-3.rs
@@ -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.
+
+// compile-flags: -Z parse-only
+
+// This test needs to the last one appearing in this file as it kills the parser
+static c: char =
+    '●●' //~ ERROR: character literal may only contain one codepoint: '●
+;
diff --git a/src/test/parse-fail/lex-bad-char-literals-4.rs b/src/test/parse-fail/lex-bad-char-literals-4.rs
new file mode 100644
index 00000000000..b230e623603
--- /dev/null
+++ b/src/test/parse-fail/lex-bad-char-literals-4.rs
@@ -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.
+
+// compile-flags: -Z parse-only
+//
+// This test needs to the last one appearing in this file as it kills the parser
+static c: char =
+    '●  //~ ERROR: character literal may only contain one codepoint: '●
+;
diff --git a/src/test/parse-fail/lex-bad-char-literals-5.rs b/src/test/parse-fail/lex-bad-char-literals-5.rs
new file mode 100644
index 00000000000..5259175b186
--- /dev/null
+++ b/src/test/parse-fail/lex-bad-char-literals-5.rs
@@ -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.
+
+// compile-flags: -Z parse-only
+//
+// This test needs to the last one appearing in this file as it kills the parser
+static c: char =
+    '\x10\x10'  //~ ERROR: character literal may only contain one codepoint: '\x10
+;