Skip to content

Commit a0533cc

Browse files
committed
---
yaml --- r: 152065 b: refs/heads/try2 c: 911cc9c h: refs/heads/master i: 152063: 9eb3cca v: v3
1 parent 598406e commit a0533cc

File tree

19 files changed

+354
-73
lines changed

19 files changed

+354
-73
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: c256dcf8b66fb7100e2d735d6640cf76cb2d22f5
8+
refs/heads/try2: 911cc9c35234ab12a4b9a6fc1cb35b52556f242d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ let ys = xs;
11061106
11071107
xs = Nil;
11081108
1109-
// `xs` can be used again
1109+
// `xs` can't be used again
11101110
~~~
11111111

11121112
A destructor call will only occur for a variable that has not been moved from,

branches/try2/src/libcollections/hashmap.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,20 @@ mod test_map {
20032003
assert_eq!(m1, m2);
20042004
}
20052005

2006+
#[test]
2007+
fn test_show() {
2008+
let mut map: HashMap<int, int> = HashMap::new();
2009+
let empty: HashMap<int, int> = HashMap::new();
2010+
2011+
map.insert(1, 2);
2012+
map.insert(3, 4);
2013+
2014+
let map_str = format!("{}", map);
2015+
2016+
assert!(map_str == "{1: 2, 3: 4}".to_owned() || map_str == "{3: 4, 1: 2}".to_owned());
2017+
assert_eq!(format!("{}", empty), "{}".to_owned());
2018+
}
2019+
20062020
#[test]
20072021
fn test_expand() {
20082022
let mut m = HashMap::new();

branches/try2/src/libcollections/treemap.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
//! trees. The only requirement for the types is that the key implements
1313
//! `TotalOrd`.
1414
15-
use std::iter;
16-
use std::iter::{Peekable};
1715
use std::cmp::Ordering;
16+
use std::fmt::Show;
17+
use std::fmt;
18+
use std::iter::Peekable;
19+
use std::iter;
1820
use std::mem::{replace, swap};
1921
use std::ptr;
2022

@@ -67,6 +69,19 @@ impl<K: Ord + TotalOrd, V: Ord> Ord for TreeMap<K, V> {
6769
fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) }
6870
}
6971

72+
impl<K: TotalOrd + Show, V: Show> Show for TreeMap<K, V> {
73+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74+
try!(write!(f, r"\{"));
75+
76+
for (i, (k, v)) in self.iter().enumerate() {
77+
if i != 0 { try!(write!(f, ", ")); }
78+
try!(write!(f, "{}: {}", *k, *v));
79+
}
80+
81+
write!(f, r"\}")
82+
}
83+
}
84+
7085
impl<K: TotalOrd, V> Container for TreeMap<K, V> {
7186
fn len(&self) -> uint { self.length }
7287
}
@@ -547,6 +562,19 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> {
547562
fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map }
548563
}
549564

565+
impl<T: TotalOrd + Show> Show for TreeSet<T> {
566+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
567+
try!(write!(f, r"\{"));
568+
569+
for (i, x) in self.iter().enumerate() {
570+
if i != 0 { try!(write!(f, ", ")); }
571+
try!(write!(f, "{}", *x));
572+
}
573+
574+
write!(f, r"\}")
575+
}
576+
}
577+
550578
impl<T: TotalOrd> Container for TreeSet<T> {
551579
#[inline]
552580
fn len(&self) -> uint { self.map.len() }
@@ -1328,6 +1356,20 @@ mod test_treemap {
13281356
assert!(a < b && a <= b);
13291357
}
13301358

1359+
#[test]
1360+
fn test_show() {
1361+
let mut map: TreeMap<int, int> = TreeMap::new();
1362+
let empty: TreeMap<int, int> = TreeMap::new();
1363+
1364+
map.insert(1, 2);
1365+
map.insert(3, 4);
1366+
1367+
let map_str = format!("{}", map);
1368+
1369+
assert!(map_str == "{1: 2, 3: 4}".to_owned());
1370+
assert_eq!(format!("{}", empty), "{}".to_owned());
1371+
}
1372+
13311373
#[test]
13321374
fn test_lazy_iterator() {
13331375
let mut m = TreeMap::new();
@@ -1723,4 +1765,18 @@ mod test_set {
17231765
assert!(set.contains(x));
17241766
}
17251767
}
1768+
1769+
#[test]
1770+
fn test_show() {
1771+
let mut set: TreeSet<int> = TreeSet::new();
1772+
let empty: TreeSet<int> = TreeSet::new();
1773+
1774+
set.insert(1);
1775+
set.insert(2);
1776+
1777+
let set_str = format!("{}", set);
1778+
1779+
assert!(set_str == "{1, 2}".to_owned());
1780+
assert_eq!(format!("{}", empty), "{}".to_owned());
1781+
}
17261782
}

