Skip to content

aggregated small commits #7657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 13 additions & 10 deletions src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ A quick summary:
Implementations of the following traits:

* `FromStr`
* `ToStr`
* `Not`
* `Ord`
* `TotalOrd`
* `Eq`
Expand All @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
50 changes: 50 additions & 0 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
Expand All @@ -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]
Expand Down Expand Up @@ -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());
}
4 changes: 2 additions & 2 deletions src/libstd/rt/global_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 1 addition & 3 deletions src/test/compile-fail/bad-main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/test/compile-fail/main-wrong-type-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/main-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}