From a4af0960bd4bef820cdd10b014d1f9858ec9fa14 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 8 Jul 2013 13:27:55 -0400 Subject: [PATCH 1/7] remove the unused exchange_malloc `align` parameter `malloc` already returns memory correctly aligned for every possible type in standard C, and that's enough for all types in Rust too --- src/librustc/middle/trans/base.rs | 3 +-- src/libstd/rt/global_heap.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) 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/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 } From f2bd4416fa3549f962c8ffdd6474cf4bf0d21eca Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 8 Jul 2013 18:31:26 -0400 Subject: [PATCH 2/7] std: Implement `Iterator::size_hint` method for `Option` iterators --- src/libstd/option.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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()); +} From 763d846dd3db43751eba5b53b6923b8355581063 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 7 Jul 2013 22:32:02 +1000 Subject: [PATCH 3/7] Impl Not for bool --- src/libstd/bool.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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] From ed5499906559a2fc3e9093574ca7e51bc0a4be4a Mon Sep 17 00:00:00 2001 From: Lenny222 Date: Sun, 7 Jul 2013 20:45:57 +0200 Subject: [PATCH 4/7] bright white for the message, similar to clang --- src/libsyntax/diagnostic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]) From a7e3f06257d6bcbb3b1d4e95b5e4d2665b8f15ee Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sat, 6 Jul 2013 00:20:08 -0700 Subject: [PATCH 5/7] Fix typo in docs for MutableCloneableVector --- src/libstd/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From b727b9efd7b854ebf099f72894c2d662d2c63977 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 8 Jul 2013 21:51:28 -0400 Subject: [PATCH 6/7] rm silly compile-fail test it's a test to make sure a feature is *not* implemented, but it is now implemented --- src/test/compile-fail/binop-add-ptr.rs | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/test/compile-fail/binop-add-ptr.rs diff --git a/src/test/compile-fail/binop-add-ptr.rs b/src/test/compile-fail/binop-add-ptr.rs deleted file mode 100644 index 679deceb7bca3..0000000000000 --- a/src/test/compile-fail/binop-add-ptr.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// 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() { } From 31114acdd7da8f2826558b11adea96d1c561aabd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 8 Jul 2013 01:03:16 -0700 Subject: [PATCH 7/7] Require `extern "Rust" fn main()` exactly --- src/librustc/middle/typeck/mod.rs | 23 ++++++++++++---------- src/test/compile-fail/bad-main.rs | 4 +--- src/test/compile-fail/extern-main-fn.rs | 11 +++++++++++ src/test/compile-fail/main-wrong-type-2.rs | 2 +- src/test/compile-fail/main-wrong-type.rs | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 src/test/compile-fail/extern-main-fn.rs 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/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/extern-main-fn.rs b/src/test/compile-fail/extern-main-fn.rs new file mode 100644 index 0000000000000..05ce3eefda86c --- /dev/null +++ b/src/test/compile-fail/extern-main-fn.rs @@ -0,0 +1,11 @@ +// 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. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +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 }