Skip to content

Commit 9e2c9f1

Browse files
committed
---
yaml --- r: 96124 b: refs/heads/dist-snap c: e094350 h: refs/heads/master v: v3
1 parent 7c8193e commit 9e2c9f1

File tree

14 files changed

+218
-131
lines changed

14 files changed

+218
-131
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: c8e6a38693d73e06e59c69fbd40c3924836a10e9
9+
refs/heads/dist-snap: e0943504e4d4c42342cb7c0fa24895f991b01ca8
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/rust.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ common_escape : '\x5c'
254254
hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
255255
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
256256
| dec_digit ;
257+
oct_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' ;
257258
dec_digit : '0' | nonzero_dec ;
258259
nonzero_dec: '1' | '2' | '3' | '4'
259260
| '5' | '6' | '7' | '8' | '9' ;
@@ -318,8 +319,9 @@ r##"foo #"# bar"##; // foo #"# bar
318319
~~~~ {.ebnf .gram}
319320
320321
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
321-
| '0' [ [ dec_digit | '_' ] + num_suffix ?
322+
| '0' [ [ dec_digit | '_' ] * num_suffix ?
322323
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
324+
| 'o' [ oct_digit | '_' ] + int_suffix ?
323325
| 'x' [ hex_digit | '_' ] + int_suffix ? ] ;
324326
325327
num_suffix : int_suffix | float_suffix ;

branches/dist-snap/src/librustc/middle/lint.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -883,20 +883,23 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
883883

884884
fn check_unused_mut_pat(cx: &Context, p: @ast::Pat) {
885885
match p.node {
886-
ast::PatIdent(ast::BindByValue(ast::MutMutable), _, _) => {
887-
let mut used = false;
888-
let mut bindings = 0;
889-
do pat_util::pat_bindings(cx.tcx.def_map, p) |_, id, _, _| {
890-
used = used || cx.tcx.used_mut_nodes.contains(&id);
891-
bindings += 1;
892-
}
893-
if !used {
894-
let msg = if bindings == 1 {
895-
"variable does not need to be mutable"
896-
} else {
897-
"variables do not need to be mutable"
898-
};
899-
cx.span_lint(unused_mut, p.span, msg);
886+
ast::PatIdent(ast::BindByValue(ast::MutMutable),
887+
ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> {
888+
// `let mut _a = 1;` doesn't need a warning.
889+
let initial_underscore = match path.segments {
890+
[ast::PathSegment { identifier: id, _ }] => {
891+
cx.tcx.sess.str_of(id).starts_with("_")
892+
}
893+
_ => {
894+
cx.tcx.sess.span_bug(p.span,
895+
"mutable binding that doesn't \
896+
consist of exactly one segment");
897+
}
898+
};
899+
900+
if !initial_underscore && !cx.tcx.used_mut_nodes.contains(&p.id) {
901+
cx.span_lint(unused_mut, p.span,
902+
"variable does not need to be mutable");
900903
}
901904
}
902905
_ => ()

branches/dist-snap/src/librustc/middle/typeck/check/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,13 @@ pub fn compare_impl_method(tcx: ty::ctxt,
863863
if impl_m.fty.sig.inputs.len() != trait_m.fty.sig.inputs.len() {
864864
tcx.sess.span_err(
865865
impl_m_span,
866-
format!("method `{}` has {} parameter(s) \
867-
but the trait has {} parameter(s)",
868-
tcx.sess.str_of(trait_m.ident),
869-
impl_m.fty.sig.inputs.len(),
870-
trait_m.fty.sig.inputs.len()));
866+
format!("method `{}` has {} parameter{} \
867+
but the declaration in trait `{}` has {}",
868+
tcx.sess.str_of(trait_m.ident),
869+
impl_m.fty.sig.inputs.len(),
870+
if impl_m.fty.sig.inputs.len() == 1 { "" } else { "s" },
871+
ty::item_path_str(tcx, trait_m.def_id),
872+
trait_m.fty.sig.inputs.len()));
871873
return;
872874
}
873875

branches/dist-snap/src/librustpkg/api.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context {
8181

8282
pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
8383
lib: Path) {
84+
build_lib_with_cfgs(sysroot, root, name, version, lib, ~[])
85+
}
86+
87+
pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str,
88+
version: Version, lib: Path, cfgs: ~[~str]) {
8489
let cx = default_context(sysroot, root.clone());
8590
let pkg_src = PkgSrc {
8691
source_workspace: root.clone(),
@@ -94,11 +99,16 @@ pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
9499
tests: ~[],
95100
benchs: ~[]
96101
};
97-
pkg_src.build(&cx, ~[], []);
102+
pkg_src.build(&cx, cfgs, []);
98103
}
99104

100105
pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
101106
main: Path) {
107+
build_exe_with_cfgs(sysroot, root, name, version, main, ~[])
108+
}
109+
110+
pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str,
111+
version: Version, main: Path, cfgs: ~[~str]) {
102112
let cx = default_context(sysroot, root.clone());
103113
let pkg_src = PkgSrc {
104114
source_workspace: root.clone(),
@@ -113,7 +123,7 @@ pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
113123
benchs: ~[]
114124
};
115125

116-
pkg_src.build(&cx, ~[], []);
126+
pkg_src.build(&cx, cfgs, []);
117127
}
118128

119129
pub fn install_pkg(cx: &BuildContext,

branches/dist-snap/src/libstd/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mod tests {
207207

208208
#[test]
209209
fn type_id_hash() {
210-
let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>::());
210+
let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>());
211211

212212
assert_eq!(a.hash(), b.hash());
213213
}

branches/dist-snap/src/libstd/io/buffered.rs

Lines changed: 26 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ use prelude::*;
5555

5656
use num;
5757
use vec;
58-
use str;
59-
use super::{Reader, Writer, Stream, Decorator};
58+
use super::{Stream, Decorator};
6059

6160
// libuv recommends 64k buffers to maximize throughput
6261
// https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA
@@ -93,45 +92,10 @@ impl<R: Reader> BufferedReader<R> {
9392
pub fn new(inner: R) -> BufferedReader<R> {
9493
BufferedReader::with_capacity(DEFAULT_CAPACITY, inner)
9594
}
95+
}
9696

97-
/// Reads the next line of input, interpreted as a sequence of utf-8
98-
/// encoded unicode codepoints. If a newline is encountered, then the
99-
/// newline is contained in the returned string.
100-
pub fn read_line(&mut self) -> Option<~str> {
101-
self.read_until('\n' as u8).map(str::from_utf8_owned)
102-
}
103-
104-
/// Reads a sequence of bytes leading up to a specified delimeter. Once the
105-
/// specified byte is encountered, reading ceases and the bytes up to and
106-
/// including the delimiter are returned.
107-
pub fn read_until(&mut self, byte: u8) -> Option<~[u8]> {
108-
let mut res = ~[];
109-
let mut used;
110-
loop {
111-
{
112-
let available = self.fill_buffer();
113-
match available.iter().position(|&b| b == byte) {
114-
Some(i) => {
115-
res.push_all(available.slice_to(i + 1));
116-
used = i + 1;
117-
break
118-
}
119-
None => {
120-
res.push_all(available);
121-
used = available.len();
122-
}
123-
}
124-
}
125-
if used == 0 {
126-
break
127-
}
128-
self.pos += used;
129-
}
130-
self.pos += used;
131-
return if res.len() == 0 {None} else {Some(res)};
132-
}
133-
134-
fn fill_buffer<'a>(&'a mut self) -> &'a [u8] {
97+
impl<R: Reader> Buffer for BufferedReader<R> {
98+
fn fill<'a>(&'a mut self) -> &'a [u8] {
13599
if self.pos == self.cap {
136100
match self.inner.read(self.buf) {
137101
Some(cap) => {
@@ -143,12 +107,17 @@ impl<R: Reader> BufferedReader<R> {
143107
}
144108
return self.buf.slice(self.pos, self.cap);
145109
}
110+
111+
fn consume(&mut self, amt: uint) {
112+
self.pos += amt;
113+
assert!(self.pos <= self.cap);
114+
}
146115
}
147116

148117
impl<R: Reader> Reader for BufferedReader<R> {
149118
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
150119
let nread = {
151-
let available = self.fill_buffer();
120+
let available = self.fill();
152121
if available.len() == 0 {
153122
return None;
154123
}
@@ -166,17 +135,9 @@ impl<R: Reader> Reader for BufferedReader<R> {
166135
}
167136

168137
impl<R: Reader> Decorator<R> for BufferedReader<R> {
169-
fn inner(self) -> R {
170-
self.inner
171-
}
172-
173-
fn inner_ref<'a>(&'a self) -> &'a R {
174-
&self.inner
175-
}
176-
177-
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut R {
178-
&mut self.inner
179-
}
138+
fn inner(self) -> R { self.inner }
139+
fn inner_ref<'a>(&'a self) -> &'a R { &self.inner }
140+
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut R { &mut self.inner }
180141
}
181142

182143
/// Wraps a Writer and buffers output to it
@@ -279,13 +240,8 @@ impl<W: Writer> Decorator<W> for LineBufferedWriter<W> {
279240
struct InternalBufferedWriter<W>(BufferedWriter<W>);
280241

281242
impl<W: Reader> Reader for InternalBufferedWriter<W> {
282-
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
283-
self.inner.read(buf)
284-
}
285-
286-
fn eof(&mut self) -> bool {
287-
self.inner.eof()
288-
}
243+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.inner.read(buf) }
244+
fn eof(&mut self) -> bool { self.inner.eof() }
289245
}
290246

291247
/// Wraps a Stream and buffers input and output to and from it
@@ -311,35 +267,24 @@ impl<S: Stream> BufferedStream<S> {
311267
}
312268
}
313269

314-
impl<S: Stream> Reader for BufferedStream<S> {
315-
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
316-
self.inner.read(buf)
317-
}
270+
impl<S: Stream> Buffer for BufferedStream<S> {
271+
fn fill<'a>(&'a mut self) -> &'a [u8] { self.inner.fill() }
272+
fn consume(&mut self, amt: uint) { self.inner.consume(amt) }
273+
}
318274

