Skip to content

Commit 603f316

Browse files
huonwalexcrichton
authored andcommitted
---
yaml --- r: 149536 b: refs/heads/try2 c: 8812e8a h: refs/heads/master v: v3
1 parent 17cf438 commit 603f316

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ff79a4471cbf5fa4e78fcf56be129a3d56690127
8+
refs/heads/try2: 8812e8ad4957e3e201dabb62c6c3a8e0b10333a7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libsyntax/codemap.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,12 @@ impl CodeMap {
460460
for mbc in multibyte_chars.get().iter() {
461461
debug!("codemap: {:?}-byte char at {:?}", mbc.bytes, mbc.pos);
462462
if mbc.pos < bpos {
463-
total_extra_bytes += mbc.bytes;
463+
// every character is at least one byte, so we only
464+
// count the actual extra bytes.
465+
total_extra_bytes += mbc.bytes - 1;
464466
// We should never see a byte position in the middle of a
465467
// character
466-
assert!(bpos == mbc.pos ||
467-
bpos.to_uint() >= mbc.pos.to_uint() + mbc.bytes);
468+
assert!(bpos.to_uint() >= mbc.pos.to_uint() + mbc.bytes);
468469
} else {
469470
break;
470471
}

branches/try2/src/test/run-make/unicode-input/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ all:
44
# check that we don't ICE on unicode input, issue #11178
55
$(RUSTC) multiple_files.rs
66
$(call RUN,multiple_files) "$(RUSTC)" "$(TMPDIR)"
7+
8+
# check that our multibyte-ident spans are (approximately) the
9+
# correct length. issue #8706
10+
$(RUSTC) span_length.rs
11+
$(call RUN,span_length) "$(RUSTC)" "$(TMPDIR)"

branches/try2/src/test/run-make/unicode-input/multiple_files.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 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+
111
use std::{char, os, run, str};
212
use std::rand::{task_rng, Rng};
313
use std::io::File;
@@ -36,7 +46,8 @@ fn main() {
3646

3747
for _ in range(0, 100) {
3848
{
39-
let mut w = File::create(&tmpdir.join("unicode_input_multiple_files_chars.rs")).unwrap();
49+
let randoms = tmpdir.join("unicode_input_multiple_files_chars.rs");
50+
let mut w = File::create(&randoms).unwrap();
4051
for _ in range(0, 30) {
4152
let _ = w.write_char(random_char());
4253
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2014 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+
use std::{char, os, run, str};
12+
use std::rand::{task_rng, Rng};
13+
use std::io::File;
14+
15+
// creates a file with `fn main() { <random ident> }` and checks the
16+
// compiler emits a span of the appropriate length (for the
17+
// "unresolved name" message); currently just using the number of code
18+
// points, but should be the number of graphemes (FIXME #7043)
19+
20+
fn random_char() -> char {
21+
let mut rng = task_rng();
22+
// a subset of the XID_start unicode table (ensuring that the
23+
// compiler doesn't fail with an "unrecognised token" error)
24+
let (lo, hi): (u32, u32) = match rng.gen_range(1, 4 + 1) {
25+
1 => (0x41, 0x5a),
26+
2 => (0xf8, 0x1ba),
27+
3 => (0x1401, 0x166c),
28+
_ => (0x10400, 0x1044f)
29+
};
30+
31+
char::from_u32(rng.gen_range(lo, hi + 1)).unwrap()
32+
}
33+
34+
fn main() {
35+
let args = os::args();
36+
let rustc = args[1].as_slice();
37+
let tmpdir = Path::new(args[2].as_slice());
38+
39+
let main_file = tmpdir.join("span_main.rs");
40+
let main_file_str = main_file.as_str().unwrap();
41+
42+
for _ in range(0, 100) {
43+
let n = task_rng().gen_range(3u, 20);
44+
45+
{
46+
let _ = write!(&mut File::create(&main_file).unwrap(),
47+
r"\#[feature(non_ascii_idents)]; fn main() \{ {} \}",
48+
// random string of length n
49+
range(0, n).map(|_| random_char()).collect::<~str>());
50+
}
51+
52+
// rustc is passed to us with --out-dir and -L etc., so we
53+
// can't exec it directly
54+
let result = run::process_output("sh", [~"-c", rustc + " " + main_file_str]).unwrap();
55+
56+
let err = str::from_utf8_lossy(result.error);
57+
58+
// the span should end the line (e.g no extra ~'s)
59+
let expected_span = "^" + "~".repeat(n - 1) + "\n";
60+
assert!(err.as_slice().contains(expected_span));
61+
}
62+
}

0 commit comments

Comments
 (0)