Skip to content

Commit 3f474d0

Browse files
committed
---
yaml --- r: 137194 b: refs/heads/release-prep c: dc987ad h: refs/heads/master v: v3
1 parent 414a317 commit 3f474d0

File tree

9 files changed

+137
-39
lines changed

9 files changed

+137
-39
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2929
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
3030
refs/heads/libuv-update-temp-branch: 6ed22c618766f1f2a2e108eef8ce3f51be0f70b7
3131
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
32-
refs/heads/release-prep: 2bb7956a83fd55e6eed89199333676e7d2cbfc04
32+
refs/heads/release-prep: dc987adfc13f84c347005db18c46c0b45fce5d01

branches/release-prep/src/libcollections/str.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,11 @@ pub trait StrAllocating: Str {
778778
/// Returns the Levenshtein Distance between two strings.
779779
fn lev_distance(&self, t: &str) -> uint {
780780
let me = self.as_slice();
781-
let slen = me.len();
782-
let tlen = t.len();
781+
if me.is_empty() { return t.char_len(); }
782+
if t.is_empty() { return me.char_len(); }
783783

784-
if slen == 0 { return tlen; }
785-
if tlen == 0 { return slen; }
786-
787-
let mut dcol = Vec::from_fn(tlen + 1, |x| x);
784+
let mut dcol = Vec::from_fn(t.len() + 1, |x| x);
785+
let mut t_last = 0;
788786

789787
for (i, sc) in me.chars().enumerate() {
790788

@@ -799,15 +797,15 @@ pub trait StrAllocating: Str {
799797
*dcol.get_mut(j + 1) = current;
800798
} else {
801799
*dcol.get_mut(j + 1) = cmp::min(current, next);
802-
*dcol.get_mut(j + 1) = cmp::min(dcol[j + 1],
803-
dcol[j]) + 1;
800+
*dcol.get_mut(j + 1) = cmp::min(dcol[j + 1], dcol[j]) + 1;
804801
}
805802

806803
current = next;
804+
t_last = j;
807805
}
808806
}
809807

810-
return dcol[tlen];
808+
dcol[t_last + 1]
811809
}
812810