319-
fn eof(&mut self) -> bool {
320-
self.inner.eof()
321-
}
275+
impl<S: Stream> Reader for BufferedStream<S> {
276+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { self.inner.read(buf) }
277+
fn eof(&mut self) -> bool { self.inner.eof() }
322278
}
323279

324280
impl<S: Stream> Writer for BufferedStream<S> {
325-
fn write(&mut self, buf: &[u8]) {
326-
self.inner.inner.write(buf)
327-
}
328-
329-
fn flush(&mut self) {
330-
self.inner.inner.flush()
331-
}
281+
fn write(&mut self, buf: &[u8]) { self.inner.inner.write(buf) }
282+
fn flush(&mut self) { self.inner.inner.flush() }
332283
}
333284

334285
impl<S: Stream> Decorator<S> for BufferedStream<S> {
335-
fn inner(self) -> S {
336-
self.inner.inner.inner()
337-
}
338-
339-
fn inner_ref<'a>(&'a self) -> &'a S {
340-
self.inner.inner.inner_ref()
341-
}
342-
286+
fn inner(self) -> S { self.inner.inner.inner() }
287+
fn inner_ref<'a>(&'a self) -> &'a S { self.inner.inner.inner_ref() }
343288
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut S {
344289
self.inner.inner.inner_mut_ref()
345290
}