branches/try2/src/librustc/middle/check_match.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,18 @@ fn default(cx: &MatchCheckCtxt, r: &[@Pat]) -> Option<Vec<@Pat> > {
863863

864864
fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) {
865865
visit::walk_local(cx, loc, ());
866-
if is_refutable(cx, loc.pat) {
867-
cx.tcx.sess.span_err(loc.pat.span,
868-
"refutable pattern in local binding");
866+
867+
let name = match loc.source {
868+
LocalLet => "local",
869+
LocalFor => "`for` loop"
870+
};
871+
872+
let mut spans = vec![];
873+
find_refutable(cx, loc.pat, &mut spans);
874+
875+
for span in spans.iter() {
876+
cx.tcx.sess.span_err(*span,
877+
format!("refutable pattern in {} binding", name).as_slice());
869878
}
870879

871880
// Check legality of move bindings.
@@ -879,53 +888,65 @@ fn check_fn(cx: &mut MatchCheckCtxt,
879888
sp: Span) {
880889
visit::walk_fn(cx, kind, decl, body, sp, ());
881890
for input in decl.inputs.iter() {
882-
if is_refutable(cx, input.pat) {
883-
cx.tcx.sess.span_err(input.pat.span,
891+
let mut spans = vec![];
892+
find_refutable(cx, input.pat, &mut spans);
893+
894+
for span in spans.iter() {
895+
cx.tcx.sess.span_err(*span,
884896
"refutable pattern in function argument");
885897
}
886898
}
887899
}
888900

889-
fn is_refutable(cx: &MatchCheckCtxt, pat: &Pat) -> bool {
901+
fn find_refutable(cx: &MatchCheckCtxt, pat: &Pat, spans: &mut Vec<Span>) {
902+
macro_rules! this_pattern {
903+
() => {
904+
{
905+
spans.push(pat.span);
906+
return
907+
}
908+
}
909+
}
890910
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat.id);
891911
match opt_def {
892912
Some(DefVariant(enum_id, _, _)) => {
893913
if ty::enum_variants(cx.tcx, enum_id).len() != 1u {
894-
return true;
914+
this_pattern!()
895915
}
896916
}
897-
Some(DefStatic(..)) => return true,
917+
Some(DefStatic(..)) => this_pattern!(),
898918
_ => ()
899919
}
900920

901921
match pat.node {
902922
PatUniq(sub) | PatRegion(sub) | PatIdent(_, _, Some(sub)) => {
903-
is_refutable(cx, sub)
923+
find_refutable(cx, sub, spans)
904924
}
905-
PatWild | PatWildMulti | PatIdent(_, _, None) => { false }
925+
PatWild | PatWildMulti | PatIdent(_, _, None) => {}
906926
PatLit(lit) => {
907927
match lit.node {
908928
ExprLit(lit) => {
909929
match lit.node {
910-
LitNil => false, // `()`
911-
_ => true,
930+
LitNil => {} // `()`
931+
_ => this_pattern!(),
912932
}
913933
}
914-
_ => true,
934+
_ => this_pattern!(),
915935
}
916936
}
917-
PatRange(_, _) => { true }
937+
PatRange(_, _) => { this_pattern!() }
918938
PatStruct(_, ref fields, _) => {
919-
fields.iter().any(|f| is_refutable(cx, f.pat))
920-
}
921-
PatTup(ref elts) => {
922-
elts.iter().any(|elt| is_refutable(cx, *elt))
939+
for f in fields.iter() {
940+
find_refutable(cx, f.pat, spans);
941+
}
923942
}
924-
PatEnum(_, Some(ref args)) => {
925-
args.iter().any(|a| is_refutable(cx, *a))
943+
PatTup(ref elts) | PatEnum(_, Some(ref elts))=> {
944+
for elt in elts.iter() {
945+
find_refutable(cx, *elt, spans)
946+
}
926947
}
927-
PatEnum(_,_) => { false }
928-
PatVec(..) => { true }
948+
PatEnum(_,_) => {}
949+
PatVec(..) => { this_pattern!() }
929950
}
930951
}
931952

branches/try2/src/librustc/middle/privacy.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
297297
}
298298
}
299299

300+
ast::ItemTy(ref ty, _) if public_first => {
301+
match ty.node {
302+
ast::TyPath(_, _, id) => {
303+
match self.tcx.def_map.borrow().get_copy(&id) {
304+
ast::DefPrimTy(..) => {},
305+
def => {
306+
let did = def_id_of_def(def);
307+
if is_local(did) {
308+
self.exported_items.insert(did.node);
309+
}
310+
}
311+
}
312+
}
313+
_ => {}
314+
}
315+
}
316+
300317
_ => {}
301318
}
302319

branches/try2/src/libserialize/json.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,36 +1434,6 @@ impl<T: Iterator<char>> Parser<T> {
14341434
},
14351435
},
14361436
_ => return self.error(InvalidEscape),
1437-
/*=======
1438-
'u' => {
1439-
// Parse \u1234.
1440-
let mut i = 0u;
1441-
let mut n = 0u;
1442-
while i < 4u && !self.eof() {
1443-
self.bump();
1444-
n = match self.ch_or_null() {
1445-
c @ '0' .. '9' => n * 16u + (c as uint) - ('0' as uint),
1446-
'a' | 'A' => n * 16u + 10u,
1447-
'b' | 'B' => n * 16u + 11u,
1448-
'c' | 'C' => n * 16u + 12u,
1449-
'd' | 'D' => n * 16u + 13u,
1450-
'e' | 'E' => n * 16u + 14u,
1451-
'f' | 'F' => n * 16u + 15u,
1452-
_ => return self.error(UnrecognizedHex)
1453-
};
1454-
1455-
i += 1u;
1456-
}
1457-
1458-
// Error out if we didn't parse 4 digits.
1459-
if i != 4u {
1460-
return self.error(NotFourDigit);
1461-
}
1462-
1463-
res.push_char(char::from_u32(n as u32).unwrap());
1464-
}
1465-
_ => return self.error(InvalidEscape),
1466-
>>>>>>> Add a streaming parser to serialize::json.*/
14671437
}
14681438
escape = false;
14691439
} else if self.ch_is('\\') {

branches/try2/src/libstd/str.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ Unicode string manipulation (`str` type)
1616
1717
Rust's string type is one of the core primitive types of the language. While
1818
represented by the name `str`, the name `str` is not actually a valid type in
19-
Rust. Each string must also be decorated with its ownership. This means that
20-
there is one common kind of string in Rust:
19+
Rust. Each string must also be decorated with a pointer. `String` is used
20+
for an owned string, so there is only one commonly-used `str` type in Rust:
21+
`&str`.
2122
22-
* `&str` - This is the borrowed string type. This type of string can only be
23-
created from the other kind of string. As the name "borrowed"
24-
implies, this type of string is owned elsewhere, and this string
25-
cannot be moved out of.
23+
`&str` is the borrowed string type. This type of string can only be created
24+
from other strings, unless it is a static string (see below). As the word
25+
"borrowed" implies, this type of string is owned elsewhere, and this string
26+
cannot be moved out of.
2627
27-
As an example, here's the one kind of string.
28+
As an example, here's some code that uses a string.
2829
2930
```rust
3031
fn main() {
3132
let borrowed_string = "This string is borrowed with the 'static lifetime";
3233
}
3334
```
3435
35-
From the example above, you can see that Rust has 1 different kind of string
36-
literal. The "borrowed literal" is akin to C's concept of a static string.
36+
From the example above, you can see that Rust's string literals have the
37+
`'static` lifetime. This is akin to C's concept of a static string.
3738
3839
String literals are allocated statically in the rodata of the
3940
executable/library. The string then has the type `&'static str` meaning that
@@ -509,7 +510,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
509510
Section: MaybeOwned
510511
*/
511512

512-
/// A MaybeOwned is a string that can hold either a String or a &str.
513+
/// A `MaybeOwned` is a string that can hold either a `String` or a `&str`.
513514
/// This can be useful as an optimization when an allocation is sometimes
514515
/// needed but not always.
515516
pub enum MaybeOwned<'a> {
@@ -519,7 +520,7 @@ pub enum MaybeOwned<'a> {
519520
Owned(String)
520521
}
521522

