Skip to content

Commit 0532f9b

Browse files
committed
---
yaml --- r: 155637 b: refs/heads/try2 c: 45fd7cd h: refs/heads/master i: 155635: 0de02dd v: v3
1 parent 5e44837 commit 0532f9b

37 files changed

+137
-622
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: 6ee3c2854fb315bba7b4a3ff9ec4e826bfda3b00
8+
refs/heads/try2: 45fd7cd3592d4cc400cbb3d47e869814de98220c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/tests.mk

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,12 @@ ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
261261
tidy:
262262
@$(call E, check: formatting)
263263
$(Q)find $(S)src -name '*.r[sc]' \
264-
-and -not -regex '^$(S)src/jemalloc.*' \
265-
-and -not -regex '^$(S)src/libuv.*' \
266-
-and -not -regex '^$(S)src/llvm.*' \
267-
-and -not -regex '^$(S)src/gyp.*' \
268-
-and -not -regex '^$(S)src/libbacktrace.*' \
269-
-print0 \
270-
| xargs -0 -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
264+
| grep '^$(S)src/jemalloc' -v \
265+
| grep '^$(S)src/libuv' -v \
266+
| grep '^$(S)src/llvm' -v \
267+
| grep '^$(S)src/gyp' -v \
268+
| grep '^$(S)src/libbacktrace' -v \
269+
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
271270
$(Q)find $(S)src/etc -name '*.py' \
272271
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
273272
$(Q)find $(S)src/doc -name '*.js' \

branches/try2/src/doc/guide-lifetimes.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,21 @@ copying.
305305
# Circle(Point, f64), // origin, radius
306306
# Rectangle(Point, Size) // upper-left, dimensions
307307
# }
308+
# static tau: f64 = 6.28;
308309
fn compute_area(shape: &Shape) -> f64 {
309310
match *shape {
310-
Circle(_, radius) => std::f64::consts::PI * radius * radius,
311+
Circle(_, radius) => 0.5 * tau * radius * radius,
311312
Rectangle(_, ref size) => size.w * size.h
312313
}
313314
}
314315
~~~
315316

316317
The first case matches against circles. Here, the pattern extracts the
317318
radius from the shape variant and the action uses it to compute the
318-
area of the circle.
319+
area of the circle. (Like any up-to-date engineer, we use the [tau
320+
circle constant][tau] and not that dreadfully outdated notion of pi).
321+
322+
[tau]: http://www.math.utah.edu/~palais/pi.html
319323

320324
The second match is more interesting. Here we match against a
321325
rectangle and extract its size: but rather than copy the `size`