813811
/// Returns an iterator over the string in Unicode Normalization Form D
@@ -1878,6 +1876,27 @@ mod tests {
18781876
assert_eq!(words, vec!["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
18791877
}
18801878

1879+
#[test]
1880+
fn test_lev_distance() {
1881+
use std::char::{ from_u32, MAX };
1882+
// Test bytelength agnosticity
1883+
for c in range(0u32, MAX as u32)
1884+
.filter_map(|i| from_u32(i))
1885+
.map(|i| String::from_char(1, i)) {
1886+
assert_eq!(c[].lev_distance(c[]), 0);
1887+
}
1888+
1889+
let a = "\nMäry häd ä little lämb\n\nLittle lämb\n";
1890+
let b = "\nMary häd ä little lämb\n\nLittle lämb\n";
1891+
let c = "Mary häd ä little lämb\n\nLittle lämb\n";
1892+
assert_eq!(a.lev_distance(b), 1);
1893+
assert_eq!(b.lev_distance(a), 1);
1894+
assert_eq!(a.lev_distance(c), 2);
1895+
assert_eq!(c.lev_distance(a), 2);
1896+
assert_eq!(b.lev_distance(c), 1);
1897+
assert_eq!(c.lev_distance(b), 1);
1898+
}
1899+
18811900
#[test]
18821901
fn test_nfd_chars() {
18831902
macro_rules! t {

branches/release-prep/src/librustc/middle/resolve.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5852,11 +5852,8 @@ impl<'a> Resolver<'a> {
58525852
visit::walk_expr(self, expr);
58535853
}
58545854

5855-
ExprFnBlock(_, ref fn_decl, ref block) => {
5856-
// NOTE(stage0): After snapshot, change to:
5857-
//
5858-
//self.capture_mode_map.insert(expr.id, capture_clause);
5859-
self.capture_mode_map.insert(expr.id, ast::CaptureByRef);
5855+
ExprFnBlock(capture_clause, ref fn_decl, ref block) => {
5856+
self.capture_mode_map.insert(expr.id, capture_clause);
58605857
self.resolve_function(ClosureRibKind(expr.id, ast::DUMMY_NODE_ID),
58615858
Some(&**fn_decl), NoTypeParameters,
58625859
&**block);

branches/release-prep/src/librustc/middle/trans/reflect.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> {
127127
self.visit(name, []);
128128
}
129129

130+
fn visit_closure_ty(&mut self, fty: &ty::ClosureTy, is_unboxed: bool) {
131+
let pureval = ast_fn_style_constant(fty.fn_style);
132+
let sigilval = match fty.store {
133+
ty::UniqTraitStore => 2u,
134+
ty::RegionTraitStore(..) => 4u,
135+
};
136+
let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u};
137+
let extra = vec!(self.c_uint(pureval),
138+
self.c_uint(sigilval),
139+
self.c_uint(fty.sig.inputs.len()),
140+
self.c_uint(retval));
141+
self.visit("enter_fn", extra.as_slice());
142+
self.visit_sig(retval, &fty.sig, is_unboxed);
143+
self.visit("leave_fn", extra.as_slice());
144+
}
145+
130146
// Entrypoint
131147
pub fn visit_ty(&mut self, t: ty::t) {
132148
let bcx = self.bcx;
@@ -247,20 +263,8 @@ impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> {
247263

248264
// FIXME (#2594): fetch constants out of intrinsic
249265
// FIXME (#4809): visitor should break out bare fns from other fns
250-
ty::ty_closure(ref fty) => {
251-
let pureval = ast_fn_style_constant(fty.fn_style);
252-
let sigilval = match fty.store {
253-
ty::UniqTraitStore => 2u,
254-
ty::RegionTraitStore(..) => 4u,
255-
};
256-
let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u};
257-
let extra = vec!(self.c_uint(pureval),
258-
self.c_uint(sigilval),
259-
self.c_uint(fty.sig.inputs.len()),
260-
self.c_uint(retval));
261-
self.visit("enter_fn", extra.as_slice());
262-
self.visit_sig(retval, &fty.sig);
263-
self.visit("leave_fn", extra.as_slice());
266+
ty::ty_closure(box ref fty) => {
267+
self.visit_closure_ty(fty, false);
264268
}
265269

266270
// FIXME (#2594): fetch constants out of intrinsic:: for the
@@ -274,7 +278,7 @@ impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> {
274278
self.c_uint(fty.sig.inputs.len()),
275279
self.c_uint(retval));
276280
self.visit("enter_fn", extra.as_slice());
277-
self.visit_sig(retval, &fty.sig);
281+
self.visit_sig(retval, &fty.sig, false);
278282
self.visit("leave_fn", extra.as_slice());
279283
}
280284

@@ -388,16 +392,30 @@ impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> {
388392
// Miscellaneous extra types
389393
ty::ty_infer(_) => self.leaf("infer"),
390394
ty::ty_err => self.leaf("err"),
391-
ty::ty_unboxed_closure(..) => self.leaf("err"),
395+
ty::ty_unboxed_closure(ref def_id, _) => {
396+
let closure_map = tcx.unboxed_closures.borrow();
397+
let fty = &closure_map.find(def_id).unwrap().closure_type;
398+
self.visit_closure_ty(fty, true);
399+
}
392400
ty::ty_param(ref p) => {
393401
let extra = vec!(self.c_uint(p.idx));
394402
self.visit("param", extra.as_slice())
395403
}
396404
}
397405
}
398406

399-
pub fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) {
400-
for (i, arg) in sig.inputs.iter().enumerate() {
407+
pub fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig, is_unboxed: bool) {
408+
let args = if is_unboxed {
409+
match ty::get(sig.inputs[0]).sty {
410+
ty::ty_tup(ref contents) => contents.iter(),
411+
ty::ty_nil => [].iter(),
412+
_ => unreachable!()
413+
}
414+
} else {
415+
sig.inputs.iter()
416+
};
417+
418+
for (i, arg) in args.enumerate() {
401419
let modeval = 5u; // "by copy"
402420
let extra = vec!(self.c_uint(i),
403421
self.c_uint(modeval),

branches/release-prep/src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,19 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
869869
ast::TypeImplItem(_) => None,
870870
}
871871
},
872+
ast_map::NodeTraitItem(ref item) => {
873+
match **item {
874+
ast::ProvidedMethod(ref m) => {
875+
Some((m.pe_fn_decl(),
876+
m.pe_generics(),
877+
m.pe_fn_style(),
878+
m.pe_ident(),
879+
Some(&m.pe_explicit_self().node),
880+
m.span))
881+
}
882+
_ => None
883+
}
884+
}
872885
_ => None
873886
},
874887
None => None

branches/release-prep/src/libsyntax/codemap.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,8 @@ impl FileMap {
291291

292292
/// get a line from the list of pre-computed line-beginnings
293293
///
294-
/// NOTE(stage0, pcwalton): Remove `#[allow(unused_mut)]` after snapshot.
295-
#[allow(unused_mut)]
296294
pub fn get_line(&self, line: int) -> String {
297-
let mut lines = self.lines.borrow_mut();
295+
let lines = self.lines.borrow();
298296
let begin: BytePos = *lines.get(line as uint) - self.start_pos;
299297
let begin = begin.to_uint();
300298
let slice = self.src.as_slice().slice_from(begin);
@@ -515,16 +513,14 @@ impl CodeMap {
515513
return a;
516514
}
517515

518-
// NOTE(stage0, pcwalton): Remove `#[allow(unused_mut)]` after snapshot.
519-
#[allow(unused_mut)]
520516
fn lookup_line(&self, pos: BytePos) -> FileMapAndLine {
521517
let idx = self.lookup_filemap_idx(pos);
522518

523519
let files = self.files.borrow();
524520
let f = files.get(idx).clone();
525521
let mut a = 0u;
526522
{
527-
let mut lines = f.lines.borrow_mut();
523+
let lines = f.lines.borrow();
528524
let mut b = lines.len();
529525
while b - a > 1u {
530526
let m = (a + b) / 2u;

branches/release-prep/src/snapshots.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
S 2014-10-04 749ff5e
2+
freebsd-x86_64 f39d94487d29b3d48217b1295ad2cda8c941e694
3+
linux-i386 555aca74f9a268f80cab2df1147dc6406403e9e4
4+
linux-x86_64 6a43c2f6c8ba2cbbcb9da1f7b58f748aef99f431
5+
macos-i386 331bd7ef519cbb424188c546273e8c7d738f0894
6+
macos-x86_64 2c83a79a9febfe1d326acb17c3af76ba053c6ca9
7+
winnt-i386 fcf0526e5dc7ca4b149e074ff056ac03e2240ac7
8+
winnt-x86_64 611f19816fbfe0730b1fee51481b8d25dd78fa10
9+
110
S 2014-09-28 7eb9337
211
freebsd-x86_64 d45e0edd44f40a976ea0affaadd98732684cfca0
312
linux-i386 3acb35755aa62b7ff78f76007d9a70696fce7aa7
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// Test that regionck suggestions in a provided method of a trait
12+
// don't ICE
13+
14+
trait Foo<'a> {
15+
fn foo(&'a self);
16+
fn bar(&self) {
17+
self.foo();
18+
//~^ ERROR mismatched types: expected `&'a Self`, found `&Self` (lifetime mismatch)
19+
}
20+
}
21+
22+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
#![feature(unboxed_closures)]
12+
13+
// Test generating type visitor glue for unboxed closures
14+
15+
extern crate debug;
16+
17+
fn main() {
18+
let expected = "fn(); fn(uint, uint) -> uint; fn() -> !";
19+
let result = format!("{:?}; {:?}; {:?}",
20+
|:| {},
21+
|&: x: uint, y: uint| { x + y },
22+
|&mut:| -> ! { fail!() });
23+
assert_eq!(expected, result.as_slice());
24+
}

0 commit comments

Comments
 (0)