branches/dist-snap/src/libstd/io/mem.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,18 @@ impl Reader for MemReader {
123123

124124
impl Seek for MemReader {
125125
fn tell(&self) -> u64 { self.pos as u64 }
126-
127126
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
128127
}
129128

130-
impl Decorator<~[u8]> for MemReader {
131-
132-
fn inner(self) -> ~[u8] {
133-
match self {
134-
MemReader { buf: buf, _ } => buf
135-
}
136-
}
137-
138-
fn inner_ref<'a>(&'a self) -> &'a ~[u8] {
139-
match *self {
140-
MemReader { buf: ref buf, _ } => buf
141-
}
142-
}
129+
impl Buffer for MemReader {
130+
fn fill<'a>(&'a mut self) -> &'a [u8] { self.buf.slice_from(self.pos) }
131+
fn consume(&mut self, amt: uint) { self.pos += amt; }
132+
}
143133

144-
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut ~[u8] {
145-
match *self {
146-
MemReader { buf: ref mut buf, _ } => buf
147-
}
148-
}
134+
impl Decorator<~[u8]> for MemReader {
135+
fn inner(self) -> ~[u8] { self.buf }
136+
fn inner_ref<'a>(&'a self) -> &'a ~[u8] { &self.buf }
137+
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut ~[u8] { &mut self.buf }
149138
}
150139

151140

@@ -244,6 +233,11 @@ impl<'self> Seek for BufReader<'self> {
244233
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
245234
}
246235

236+
impl<'self> Buffer for BufReader<'self> {
237+
fn fill<'a>(&'a mut self) -> &'a [u8] { self.buf.slice_from(self.pos) }
238+
fn consume(&mut self, amt: uint) { self.pos += amt; }
239+
}
240+
247241
///Calls a function with a MemWriter and returns
248242
///the writer's stored vector.
249243
pub fn with_mem_writer(writeFn:&fn(&mut MemWriter)) -> ~[u8] {
@@ -394,4 +388,20 @@ mod test {
394388
let buf = with_mem_writer(|wr| wr.write([1,2,3,4,5,6,7]));
395389
assert_eq!(buf, ~[1,2,3,4,5,6,7]);
396390
}
391+
392+
#[test]
393+
fn test_read_char() {
394+
let mut r = BufReader::new(bytes!("Việt"));
395+
assert_eq!(r.read_char(), Some('V'));
396+
assert_eq!(r.read_char(), Some('i'));
397+
assert_eq!(r.read_char(), Some('ệ'));
398+
assert_eq!(r.read_char(), Some('t'));
399+
assert_eq!(r.read_char(), None);
400+
}
401+
402+
#[test]
403+
fn test_read_bad_char() {
404+
let mut r = BufReader::new(bytes!(0x80));
405+
assert_eq!(r.read_char(), None);
406+
}
397407
}

0 commit comments

Comments
 (0)