Skip to content

Commit 137d1fb

Browse files
committed
auto merge of #7657 : thestinger/rust/rollup, r=thestinger
d3be8ab r=brson 05eb3cf r=thestinger c80f4e1 r=huonw 8c27af1 r=huonw 0eee0b6 r=cmr ea2756a r=thestinger
2 parents e388a80 + 31114ac commit 137d1fb

File tree

11 files changed

+98
-26
lines changed

11 files changed

+98
-26
lines changed

src/librustc/middle/trans/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,12 @@ pub fn malloc_raw_dyn(bcx: block,
292292

293293
if heap == heap_exchange {
294294
let llty_value = type_of::type_of(ccx, t);
295-
let llalign = llalign_of_min(ccx, llty_value);
296295

297296
// Allocate space:
298297
let r = callee::trans_lang_call(
299298
bcx,
300299
bcx.tcx().lang_items.exchange_malloc_fn(),
301-
[C_i32(llalign as i32), size],
300+
[size],
302301
None);
303302
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
304303
} else if heap == heap_exchange_vector {

src/librustc/middle/typeck/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,19 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
319319
}
320320
_ => ()
321321
}
322-
let mut ok = ty::type_is_nil(fn_ty.sig.output);
323-
let num_args = fn_ty.sig.inputs.len();
324-
ok &= num_args == 0u;
325-
if !ok {
326-
tcx.sess.span_err(
327-
main_span,
328-
fmt!("Wrong type in main function: found `%s`, \
329-
expected `fn() -> ()`",
330-
ppaux::ty_to_str(tcx, main_t)));
331-
}
322+
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
323+
purity: ast::impure_fn,
324+
abis: abi::AbiSet::Rust(),
325+
sig: ty::FnSig {
326+
bound_lifetime_names: opt_vec::Empty,
327+
inputs: ~[],
328+
output: ty::mk_nil()
329+
}
330+
});
331+
332+
require_same_types(tcx, None, false, main_span, main_t, se_ty,
333+
|| fmt!("main function expects type: `%s`",
334+
ppaux::ty_to_str(ccx.tcx, se_ty)));
332335
}
333336
_ => {
334337
tcx.sess.span_bug(main_span,

src/libstd/bool.rs

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ A quick summary:
1919
Implementations of the following traits:
2020
2121
* `FromStr`
22+
* `ToStr`
23+
* `Not`
2224
* `Ord`
2325
* `TotalOrd`
2426
* `Eq`
@@ -36,6 +38,8 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
3638

3739
#[cfg(not(test))]
3840
use cmp::{Eq, Ord, TotalOrd, Ordering};
41+
#[cfg(not(test))]
42+
use ops::Not;
3943
use option::{None, Option, Some};
4044
use from_str::FromStr;
4145
use to_str::ToStr;
@@ -254,6 +258,27 @@ pub fn all_values(blk: &fn(v: bool)) {
254258
#[inline]
255259
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
256260

261+
/**
262+
* The logical complement of a boolean value.
263+
*
264+
* # Examples
265+
*
266+
* ~~~rust
267+
* rusti> !true
268+
* false
269+
* ~~~
270+
*
271+
* ~~~rust
272+
* rusti> !false
273+
* true
274+
* ~~~
275+
*/
276+
#[cfg(not(test))]
277+
impl Not<bool> for bool {
278+
#[inline]
279+
fn not(&self) -> bool { !*self }
280+
}
281+
257282
#[cfg(not(test))]
258283
impl Ord for bool {
259284
#[inline]

src/libstd/option.rs

+50
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ impl<'self, A> Iterator<&'self A> for OptionIterator<'self, A> {
379379
fn next(&mut self) -> Option<&'self A> {
380380
util::replace(&mut self.opt, None)
381381
}
382+
383+
fn size_hint(&self) -> (uint, Option<uint>) {
384+
match self.opt {
385+
Some(_) => (1, Some(1)),
386+
None => (0, Some(0)),
387+
}
388+
}
382389
}
383390

384391
/// Mutable iterator over an `Option<A>`
@@ -390,6 +397,13 @@ impl<'self, A> Iterator<&'self mut A> for OptionMutIterator<'self, A> {
390397
fn next(&mut self) -> Option<&'self mut A> {
391398
util::replace(&mut self.opt, None)
392399
}
400+
401+
fn size_hint(&self) -> (uint, Option<uint>) {
402+
match self.opt {
403+
Some(_) => (1, Some(1)),
404+
None => (0, Some(0)),
405+
}
406+
}
393407
}
394408

