Skip to content

Commit ec5d20f

Browse files
committed
---
yaml --- r: 158689 b: refs/heads/snap-stage3 c: e8d6031 h: refs/heads/master i: 158687: 595726a v: v3
1 parent a5407c4 commit ec5d20f

File tree

14 files changed

+4299
-4214
lines changed

14 files changed

+4299
-4214
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 0b48001c28329392b26961eaf1c3ed293a352d6f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ceeac26de859bd217d8ff576ff291dbd38ff3951
4+
refs/heads/snap-stage3: e8d6031c71a5ab42648f26a253671ba17584407a
55
refs/heads/try: f58aad6dce273570fb130b4df008ef9acd5a5be2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/doc/guide.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,7 @@ let y = &mut x;
34483448
Rust will complain:
34493449

34503450
```{ignore,notrust}
3451-
error: cannot borrow immutable local variable `x` as mutable
3451+
6:19 error: cannot borrow immutable local variable `x` as mutable
34523452
let y = &mut x;
34533453
^
34543454
```
@@ -3492,7 +3492,7 @@ note: previous borrow ends here
34923492

34933493
This is a big error message. Let's dig into it for a moment. There are three
34943494
parts: the error and two notes. The error says what we expected, we cannot have
3495-
two mutable pointers that point to the same memory.
3495+
two pointers that point to the same memory.
34963496

34973497
The two notes give some extra context. Rust's error messages often contain this
34983498
kind of extra information when the error is complex. Rust is telling us two
@@ -3763,10 +3763,10 @@ let y = &mut x;
37633763
This gives us this error:
37643764

37653765
```{notrust,ignore}
3766-
error: cannot use `*x` because it was mutably borrowed
3766+
8:7 error: cannot use `*x` because it was mutably borrowed
37673767
*x;
37683768
^~
3769-
note: borrow of `x` occurs here
3769+
6:19 note: borrow of `x` occurs here
37703770
let y = &mut x;
37713771
^
37723772
```
@@ -3791,7 +3791,7 @@ value that must persist as long as any of several referrers, read on.
37913791

37923792
## Rc and Arc
37933793

