Skip to content

Commit 762ba03

Browse files
committed
---
yaml --- r: 155638 b: refs/heads/try2 c: d596aa2 h: refs/heads/master v: v3
1 parent 0532f9b commit 762ba03

36 files changed

+620
-137
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: 45fd7cd3592d4cc400cbb3d47e869814de98220c
8+
refs/heads/try2: d596aa25e174f0e3fe36003326cf06aa5b6c8919
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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,13 @@ 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-
| 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
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
270271
$(Q)find $(S)src/etc -name '*.py' \
271272
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
272273
$(Q)find $(S)src/doc -name '*.js' \

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

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

317316
The first case matches against circles. Here, the pattern extracts the
318317
radius from the shape variant and the action uses it to compute the
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
318+
area of the circle.
323319

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

branches/try2/src/doc/guide.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,12 @@ 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. `()` 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.
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.
670668

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

16811679
Rust provides a method on these `IoResult<T>`s called `ok()`, which does the
16821680
same thing as our `match` statement, but assuming that we have a valid value.
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.
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.
16881686

16891687
We will cover the exact details of how all of this works later in the Guide.
16901688
For now, this gives you enough of a basic understanding to work with.
@@ -2030,7 +2028,7 @@ fn main() {
20302028
match cmp(input, secret_number) {
20312029
Less => println!("Too small!"),
20322030
Greater => println!("Too big!"),
2033-
Equal => { println!("You win!"); },
2031+
Equal => println!("You win!"),
20342032
}
20352033
}
20362034
@@ -2727,7 +2725,8 @@ mod hello {
27272725
}
27282726
```
27292727

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

27322731
```{notrust,ignore}
27332732
$ cargo run
@@ -3291,8 +3290,7 @@ use super::times_four;
32913290

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

32973295
We've now covered the basics of testing. Rust's tools are primitive, but they
32983296
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, V> {
49+
pub struct Entries<'a, K: 'a, V: 'a> {
5050
inner: AbsEntries<Traversal<'a, K, V>>
5151
}
5252

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

branches/try2/src/libcollections/vec.rs

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,16 @@ 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());
795794
let ptr = self.ptr;
796795
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+
};
797802
mem::forget(self);
798-
MoveItems { allocation: ptr, cap: cap, iter: iter }
803+
MoveItems { allocation: ptr, cap: cap, ptr: begin, end: end }
799804
}
800805
}
801806

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

17251731
impl<T> MoveItems<T> {
@@ -1728,7 +1734,7 @@ impl<T> MoveItems<T> {
17281734
pub fn unwrap(mut self) -> Vec<T> {
17291735
unsafe {
17301736
for _x in self { }
1731-
let MoveItems { allocation, cap, iter: _iter } = self;
1737+
let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
17321738
mem::forget(self);
17331739
Vec { ptr: allocation, cap: cap, len: 0 }
17341740
}
@@ -1739,29 +1745,55 @@ impl<T> Iterator<T> for MoveItems<T> {
17391745
#[inline]
17401746
fn next<'a>(&'a mut self) -> Option<T> {
17411747
unsafe {
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))
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+
}
17471766
}
17481767
}
17491768

17501769
#[inline]
17511770
fn size_hint(&self) -> (uint, Option<uint>) {
1752-
self.iter.size_hint()
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))
17531775
}
17541776
}
17551777

17561778
impl<T> DoubleEndedIterator<T> for MoveItems<T> {
17571779
#[inline]
17581780
fn next_back<'a>(&'a mut self) -> Option<T> {
17591781
unsafe {
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))
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+
}
17651797
}
17661798
}
17671799
}
@@ -2473,6 +2505,36 @@ mod tests {
24732505
assert_eq!(v.map_in_place(|_| ZeroSized).as_slice(), [ZeroSized, ZeroSized].as_slice());
24742506
}
24752507

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+
24762538
#[bench]
24772539
fn bench_new(b: &mut Bencher) {
24782540
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> {
1221+
pub struct Items<'a, T: 'a> {
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> {
1264+
pub struct MutItems<'a, T: 'a> {
12651265
ptr: *mut T,
12661266
end: *mut T,
12671267
marker: marker::ContravariantLifetime<'a>,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,12 @@ 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+
619625
fn write_out_deps(sess: &Session,
620626
input: &Input,
621627
outputs: &OutputFilenames,
@@ -659,7 +665,7 @@ fn write_out_deps(sess: &Session,
659665
// write Makefile-compatible dependency rules
660666
let files: Vec<String> = sess.codemap().files.borrow()
661667
.iter().filter(|fmap| fmap.is_real_file())
662-
.map(|fmap| fmap.name.to_string())
668+
.map(|fmap| escape_dep_filename(fmap.name.as_slice()))
663669
.collect();
664670
let mut file = try!(io::File::create(&deps_filename));
665671
for path in out_filenames.iter() {

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

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

3030
use getopts;
3131

32-
3332
pub mod driver;
3433
pub mod session;
3534
pub mod config;
3635
pub mod pretty;
3736

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()));
37+
pub fn run(args: Vec<String>) -> int {
38+
monitor(proc() run_compiler(args.as_slice()));
4239
0
4340
}
4441

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

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+
131143
/// Prints version information and returns None on success or an error
132144
/// message on failure.
133145
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
@@ -137,13 +149,14 @@ pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
137149
Some(s) => return Some(format!("Unrecognized argument: {}", s))
138150
};
139151

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

branches/try2/src/librustc/lib.rs

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

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

0 commit comments

Comments
 (0)