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
This commit is contained in:
commit
137d1fb210
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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<bool> for bool {
|
||||
#[inline]
|
||||
fn not(&self) -> bool { !*self }
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Ord for bool {
|
||||
#[inline]
|
||||
|
@ -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<uint>) {
|
||||
match self.opt {
|
||||
Some(_) => (1, Some(1)),
|
||||
None => (0, Some(0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Mutable iterator over an `Option<A>`
|
||||
@ -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<uint>) {
|
||||
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());
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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<T> {
|
||||
/// 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.
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user