522-
/// SendStr is a specialization of `MaybeOwned` to be sendable
523+
/// `SendStr` is a specialization of `MaybeOwned` to be sendable
523524
pub type SendStr = MaybeOwned<'static>;
524525

525526
impl<'a> MaybeOwned<'a> {

branches/try2/src/libsyntax/ast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ pub enum Stmt_ {
417417
StmtMac(Mac, bool),
418418
}
419419

420+
/// Where a local declaration came from: either a true `let ... =
421+
/// ...;`, or one desugared from the pattern of a for loop.
422+
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
423+
pub enum LocalSource {
424+
LocalLet,
425+
LocalFor,
426+
}
427+
420428
// FIXME (pending discussion of #1697, #2178...): local should really be
421429
// a refinement on pat.
422430
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -427,6 +435,7 @@ pub struct Local {
427435
pub init: Option<@Expr>,
428436
pub id: NodeId,
429437
pub span: Span,
438+
pub source: LocalSource,
430439
}
431440

432441
pub type Decl = Spanned<Decl_>;

branches/try2/src/libsyntax/ext/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
439439
init: Some(ex),
440440
id: ast::DUMMY_NODE_ID,
441441
span: sp,
442+
source: ast::LocalLet,
442443
};
443444
let decl = respan(sp, ast::DeclLocal(local));
444445
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))
@@ -462,6 +463,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
462463
init: Some(ex),
463464
id: ast::DUMMY_NODE_ID,
464465
span: sp,
466+
source: ast::LocalLet,
465467
};
466468
let decl = respan(sp, ast::DeclLocal(local));
467469
@respan(sp, ast::StmtDecl(@decl, ast::DUMMY_NODE_ID))

0 commit comments

Comments
 (0)