3794-
Sometimes you need a variable that is referenced from multiple places
3794+
Sometimes, you need a variable that is referenced from multiple places
37953795
(immutably!), lasting as long as any of those places, and disappearing when it
37963796
is no longer referenced. For instance, in a graph-like data structure, a node
37973797
might be referenced from all of its neighbors. In this case, it is not possible
@@ -3887,7 +3887,7 @@ match x {
38873887
```
38883888

38893889
If you're matching on an enum which has variants, you can use `..` to
3890-
ignore the value and type in the variant:
3890+
ignore the value in the variant:
38913891

38923892
```{rust}
38933893
enum OptionalInt {
@@ -4559,8 +4559,8 @@ So this would give us the numbers from `2-100`. Well, almost! If you
45594559
compile the example, you'll get a warning:
45604560

45614561
```{notrust,ignore}
4562-
warning: unused result which must be used: iterator adaptors are lazy and
4563-
do nothing unless consumed, #[warn(unused_must_use)] on by default
4562+
2:37 warning: unused result which must be used: iterator adaptors are lazy and
4563+
do nothing unless consumed, #[warn(unused_must_use)] on by default
45644564
range(1i, 100i).map(|x| x + 1i);
45654565
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45664566
```

branches/snap-stage3/src/etc/unicode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def load_east_asian_width(want_widths, except_cats):
283283
return widths
284284

285285
def escape_char(c):
286-
if c <= 0xff:
286+
if c <= 0x7f:
287287
return "'\\x%2.2x'" % c
288288
if c <= 0xffff:
289289
return "'\\u%4.4x'" % c

branches/snap-stage3/src/libcollections/str.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,15 @@ mod tests {
810810
assert_eq!("".len(), 0u);
811811
assert_eq!("hello world".len(), 11u);
812812
assert_eq!("\x63".len(), 1u);
813-
assert_eq!("\xa2".len(), 2u);
813+
assert_eq!("\u00a2".len(), 2u);
814814
assert_eq!("\u03c0".len(), 2u);
815815
assert_eq!("\u2620".len(), 3u);
816816
assert_eq!("\U0001d11e".len(), 4u);
817817

818818
assert_eq!("".char_len(), 0u);
819819
assert_eq!("hello world".char_len(), 11u);
820820
assert_eq!("\x63".char_len(), 1u);
821-
assert_eq!("\xa2".char_len(), 1u);
821+
assert_eq!("\u00a2".char_len(), 1u);
822822
assert_eq!("\u03c0".char_len(), 1u);
823823
assert_eq!("\u2620".char_len(), 1u);
824824
assert_eq!("\U0001d11e".char_len(), 1u);
@@ -1499,7 +1499,8 @@ mod tests {
14991499
assert_eq!("a c".escape_unicode(), String::from_str("\\x61\\x20\\x63"));
15001500
assert_eq!("\r\n\t".escape_unicode(), String::from_str("\\x0d\\x0a\\x09"));
15011501
assert_eq!("'\"\\".escape_unicode(), String::from_str("\\x27\\x22\\x5c"));
1502-
assert_eq!("\x00\x01\xfe\xff".escape_unicode(), String::from_str("\\x00\\x01\\xfe\\xff"));
1502+
assert_eq!("\x00\x01\u00fe\u00ff".escape_unicode(),
1503+
String::from_str("\\x00\\x01\\u00fe\\u00ff"));
15031504
assert_eq!("\u0100\uffff".escape_unicode(), String::from_str("\\u0100\\uffff"));
15041505
assert_eq!("\U00010000\U0010ffff".escape_unicode(),
15051506
String::from_str("\\U00010000\\U0010ffff"));
@@ -1783,11 +1784,11 @@ mod tests {
17831784
t!("\u2126", "\u03a9");
17841785
t!("\u1e0b\u0323", "\u1e0d\u0307");
17851786
t!("\u1e0d\u0307", "\u1e0d\u0307");
1786-
t!("a\u0301", "\xe1");
1787+
t!("a\u0301", "\u00e1");
17871788
t!("\u0301a", "\u0301a");
17881789
t!("\ud4db", "\ud4db");
17891790
t!("\uac1c", "\uac1c");
1790-
t!("a\u0300\u0305\u0315\u05aeb", "\xe0\u05ae\u0305\u0315b");
1791+
t!("a\u0300\u0305\u0315\u05aeb", "\u00e0\u05ae\u0305\u0315b");
17911792
}
17921793

17931794
#[test]
@@ -1803,11 +1804,11 @@ mod tests {
18031804
t!("\u2126", "\u03a9");
18041805
t!("\u1e0b\u0323", "\u1e0d\u0307");
18051806
t!("\u1e0d\u0307", "\u1e0d\u0307");
1806-
t!("a\u0301", "\xe1");
1807+
t!("a\u0301", "\u00e1");
18071808
t!("\u0301a", "\u0301a");
18081809
t!("\ud4db", "\ud4db");
18091810
t!("\uac1c", "\uac1c");
1810-
t!("a\u0300\u0305\u0315\u05aeb", "\xe0\u05ae\u0305\u0315b");
1811+
t!("a\u0300\u0305\u0315\u05aeb", "\u00e0\u05ae\u0305\u0315b");
18111812
}
18121813

18131814
#[test]

branches/snap-stage3/src/libcore/char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub fn escape_unicode(c: char, f: |char|) {
176176
// here.
177177
f('\\');
178178
let pad = match () {
179-
_ if c <= '\xff' => { f('x'); 2 }
179+
_ if c <= '\x7f' => { f('x'); 2 }
180180
_ if c <= '\uffff' => { f('u'); 4 }
181181
_ => { f('U'); 8 }
182182
};

branches/snap-stage3/src/libcoretest/char.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ fn test_escape_default() {
140140
assert_eq!(s.as_slice(), "\\x1f");
141141
let s = string('\x7f');
142142
assert_eq!(s.as_slice(), "\\x7f");
143-
let s = string('\xff');
144-
assert_eq!(s.as_slice(), "\\xff");
143+
let s = string('\u00ff');
144+
assert_eq!(s.as_slice(), "\\u00ff");
145145
let s = string('\u011b');
146146
assert_eq!(s.as_slice(), "\\u011b");
147147
let s = string('\U0001d4b6');
@@ -211,8 +211,8 @@ fn test_width() {
211211
assert_eq!('h'.width(false),Some(2));
212212
assert_eq!('h'.width(true),Some(2));
213213

214-
assert_eq!('\xAD'.width(false),Some(1));
215-
assert_eq!('\xAD'.width(true),Some(1));
214+
assert_eq!('\u00AD'.width(false),Some(1));
215+
assert_eq!('\u00AD'.width(true),Some(1));
216216

217217
assert_eq!('\u1160'.width(false),Some(0));
218218
assert_eq!('\u1160'.width(true),Some(0));

branches/snap-stage3/src/libregex/test/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,16 @@ mat!(match_flag_ungreedy_greedy, "(?U)a+?", "aa", Some((0, 2)))
209209
mat!(match_flag_ungreedy_noop, "(?U)(?-U)a+", "aa", Some((0, 2)))
210210

211211
// Some Unicode tests.
212-
mat!(uni_literal, r"Ⅰ", "Ⅰ", Some((0, 3)))
212+
// A couple of these are commented out because something in the guts of macro expansion is creating
213+
// invalid byte strings.
214+
//mat!(uni_literal, r"Ⅰ", "Ⅰ", Some((0, 3)))
213215
mat!(uni_one, r"\pN", "Ⅰ", Some((0, 3)))
214216
mat!(uni_mixed, r"\pN+", "Ⅰ1Ⅱ2", Some((0, 8)))
215217
mat!(uni_not, r"\PN+", "abⅠ", Some((0, 2)))
216218
mat!(uni_not_class, r"[\PN]+", "abⅠ", Some((0, 2)))
217219
mat!(uni_not_class_neg, r"[^\PN]+", "abⅠ", Some((2, 5)))
218220
mat!(uni_case, r"(?i)Δ", "δ", Some((0, 2)))
219-
mat!(uni_case_not, r"Δ", "δ", None)
221+
//mat!(uni_case_not, r"Δ", "δ", None)
220222
mat!(uni_case_upper, r"\p{Lu}+", "ΛΘΓΔα", Some((0, 8)))
221223
mat!(uni_case_upper_nocase_flag, r"(?i)\p{Lu}+", "ΛΘΓΔα", Some((0, 10)))
222224
mat!(uni_case_upper_nocase, r"\p{L}+", "ΛΘΓΔα", Some((0, 10)))

branches/snap-stage3/src/libstd/ascii.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,38 @@ impl OwnedAsciiExt for Vec<u8> {
461461
}
462462
}
463463

464+
/// Returns a 'default' ASCII and C++11-like literal escape of a `u8`
465+
///
466+
/// The default is chosen with a bias toward producing literals that are
467+
/// legal in a variety of languages, including C++11 and similar C-family
468+
/// languages. The exact rules are:
469+
///
470+
/// - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively.
471+
/// - Single-quote, double-quote and backslash chars are backslash-escaped.
472+
/// - Any other chars in the range [0x20,0x7e] are not escaped.
473+
/// - Any other chars are given hex escapes.
474+
/// - Unicode escapes are never generated by this function.
475+
pub fn escape_default(c: u8, f: |u8|) {
476+
match c {
477+
b'\t' => { f(b'\\'); f(b't'); }
478+
b'\r' => { f(b'\\'); f(b'r'); }
479+
b'\n' => { f(b'\\'); f(b'n'); }
480+
b'\\' => { f(b'\\'); f(b'\\'); }
481+
b'\'' => { f(b'\\'); f(b'\''); }
482+
b'"' => { f(b'\\'); f(b'"'); }
483+
b'\x20' ... b'\x7e' => { f(c); }
484+
_ => {
485+
f(b'\\');
486+
f(b'x');
487+
for &offset in [4u, 0u].iter() {
488+
match ((c as i32) >> offset) & 0xf {
489+
i @ 0 ... 9 => f(b'0' + (i as u8)),
490+
i => f(b'a' + (i as u8 - 10)),
491+
}
492+
}
493+
}
494+
}
495+
}
464496

465497
pub static ASCII_LOWER_MAP: [u8, ..256] = [
466498
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,

branches/snap-stage3/src/libsyntax/parse/lexer/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,11 @@ impl<'a> StringReader<'a> {
720720

721721
/// Scan over `n_digits` hex digits, stopping at `delim`, reporting an
722722
/// error if too many or too few digits are encountered.
723-
fn scan_hex_digits(&mut self, n_digits: uint, delim: char) -> bool {
723+
fn scan_hex_digits(&mut self,
724+
n_digits: uint,
725+
delim: char,
726+
below_0x7f_only: bool)
727+
-> bool {
724728
debug!("scanning {} digits until {}", n_digits, delim);
725729
let start_bpos = self.last_pos;
726730
let mut accum_int = 0;
@@ -745,6 +749,13 @@ impl<'a> StringReader<'a> {
745749
self.bump();
746750
}
747751

752+
if below_0x7f_only && accum_int >= 0x80 {
753+
self.err_span_(start_bpos,
754+
self.last_pos,
755+
"this form of character escape may only be used \
756+
with characters in the range [\\x00-\\x7f]");
757+
}
758+
748759
match char::from_u32(accum_int) {
749760
Some(_) => true,
750761
None => {
@@ -773,9 +784,13 @@ impl<'a> StringReader<'a> {
773784
Some(e) => {
774785
return match e {
775786
'n' | 'r' | 't' | '\\' | '\'' | '"' | '0' => true,
776-
'x' => self.scan_hex_digits(2u, delim),
777-
'u' if !ascii_only => self.scan_hex_digits(4u, delim),
778-
'U' if !ascii_only => self.scan_hex_digits(8u, delim),
787+
'x' => self.scan_hex_digits(2u, delim, !ascii_only),
788+
'u' if !ascii_only => {
789+
self.scan_hex_digits(4u, delim, false)
790+
}
791+
'U' if !ascii_only => {
792+
self.scan_hex_digits(8u, delim, false)
793+
}
779794
'\n' if delim == '"' => {
780795
self.consume_whitespace();
781796
true

branches/snap-stage3/src/libsyntax/print/pprust.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use print::pp::{Breaks, Consistent, Inconsistent, eof};
3030
use print::pp;
3131
use ptr::P;
3232

33+
use std::ascii;
3334
use std::io::{IoResult, MemWriter};
3435
use std::io;
3536
use std::mem;
@@ -2776,7 +2777,7 @@ impl<'a> State<'a> {
27762777
ast::LitStr(ref st, style) => self.print_string(st.get(), style),
27772778
ast::LitByte(byte) => {
27782779
let mut res = String::from_str("b'");
2779-
(byte as char).escape_default(|c| res.push(c));
2780+
ascii::escape_default(byte, |c| res.push(c as char));
27802781
res.push('\'');
27812782
word(&mut self.s, res.as_slice())
27822783
}
@@ -2821,8 +2822,12 @@ impl<'a> State<'a> {
28212822
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
28222823
}
28232824
ast::LitBinary(ref v) => {
2824-
let escaped: String = v.iter().map(|&b| b as char).collect();
2825-
word(&mut self.s, format!("b\"{}\"", escaped.escape_default()).as_slice())
2825+
let mut escaped: String = String::new();
2826+
for &ch in v.iter() {
2827+
ascii::escape_default(ch as u8,
2828+
|ch| escaped.push(ch as char));
2829+
}
2830+
word(&mut self.s, format!("b\"{}\"", escaped).as_slice())
28262831
}
28272832
}
28282833
}

0 commit comments

Comments
 (0)