diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 80fc3803ae732..2fc502568a8f2 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -292,13 +292,12 @@ pub fn malloc_raw_dyn(bcx: block, if heap == heap_exchange { let llty_value = type_of::type_of(ccx, t); - let llalign = llalign_of_min(ccx, llty_value); // Allocate space: let r = callee::trans_lang_call( bcx, bcx.tcx().lang_items.exchange_malloc_fn(), - [C_i32(llalign as i32), size], + [size], None); rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to())) } else if heap == heap_exchange_vector { diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index bbcfc73853a1e..6f5dde74b5c10 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -319,16 +319,19 @@ fn check_main_fn_ty(ccx: &CrateCtxt, } _ => () } - let mut ok = ty::type_is_nil(fn_ty.sig.output); - let num_args = fn_ty.sig.inputs.len(); - ok &= num_args == 0u; - if !ok { - tcx.sess.span_err( - main_span, - fmt!("Wrong type in main function: found `%s`, \ - expected `fn() -> ()`", - ppaux::ty_to_str(tcx, main_t))); - } + let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy { + purity: ast::impure_fn, + abis: abi::AbiSet::Rust(), + sig: ty::FnSig { + bound_lifetime_names: opt_vec::Empty, + inputs: ~[], + output: ty::mk_nil() + } + }); + + require_same_types(tcx, None, false, main_span, main_t, se_ty, + || fmt!("main function expects type: `%s`", + ppaux::ty_to_str(ccx.tcx, se_ty))); } _ => { tcx.sess.span_bug(main_span, diff --git a/src/libstd/bool.rs b/src/libstd/bool.rs index b0b586df4b58e..126650981cd5f 100644 --- a/src/libstd/bool.rs +++ b/src/libstd/bool.rs @@ -19,6 +19,8 @@ A quick summary: Implementations of the following traits: * `FromStr` +* `ToStr` +* `Not` * `Ord` * `TotalOrd` * `Eq` @@ -36,6 +38,8 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`. #[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering}; +#[cfg(not(test))] +use ops::Not; use option::{None, Option, Some}; use from_str::FromStr; use to_str::ToStr; @@ -254,6 +258,27 @@ pub fn all_values(blk: &fn(v: bool)) { #[inline] pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } } +/** +* The logical complement of a boolean value. +* +* # Examples +* +* ~~~rust +* rusti> !true +* false +* ~~~ +* +* ~~~rust +* rusti> !false +* true +* ~~~ +*/ +#[cfg(not(test))] +impl Not for bool { + #[inline] + fn not(&self) -> bool { !*self } +} + #[cfg(not(test))] impl Ord for bool { #[inline] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index fb9962f8a44ec..222952a6dc143 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -379,6 +379,13 @@ impl<'self, A> Iterator<&'self A> for OptionIterator<'self, A> { fn next(&mut self) -> Option<&'self A> { util::replace(&mut self.opt, None) } + + fn size_hint(&self) -> (uint, Option) { + match self.opt { + Some(_) => (1, Some(1)), + None => (0, Some(0)), + } + } } /// Mutable iterator over an `Option` @@ -390,6 +397,13 @@ impl<'self, A> Iterator<&'self mut A> for OptionMutIterator<'self, A> { fn next(&mut self) -> Option<&'self mut A> { util::replace(&mut self.opt, None) } + + fn size_hint(&self) -> (uint, Option) { + match self.opt { + Some(_) => (1, Some(1)), + None => (0, Some(0)), + } + } } #[test] @@ -487,3 +501,39 @@ fn test_filtered() { assert_eq!(some_stuff.get(), 42); assert!(modified_stuff.is_none()); } + +#[test] +fn test_iter() { + let val = 5; + + let x = Some(val); + let mut it = x.iter(); + + assert_eq!(it.size_hint(), (1, Some(1))); + assert_eq!(it.next(), Some(&val)); + assert_eq!(it.size_hint(), (0, Some(0))); + assert!(it.next().is_none()); +} + +#[test] +fn test_mut_iter() { + let val = 5; + let new_val = 11; + + let mut x = Some(val); + let mut it = x.mut_iter(); + + assert_eq!(it.size_hint(), (1, Some(1))); + + match it.next() { + Some(interior) => { + assert_eq!(*interior, val); + *interior = new_val; + assert_eq!(x, Some(new_val)); + } + None => assert!(false), + } + + assert_eq!(it.size_hint(), (0, Some(0))); + assert!(it.next().is_none()); +} diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 54deb8924f5c7..ef89b8de45490 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -76,11 +76,11 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { box as *c_char } -// FIXME #4942: Make these signatures agree with exchange_alloc's signatures +/// The allocator for unique pointers without contained managed pointers. #[cfg(not(stage0), not(test))] #[lang="exchange_malloc"] #[inline] -pub unsafe fn exchange_malloc(_align: u32, size: uintptr_t) -> *c_char { +pub unsafe fn exchange_malloc(size: uintptr_t) -> *c_char { malloc_raw(size as uint) as *c_char } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 191c2a4a0b2d3..66aad294991cc 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1771,7 +1771,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] { } -/// Trait for ~[T] where T is Cloneable +/// Trait for &[T] where T is Cloneable pub trait MutableCloneableVector { /// Copies as many elements from `src` as it can into `self` /// (the shorter of self.len() and src.len()). Returns the number of elements copied. diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 204028212d621..0180c2b31d723 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -213,7 +213,7 @@ fn print_diagnostic(topic: &str, lvl: level, msg: &str) { } print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl)); - stderr.write_str(fmt!("%s\n", msg)); + print_maybe_colored(fmt!("%s\n", msg), term::color::BRIGHT_WHITE); } pub fn collect(messages: @mut ~[~str]) diff --git a/src/test/compile-fail/bad-main.rs b/src/test/compile-fail/bad-main.rs index 3f366fcd06fd7..da8596fa25b47 100644 --- a/src/test/compile-fail/bad-main.rs +++ b/src/test/compile-fail/bad-main.rs @@ -8,6 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected `fn() - -fn main(x: int) { } +fn main(x: int) { } //~ ERROR: main function expects type diff --git a/src/test/compile-fail/binop-add-ptr.rs b/src/test/compile-fail/extern-main-fn.rs similarity index 67% rename from src/test/compile-fail/binop-add-ptr.rs rename to src/test/compile-fail/extern-main-fn.rs index 679deceb7bca3..05ce3eefda86c 100644 --- a/src/test/compile-fail/binop-add-ptr.rs +++ b/src/test/compile-fail/extern-main-fn.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,7 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:binary operation + cannot be applied to type `*int` - -fn die() -> *int { (0 as *int) + (0 as *int) } -fn main() { } +extern fn main() {} //~ ERROR: main function expects type diff --git a/src/test/compile-fail/main-wrong-type-2.rs b/src/test/compile-fail/main-wrong-type-2.rs index 136cc2b8680bc..09d5765a80f3f 100644 --- a/src/test/compile-fail/main-wrong-type-2.rs +++ b/src/test/compile-fail/main-wrong-type-2.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() -> char { -//~^ ERROR Wrong type in main function: found `extern "Rust" fn() -> char` +//~^ ERROR: main function expects type } diff --git a/src/test/compile-fail/main-wrong-type.rs b/src/test/compile-fail/main-wrong-type.rs index f3ecac3f406bd..ae990880523f9 100644 --- a/src/test/compile-fail/main-wrong-type.rs +++ b/src/test/compile-fail/main-wrong-type.rs @@ -14,5 +14,5 @@ struct S { } fn main(foo: S) { -//~^ ERROR Wrong type in main function: found `extern "Rust" fn(S)` +//~^ ERROR: main function expects type }