395409
#[test]
@@ -487,3 +501,39 @@ fn test_filtered() {
487501
assert_eq!(some_stuff.get(), 42);
488502
assert!(modified_stuff.is_none());
489503
}
504+
505+
#[test]
506+
fn test_iter() {
507+
let val = 5;
508+
509+
let x = Some(val);
510+
let mut it = x.iter();
511+
512+
assert_eq!(it.size_hint(), (1, Some(1)));
513+
assert_eq!(it.next(), Some(&val));
514+
assert_eq!(it.size_hint(), (0, Some(0)));
515+
assert!(it.next().is_none());
516+
}
517+
518+
#[test]
519+
fn test_mut_iter() {
520+
let val = 5;
521+
let new_val = 11;
522+
523+
let mut x = Some(val);
524+
let mut it = x.mut_iter();
525+
526+
assert_eq!(it.size_hint(), (1, Some(1)));
527+
528+
match it.next() {
529+
Some(interior) => {
530+
assert_eq!(*interior, val);
531+
*interior = new_val;
532+
assert_eq!(x, Some(new_val));
533+
}
534+
None => assert!(false),
535+
}
536+
537+
assert_eq!(it.size_hint(), (0, Some(0)));
538+
assert!(it.next().is_none());
539+
}

src/libstd/rt/global_heap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
7676
box as *c_char
7777
}
7878

79-
// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
79+
/// The allocator for unique pointers without contained managed pointers.
8080
#[cfg(not(stage0), not(test))]
8181
#[lang="exchange_malloc"]
8282
#[inline]
83-
pub unsafe fn exchange_malloc(_align: u32, size: uintptr_t) -> *c_char {
83+
pub unsafe fn exchange_malloc(size: uintptr_t) -> *c_char {
8484
malloc_raw(size as uint) as *c_char
8585
}
8686

src/libstd/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
17711771

17721772
}
17731773

1774-
/// Trait for ~[T] where T is Cloneable
1774+
/// Trait for &[T] where T is Cloneable
17751775
pub trait MutableCloneableVector<T> {
17761776
/// Copies as many elements from `src` as it can into `self`
17771777
/// (the shorter of self.len() and src.len()). Returns the number of elements copied.

src/libsyntax/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
213213
}
214214

215215
print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl));
216-
stderr.write_str(fmt!("%s\n", msg));
216+
print_maybe_colored(fmt!("%s\n", msg), term::color::BRIGHT_WHITE);
217217
}
218218

219219
pub fn collect(messages: @mut ~[~str])

src/test/compile-fail/bad-main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:expected `fn()
12-
13-
fn main(x: int) { }
11+
fn main(x: int) { } //~ ERROR: main function expects type
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,7 +8,4 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:binary operation + cannot be applied to type `*int`
12-
13-
fn die() -> *int { (0 as *int) + (0 as *int) }
14-
fn main() { }
11+
extern fn main() {} //~ ERROR: main function expects type

src/test/compile-fail/main-wrong-type-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() -> char {
12-
//~^ ERROR Wrong type in main function: found `extern "Rust" fn() -> char`
12+
//~^ ERROR: main function expects type
1313
}

src/test/compile-fail/main-wrong-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ struct S {
1414
}
1515

1616
fn main(foo: S) {
17-
//~^ ERROR Wrong type in main function: found `extern "Rust" fn(S)`
17+
//~^ ERROR: main function expects type
1818
}

0 commit comments

Comments
 (0)