branches/try2/src/doc/guide.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,14 @@ error: mismatched types: expected `int` but found `()` (expected int but found (
659659
```
660660

661661
We expected an integer, but we got `()`. `()` is pronounced 'unit', and is a
662-
special type in Rust's type system. In Rust, `()` is _not_ a valid value for a
663-
variable of type `int`. It's only a valid value for variables of the type `()`,
664-
which aren't very useful. Remember how we said statements don't return a value?
665-
Well, that's the purpose of unit in this case. The semicolon turns any
666-
expression into a statement by throwing away its value and returning unit
667-
instead.
662+
special type in Rust's type system. `()` is different than `null` in other
663+
languages, because `()` is distinct from other types. For example, in C, `null`
664+
is a valid value for a variable of type `int`. In Rust, `()` is _not_ a valid
665+
value for a variable of type `int`. It's only a valid value for variables of
666+
the type `()`, which aren't very useful. Remember how we said statements don't
667+
return a value? Well, that's the purpose of unit in this case. The semicolon
668+
turns any expression into a statement by throwing away its value and returning
669+
unit instead.
668670

669671
There's one more time in which you won't see a semicolon at the end of a line
670672
of Rust code. For that, we'll need our next concept: functions.
@@ -1678,11 +1680,11 @@ just `int`s.
16781680

16791681
Rust provides a method on these `IoResult<T>`s called `ok()`, which does the
16801682
same thing as our `match` statement, but assuming that we have a valid value.
1681-
We then call `expect()` on the result, which will terminate our program if we
1682-
don't have a valid value. In this case, if we can't get input, our program
1683-
doesn't work, so we're okay with that. In most cases, we would want to handle
1684-
the error case explicitly. `expect()` allows us to give an error message if
1685-
this crash happens.
1683+
If we don't, it will terminate our program. In this case, if we can't get
1684+
input, our program doesn't work, so we're okay with that. In most cases, we
1685+
would want to handle the error case explicitly. The result of `ok()` has a
1686+
method, `expect()`, which allows us to give an error message if this crash
1687+
happens.
16861688

16871689
We will cover the exact details of how all of this works later in the Guide.
16881690
For now, this gives you enough of a basic understanding to work with.
@@ -2028,7 +2030,7 @@ fn main() {
20282030
match cmp(input, secret_number) {
20292031
Less => println!("Too small!"),
20302032
Greater => println!("Too big!"),
2031-
Equal => println!("You win!"),
2033+
Equal => { println!("You win!"); },
20322034
}
20332035
}
20342036
@@ -2725,8 +2727,7 @@ mod hello {
27252727
}
27262728
```
27272729

2728-
Usage of the `pub` keyword is sometimes called 'exporting', because
2729-
we're making the function available for other modules. This will work:
2730+
This will work:
27302731

27312732
```{notrust,ignore}
27322733
$ cargo run
@@ -3290,7 +3291,8 @@ use super::times_four;
32903291

32913292
Because we've made a nested module, we can import functions from the parent
32923293
module by using `super`. Sub-modules are allowed to 'see' private functions in
3293-
the parent.
3294+
the parent. We sometimes call this usage of `use` a 're-export,' because we're
3295+
exporting the name again, somewhere else.
32943296

32953297
We've now covered the basics of testing. Rust's tools are primitive, but they
32963298
work well in the simple cases. There are some Rustaceans working on building

branches/try2/src/libcollections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ struct AbsEntries<T> {
4646
}
4747

4848
/// An iterator over a BTreeMap's entries.
49-
pub struct Entries<'a, K: 'a, V: 'a> {
49+
pub struct Entries<'a, K, V> {
5050
inner: AbsEntries<Traversal<'a, K, V>>
5151
}
5252

5353
/// A mutable iterator over a BTreeMap's entries.
54-
pub struct MutEntries<'a, K: 'a, V: 'a> {
54+
pub struct MutEntries<'a, K, V> {
5555
inner: AbsEntries<MutTraversal<'a, K, V>>
5656
}
5757

branches/try2/src/libcollections/vec.rs

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -791,16 +791,11 @@ impl<T> Vec<T> {
791791
#[inline]
792792
pub fn into_iter(self) -> MoveItems<T> {
793793
unsafe {
794+
let iter = mem::transmute(self.as_slice().iter());
794795
let ptr = self.ptr;
795796
let cap = self.cap;
796-
let begin = self.ptr as *const T;
797-
let end = if mem::size_of::<T>() == 0 {
798-
(ptr as uint + self.len()) as *const T
799-
} else {
800-
ptr.offset(self.len() as int) as *const T
801-
};
802797
mem::forget(self);
803-
MoveItems { allocation: ptr, cap: cap, ptr: begin, end: end }
798+
MoveItems { allocation: ptr, cap: cap, iter: iter }
804799
}
805800
}
806801

@@ -1724,8 +1719,7 @@ impl<T> MutableSeq<T> for Vec<T> {
17241719
pub struct MoveItems<T> {
17251720
allocation: *mut T, // the block of memory allocated for the vector
17261721
cap: uint, // the capacity of the vector
1727-
ptr: *const T,
1728-
end: *const T
1722+
iter: Items<'static, T>
17291723
}
17301724

17311725
impl<T> MoveItems<T> {
@@ -1734,7 +1728,7 @@ impl<T> MoveItems<T> {
17341728
pub fn unwrap(mut self) -> Vec<T> {
17351729
unsafe {
17361730
for _x in self { }
1737-
let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
1731+
let MoveItems { allocation, cap, iter: _iter } = self;
17381732
mem::forget(self);
17391733
Vec { ptr: allocation, cap: cap, len: 0 }
17401734
}
@@ -1745,55 +1739,29 @@ impl<T> Iterator<T> for MoveItems<T> {
17451739
#[inline]
17461740
fn next<'a>(&'a mut self) -> Option<T> {
17471741
unsafe {
1748-
if self.ptr == self.end {
1749-
None
1750-
} else {
1751-
if mem::size_of::<T>() == 0 {
1752-
// purposefully don't use 'ptr.offset' because for
1753-
// vectors with 0-size elements this would return the
1754-
// same pointer.
1755-
self.ptr = mem::transmute(self.ptr as uint + 1);
1756-
1757-
// Use a non-null pointer value
1758-
Some(ptr::read(mem::transmute(1u)))
1759-
} else {
1760-
let old = self.ptr;
1761-
self.ptr = self.ptr.offset(1);
1762-
1763-
Some(ptr::read(old))
1764-
}
1765-
}
1742+
// Unsafely transmute from Items<'static, T> to Items<'a,
1743+
// T> because otherwise the type checker requires that T
1744+
// be bounded by 'static.
1745+
let iter: &mut Items<'a, T> = mem::transmute(&mut self.iter);
1746+
iter.next().map(|x| ptr::read(x))
17661747
}
17671748
}
17681749

17691750
#[inline]
17701751
fn size_hint(&self) -> (uint, Option<uint>) {
1771-
let diff = (self.end as uint) - (self.ptr as uint);
1772-
let size = mem::size_of::<T>();
1773-
let exact = diff / (if size == 0 {1} else {size});
1774-
(exact, Some(exact))
1752+
self.iter.size_hint()
17751753
}
17761754
}
17771755

17781756
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
17791757
#[inline]
17801758
fn next_back<'a>(&'a mut self) -> Option<T> {
17811759
unsafe {
1782-
if self.end == self.ptr {
1783-
None
1784-
} else {
1785-
if mem::size_of::<T>() == 0 {
1786-
// See above for why 'ptr.offset' isn't used
1787-
self.end = mem::transmute(self.end as uint - 1);
1788-
1789-
// Use a non-null pointer value
1790-
Some(ptr::read(mem::transmute(1u)))
1791-
} else {
1792-
self.end = self.end.offset(-1);
1793-
1794-
Some(ptr::read(mem::transmute(self.end)))
1795-
}
1796-
}
1760+
// Unsafely transmute from Items<'static, T> to Items<'a,
1761+
// T> because otherwise the type checker requires that T
1762+
// be bounded by 'static.
1763+
let iter: &mut Items<'a, T> = mem::transmute(&mut self.iter);
1764+
iter.next_back().map(|x| ptr::read(x))
17971765
}
17981766
}
17991767
}
@@ -2505,36 +2473,6 @@ mod tests {
25052473
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
25062474
}
25072475

2508-
#[test]
2509-
fn test_move_items() {
2510-
let mut vec = vec!(1i, 2, 3);
2511-
let mut vec2 : Vec<int> = vec!();
2512-
for i in vec.into_iter() {
2513-
vec2.push(i);
2514-
}
2515-
assert!(vec2 == vec!(1i, 2, 3));
2516-
}
2517-
2518-
#[test]
2519-
fn test_move_items_reverse() {
2520-
let mut vec = vec!(1i, 2, 3);
2521-
let mut vec2 : Vec<int> = vec!();
2522-
for i in vec.into_iter().rev() {
2523-
vec2.push(i);
2524-
}
2525-
assert!(vec2 == vec!(3i, 2, 1));
2526-
}
2527-
2528-
#[test]
2529-
fn test_move_items_zero_sized() {
2530-
let mut vec = vec!((), (), ());
2531-
let mut vec2 : Vec<()> = vec!();
2532-
for i in vec.into_iter() {
2533-
vec2.push(i);
2534-
}
2535-
assert!(vec2 == vec!((), (), ()));
2536-
}
2537-
25382476
#[bench]
25392477
fn bench_new(b: &mut Bencher) {
25402478
b.iter(|| {

branches/try2/src/libcore/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ macro_rules! iterator {
12181218

12191219
/// Immutable slice iterator
12201220
#[experimental = "needs review"]
1221-
pub struct Items<'a, T: 'a> {
1221+
pub struct Items<'a, T> {
12221222
ptr: *const T,
12231223
end: *const T,
12241224
marker: marker::ContravariantLifetime<'a>
@@ -1261,7 +1261,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
12611261

12621262
/// Mutable slice iterator.
12631263
#[experimental = "needs review"]
1264-
pub struct MutItems<'a, T: 'a> {
1264+
pub struct MutItems<'a, T> {
12651265
ptr: *mut T,
12661266
end: *mut T,
12671267
marker: marker::ContravariantLifetime<'a>,

branches/try2/src/librustc/driver/driver.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,6 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
616616
return false;
617617
}
618618

619-
fn escape_dep_filename(filename: &str) -> String {
620-
// Apparently clang and gcc *only* escape spaces:
621-
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
622-
filename.replace(" ", "\\ ")
623-
}
624-
625619
fn write_out_deps(sess: &Session,
626620
input: &Input,
627621
outputs: &OutputFilenames,
@@ -665,7 +659,7 @@ fn write_out_deps(sess: &Session,
665659
// write Makefile-compatible dependency rules
666660
let files: Vec<String> = sess.codemap().files.borrow()
667661
.iter().filter(|fmap| fmap.is_real_file())
668-
.map(|fmap| escape_dep_filename(fmap.name.as_slice()))
662+
.map(|fmap| fmap.name.to_string())
669663
.collect();
670664
let mut file = try!(io::File::create(&deps_filename));
671665
for path in out_filenames.iter() {

branches/try2/src/librustc/driver/mod.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ use syntax::diagnostics;
2929

3030
use getopts;
3131

32+
3233
pub mod driver;
3334
pub mod session;
3435
pub mod config;
3536
pub mod pretty;
3637

37-
pub fn run(args: Vec<String>) -> int {
38-
monitor(proc() run_compiler(args.as_slice()));
38+
39+
pub fn main_args(args: &[String]) -> int {
40+
let owned_args = args.to_vec();
41+
monitor(proc() run_compiler(owned_args.as_slice()));
3942
0
4043
}
4144

@@ -125,21 +128,6 @@ fn run_compiler(args: &[String]) {
125128
driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
126129
}
127130

128-
/// Returns a version string such as "0.12.0-dev".
129-
pub fn release_str() -> Option<&'static str> {
130-
option_env!("CFG_RELEASE")
131-
}
132-
133-
/// Returns the full SHA1 hash of HEAD of the Git repo from which rustc was built.
134-
pub fn commit_hash_str() -> Option<&'static str> {
135-
option_env!("CFG_VER_HASH")
136-
}
137-
138-
/// Returns the "commit date" of HEAD of the Git repo from which rustc was built as a static string.
139-
pub fn commit_date_str() -> Option<&'static str> {
140-
option_env!("CFG_VER_DATE")
141-
}
142-
143131
/// Prints version information and returns None on success or an error
144132
/// message on failure.
145133
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
@@ -149,14 +137,13 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
149137
Some(s) => return Some(format!("Unrecognized argument: {}", s))
150138
};
151139

152-
println!("{} {}", binary, option_env!("CFG_VERSION").unwrap_or("unknown version"));
140+
println!("{} {}", binary, env!("CFG_VERSION"));
153141
if verbose {
154-
fn unw(x: Option<&str>) -> &str { x.unwrap_or("unknown") }
155142
println!("binary: {}", binary);
156-
println!("commit-hash: {}", unw(commit_hash_str()));
157-
println!("commit-date: {}", unw(commit_date_str()));
143+
println!("commit-hash: {}", option_env!("CFG_VER_HASH").unwrap_or("unknown"));
144+
println!("commit-date: {}", option_env!("CFG_VER_DATE").unwrap_or("unknown"));
158145
println!("host: {}", driver::host_triple());
159-
println!("release: {}", unw(release_str()));
146+
println!("release: {}", env!("CFG_RELEASE"));
160147
}
161148
None
162149
}

branches/try2/src/librustc/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,5 @@ mod rustc {
149149

150150
pub fn main() {
151151
let args = std::os::args();
152-
let result = driver::run(args);
153-
std::os::set_exit_status(result);
152+
std::os::set_exit_status(driver::main_args(args.as_slice()));
154153
}

0 commit comments

Comments
 (0)