Merge pull request #4625 from thestinger/container
more little container improvements
This commit is contained in:
commit
85a34c2898
@ -70,7 +70,7 @@ fn parse_config(args: ~[~str]) -> config {
|
|||||||
getopts::optopt(~"logfile"),
|
getopts::optopt(~"logfile"),
|
||||||
getopts::optflag(~"jit")];
|
getopts::optflag(~"jit")];
|
||||||
|
|
||||||
assert (vec::is_not_empty(args));
|
assert !args.is_empty();
|
||||||
let args_ = vec::tail(args);
|
let args_ = vec::tail(args);
|
||||||
let matches =
|
let matches =
|
||||||
&match getopts::getopts(args_, opts) {
|
&match getopts::getopts(args_, opts) {
|
||||||
|
@ -59,8 +59,8 @@ fn run_cfail_test(config: config, props: test_props, testfile: &Path) {
|
|||||||
check_correct_failure_status(procres);
|
check_correct_failure_status(procres);
|
||||||
|
|
||||||
let expected_errors = errors::load_errors(testfile);
|
let expected_errors = errors::load_errors(testfile);
|
||||||
if vec::is_not_empty(expected_errors) {
|
if !expected_errors.is_empty() {
|
||||||
if vec::is_not_empty(props.error_patterns) {
|
if !props.error_patterns.is_empty() {
|
||||||
fatal(~"both error pattern and expected errors specified");
|
fatal(~"both error pattern and expected errors specified");
|
||||||
}
|
}
|
||||||
check_expected_errors(expected_errors, testfile, procres);
|
check_expected_errors(expected_errors, testfile, procres);
|
||||||
@ -440,7 +440,7 @@ fn compose_and_run_compiler(
|
|||||||
args: procargs,
|
args: procargs,
|
||||||
input: Option<~str>) -> procres {
|
input: Option<~str>) -> procres {
|
||||||
|
|
||||||
if props.aux_builds.is_not_empty() {
|
if !props.aux_builds.is_empty() {
|
||||||
ensure_dir(&aux_output_dir_name(config, testfile));
|
ensure_dir(&aux_output_dir_name(config, testfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,8 @@ pub use path::PosixPath;
|
|||||||
|
|
||||||
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
|
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
|
||||||
pub use str::{StrSlice, Trimmable};
|
pub use str::{StrSlice, Trimmable};
|
||||||
pub use vec::{ConstVector, CopyableVector, ImmutableVector};
|
pub use container::{Container, Mutable};
|
||||||
|
pub use vec::{CopyableVector, ImmutableVector};
|
||||||
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
|
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
|
||||||
pub use vec::{OwnedVector, OwnedCopyableVector};
|
pub use vec::{OwnedVector, OwnedCopyableVector};
|
||||||
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
||||||
|
@ -208,8 +208,6 @@ impl<T> DList<T> {
|
|||||||
pure fn len(@self) -> uint { self.size }
|
pure fn len(@self) -> uint { self.size }
|
||||||
/// Returns true if the list is empty. O(1).
|
/// Returns true if the list is empty. O(1).
|
||||||
pure fn is_empty(@self) -> bool { self.len() == 0 }
|
pure fn is_empty(@self) -> bool { self.len() == 0 }
|
||||||
/// Returns true if the list is not empty. O(1).
|
|
||||||
pure fn is_not_empty(@self) -> bool { self.len() != 0 }
|
|
||||||
|
|
||||||
/// Add data to the head of the list. O(1).
|
/// Add data to the head of the list. O(1).
|
||||||
fn push_head(@self, data: T) {
|
fn push_head(@self, data: T) {
|
||||||
@ -648,8 +646,6 @@ mod tests {
|
|||||||
let full1 = from_vec(~[1,2,3]);
|
let full1 = from_vec(~[1,2,3]);
|
||||||
assert empty.is_empty();
|
assert empty.is_empty();
|
||||||
assert !full1.is_empty();
|
assert !full1.is_empty();
|
||||||
assert !empty.is_not_empty();
|
|
||||||
assert full1.is_not_empty();
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dlist_head_tail() {
|
fn test_dlist_head_tail() {
|
||||||
|
@ -157,7 +157,7 @@ pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
|
|||||||
|
|
||||||
// turn digits into string
|
// turn digits into string
|
||||||
// using stack of digits
|
// using stack of digits
|
||||||
while fractionalParts.is_not_empty() {
|
while !fractionalParts.is_empty() {
|
||||||
// Bleh; shouldn't need to be unsafe
|
// Bleh; shouldn't need to be unsafe
|
||||||
let mut adjusted_digit = carry + unsafe { fractionalParts.pop() };
|
let mut adjusted_digit = carry + unsafe { fractionalParts.pop() };
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ pub use path::PosixPath;
|
|||||||
|
|
||||||
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
|
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
|
||||||
pub use str::{StrSlice, Trimmable};
|
pub use str::{StrSlice, Trimmable};
|
||||||
pub use vec::{ConstVector, CopyableVector, ImmutableVector};
|
pub use container::{Container, Mutable};
|
||||||
|
pub use vec::{CopyableVector, ImmutableVector};
|
||||||
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
|
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
|
||||||
pub use vec::{OwnedVector, OwnedCopyableVector};
|
pub use vec::{OwnedVector, OwnedCopyableVector};
|
||||||
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
|
||||||
|
@ -1419,9 +1419,6 @@ pub pure fn is_ascii(s: &str) -> bool {
|
|||||||
/// Returns true if the string has length 0
|
/// Returns true if the string has length 0
|
||||||
pub pure fn is_empty(s: &str) -> bool { len(s) == 0u }
|
pub pure fn is_empty(s: &str) -> bool { len(s) == 0u }
|
||||||
|
|
||||||
/// Returns true if the string has length greater than 0
|
|
||||||
pub pure fn is_not_empty(s: &str) -> bool { !is_empty(s) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the string contains only whitespace
|
* Returns true if the string contains only whitespace
|
||||||
*
|
*
|
||||||
@ -2167,7 +2164,6 @@ pub trait StrSlice {
|
|||||||
pure fn each_chari(it: fn(uint, char) -> bool);
|
pure fn each_chari(it: fn(uint, char) -> bool);
|
||||||
pure fn ends_with(needle: &str) -> bool;
|
pure fn ends_with(needle: &str) -> bool;
|
||||||
pure fn is_empty() -> bool;
|
pure fn is_empty() -> bool;
|
||||||
pure fn is_not_empty() -> bool;
|
|
||||||
pure fn is_whitespace() -> bool;
|
pure fn is_whitespace() -> bool;
|
||||||
pure fn is_alphanumeric() -> bool;
|
pure fn is_alphanumeric() -> bool;
|
||||||
pure fn len() -> uint;
|
pure fn len() -> uint;
|
||||||
@ -2229,9 +2225,6 @@ impl &str: StrSlice {
|
|||||||
/// Returns true if the string has length 0
|
/// Returns true if the string has length 0
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn is_empty() -> bool { is_empty(self) }
|
pure fn is_empty() -> bool { is_empty(self) }
|
||||||
/// Returns true if the string has length greater than 0
|
|
||||||
#[inline]
|
|
||||||
pure fn is_not_empty() -> bool { is_not_empty(self) }
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the string contains only whitespace
|
* Returns true if the string contains only whitespace
|
||||||
*
|
*
|
||||||
@ -2739,12 +2732,6 @@ mod tests {
|
|||||||
assert (!is_empty(~"a"));
|
assert (!is_empty(~"a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_not_empty() {
|
|
||||||
assert (is_not_empty(~"a"));
|
|
||||||
assert (!is_not_empty(~""));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_replace() {
|
fn test_replace() {
|
||||||
let a = ~"a";
|
let a = ~"a";
|
||||||
|
@ -84,7 +84,7 @@ terminate normally, but instead directly return from a function.
|
|||||||
|
|
||||||
~~~
|
~~~
|
||||||
fn choose_weighted_item(v: &[Item]) -> Item {
|
fn choose_weighted_item(v: &[Item]) -> Item {
|
||||||
assert v.is_not_empty();
|
assert !v.is_empty();
|
||||||
let mut so_far = 0u;
|
let mut so_far = 0u;
|
||||||
for v.each |item| {
|
for v.each |item| {
|
||||||
so_far += item.weight;
|
so_far += item.weight;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#[forbid(deprecated_pattern)];
|
#[forbid(deprecated_pattern)];
|
||||||
#[warn(non_camel_case_types)];
|
#[warn(non_camel_case_types)];
|
||||||
|
|
||||||
|
use container::{Container, Mutable};
|
||||||
use cast::transmute;
|
use cast::transmute;
|
||||||
use cast;
|
use cast;
|
||||||
use cmp::{Eq, Ord};
|
use cmp::{Eq, Ord};
|
||||||
@ -48,11 +49,6 @@ pub pure fn is_empty<T>(v: &[const T]) -> bool {
|
|||||||
as_const_buf(v, |_p, len| len == 0u)
|
as_const_buf(v, |_p, len| len == 0u)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a vector contains some elements
|
|
||||||
pub pure fn is_not_empty<T>(v: &[const T]) -> bool {
|
|
||||||
as_const_buf(v, |_p, len| len > 0u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if two vectors have the same length
|
/// Returns true if two vectors have the same length
|
||||||
pub pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
|
pub pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
|
||||||
len(xs) == len(ys)
|
len(xs) == len(ys)
|
||||||
@ -453,7 +449,7 @@ pub pure fn partitioned<T: Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
|
|||||||
/// Removes the first element from a vector and return it
|
/// Removes the first element from a vector and return it
|
||||||
pub fn shift<T>(v: &mut ~[T]) -> T {
|
pub fn shift<T>(v: &mut ~[T]) -> T {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert v.is_not_empty();
|
assert !v.is_empty();
|
||||||
|
|
||||||
if v.len() == 1 { return v.pop() }
|
if v.len() == 1 { return v.pop() }
|
||||||
|
|
||||||
@ -1647,20 +1643,11 @@ pub mod traits {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ConstVector {
|
impl<T> &[const T]: Container {
|
||||||
pure fn is_empty(&self) -> bool;
|
|
||||||
pure fn is_not_empty(&self) -> bool;
|
|
||||||
pure fn len(&self) -> uint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extension methods for vectors
|
|
||||||
impl<T> &[const T]: ConstVector {
|
|
||||||
/// Returns true if a vector contains no elements
|
/// Returns true if a vector contains no elements
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn is_empty(&self) -> bool { is_empty(*self) }
|
pure fn is_empty(&self) -> bool { is_empty(*self) }
|
||||||
/// Returns true if a vector contains some elements
|
|
||||||
#[inline]
|
|
||||||
pure fn is_not_empty(&self) -> bool { is_not_empty(*self) }
|
|
||||||
/// Returns the length of a vector
|
/// Returns the length of a vector
|
||||||
#[inline]
|
#[inline]
|
||||||
pure fn len(&self) -> uint { len(*self) }
|
pure fn len(&self) -> uint { len(*self) }
|
||||||
@ -1949,6 +1936,11 @@ impl<T> ~[T]: OwnedVector<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> ~[T]: Mutable {
|
||||||
|
/// Clear the vector, removing all values.
|
||||||
|
fn clear(&mut self) { self.truncate(0) }
|
||||||
|
}
|
||||||
|
|
||||||
pub trait OwnedCopyableVector<T: Copy> {
|
pub trait OwnedCopyableVector<T: Copy> {
|
||||||
fn push_all(&mut self, rhs: &[const T]);
|
fn push_all(&mut self, rhs: &[const T]);
|
||||||
fn grow(&mut self, n: uint, initval: &T);
|
fn grow(&mut self, n: uint, initval: &T);
|
||||||
@ -2518,12 +2510,6 @@ mod tests {
|
|||||||
assert (!is_empty(~[0]));
|
assert (!is_empty(~[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_not_empty() {
|
|
||||||
assert (is_not_empty(~[0]));
|
|
||||||
assert (!is_not_empty::<int>(~[]));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_len_divzero() {
|
fn test_len_divzero() {
|
||||||
type Z = [i8 * 0];
|
type Z = [i8 * 0];
|
||||||
@ -2700,6 +2686,14 @@ mod tests {
|
|||||||
// If the unsafe block didn't drop things properly, we blow up here.
|
// If the unsafe block didn't drop things properly, we blow up here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_clear() {
|
||||||
|
let mut v = ~[@6,@5,@4];
|
||||||
|
v.clear();
|
||||||
|
assert(v.len() == 0);
|
||||||
|
// If the unsafe block didn't drop things properly, we blow up here.
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dedup() {
|
fn test_dedup() {
|
||||||
fn case(a: ~[uint], b: ~[uint]) {
|
fn case(a: ~[uint], b: ~[uint]) {
|
||||||
|
@ -167,7 +167,7 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
|
|||||||
|
|
||||||
path.push_all(vec::view(split2, start_idx, len2 - 1));
|
path.push_all(vec::view(split2, start_idx, len2 - 1));
|
||||||
|
|
||||||
if vec::is_not_empty(path) {
|
if !path.is_empty() {
|
||||||
return Path("").push_many(path);
|
return Path("").push_many(path);
|
||||||
} else {
|
} else {
|
||||||
return Path(".");
|
return Path(".");
|
||||||
|
@ -147,8 +147,8 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_test_fn(i: @ast::item) -> bool {
|
fn is_test_fn(i: @ast::item) -> bool {
|
||||||
let has_test_attr = attr::find_attrs_by_name(i.attrs,
|
let has_test_attr = !attr::find_attrs_by_name(i.attrs,
|
||||||
~"test").is_not_empty();
|
~"test").is_empty();
|
||||||
|
|
||||||
fn has_test_signature(i: @ast::item) -> bool {
|
fn has_test_signature(i: @ast::item) -> bool {
|
||||||
match &i.node {
|
match &i.node {
|
||||||
@ -171,7 +171,7 @@ fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool {
|
|||||||
let ignoreitems = attr::attr_metas(ignoreattrs);
|
let ignoreitems = attr::attr_metas(ignoreattrs);
|
||||||
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
|
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
|
||||||
|i| attr::get_meta_item_list(*i)));
|
|i| attr::get_meta_item_list(*i)));
|
||||||
return if vec::is_not_empty(ignoreitems) {
|
return if !ignoreitems.is_empty() {
|
||||||
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
|
config::metas_in_cfg(/*bad*/copy cx.crate.node.config, cfg_metas)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -1331,7 +1331,7 @@ fn type_to_str_inner(names: type_names, +outer0: ~[TypeRef], ty: TypeRef) ->
|
|||||||
Struct => {
|
Struct => {
|
||||||
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
|
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
|
||||||
let mut elts = vec::from_elem(n_elts, 0 as TypeRef);
|
let mut elts = vec::from_elem(n_elts, 0 as TypeRef);
|
||||||
if elts.is_not_empty() {
|
if !elts.is_empty() {
|
||||||
llvm::LLVMGetStructElementTypes(
|
llvm::LLVMGetStructElementTypes(
|
||||||
ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
|
ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ fn warn_if_multiple_versions(e: env, diag: span_handler,
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
assert matches.is_not_empty();
|
assert !matches.is_empty();
|
||||||
|
|
||||||
if matches.len() != 1u {
|
if matches.len() != 1u {
|
||||||
diag.handler().warn(
|
diag.handler().warn(
|
||||||
@ -168,7 +168,7 @@ fn visit_item(e: env, i: @ast::item) {
|
|||||||
already_added = !cstore::add_used_library(cstore,
|
already_added = !cstore::add_used_library(cstore,
|
||||||
foreign_name);
|
foreign_name);
|
||||||
}
|
}
|
||||||
if link_args.is_not_empty() && already_added {
|
if !link_args.is_empty() && already_added {
|
||||||
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
|
e.diag.span_fatal(i.span, ~"library '" + foreign_name +
|
||||||
~"' already added: can't specify link_args.");
|
~"' already added: can't specify link_args.");
|
||||||
}
|
}
|
||||||
|
@ -1018,8 +1018,8 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: &crate) -> ~[attribute] {
|
|||||||
fn synthesize_link_attr(ecx: @encode_ctxt, +items: ~[@meta_item]) ->
|
fn synthesize_link_attr(ecx: @encode_ctxt, +items: ~[@meta_item]) ->
|
||||||
attribute {
|
attribute {
|
||||||
|
|
||||||
assert ecx.link_meta.name.is_not_empty();
|
assert !ecx.link_meta.name.is_empty();
|
||||||
assert ecx.link_meta.vers.is_not_empty();
|
assert !ecx.link_meta.vers.is_empty();
|
||||||
|
|
||||||
let name_item =
|
let name_item =
|
||||||
attr::mk_name_value_item_str(~"name",
|
attr::mk_name_value_item_str(~"name",
|
||||||
|
@ -179,7 +179,7 @@ fn crate_matches(crate_data: @~[u8], +metas: ~[@ast::meta_item],
|
|||||||
hash: ~str) -> bool {
|
hash: ~str) -> bool {
|
||||||
let attrs = decoder::get_crate_attributes(crate_data);
|
let attrs = decoder::get_crate_attributes(crate_data);
|
||||||
let linkage_metas = attr::find_linkage_metas(attrs);
|
let linkage_metas = attr::find_linkage_metas(attrs);
|
||||||
if hash.is_not_empty() {
|
if !hash.is_empty() {
|
||||||
let chash = decoder::get_crate_hash(crate_data);
|
let chash = decoder::get_crate_hash(crate_data);
|
||||||
if chash != hash { return false; }
|
if chash != hash { return false; }
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ fn raw_pat(p: @pat) -> @pat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||||
assert(pats.is_not_empty());
|
assert(!pats.is_empty());
|
||||||
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
|
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
|
||||||
not_useful => return, // This is good, wildcard pattern isn't reachable
|
not_useful => return, // This is good, wildcard pattern isn't reachable
|
||||||
useful_ => None,
|
useful_ => None,
|
||||||
|
@ -820,7 +820,7 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
|
|||||||
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
|
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
|
||||||
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
|
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
|
||||||
let ident = cx.sess.str_of(ident);
|
let ident = cx.sess.str_of(ident);
|
||||||
assert ident.is_not_empty();
|
assert !ident.is_empty();
|
||||||
let ident = ident_without_trailing_underscores(ident);
|
let ident = ident_without_trailing_underscores(ident);
|
||||||
let ident = ident_without_leading_underscores(ident);
|
let ident = ident_without_leading_underscores(ident);
|
||||||
char::is_uppercase(str::char_at(ident, 0)) &&
|
char::is_uppercase(str::char_at(ident, 0)) &&
|
||||||
|
@ -459,7 +459,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
|
|||||||
parent_id: ast::def_id, substs: ~[ty::t])
|
parent_id: ast::def_id, substs: ~[ty::t])
|
||||||
-> ValueRef {
|
-> ValueRef {
|
||||||
let _icx = ccx.insn_ctxt("trans_res_dtor");
|
let _icx = ccx.insn_ctxt("trans_res_dtor");
|
||||||
if (substs.is_not_empty()) {
|
if !substs.is_empty() {
|
||||||
let did = if did.crate != ast::local_crate {
|
let did = if did.crate != ast::local_crate {
|
||||||
inline::maybe_instantiate_inline(ccx, did, true)
|
inline::maybe_instantiate_inline(ccx, did, true)
|
||||||
} else { did };
|
} else { did };
|
||||||
|
@ -635,7 +635,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
|||||||
} else {
|
} else {
|
||||||
for m.items.each |item| {
|
for m.items.each |item| {
|
||||||
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
|
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
|
||||||
if (*tpt.bounds).is_not_empty() {
|
if !tpt.bounds.is_empty() {
|
||||||
ccx.tcx.sess.span_err(
|
ccx.tcx.sess.span_err(
|
||||||
item.span,
|
item.span,
|
||||||
fmt!("foreign items may not have type parameters"));
|
fmt!("foreign items may not have type parameters"));
|
||||||
|
@ -356,7 +356,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
|
|||||||
Some(ast_map::node_item(it,_)) => {
|
Some(ast_map::node_item(it,_)) => {
|
||||||
match it.node {
|
match it.node {
|
||||||
ast::item_fn(_, _, ref ps, _)
|
ast::item_fn(_, _, ref ps, _)
|
||||||
if vec::is_not_empty(*ps) => {
|
if !ps.is_empty() => {
|
||||||
tcx.sess.span_err(
|
tcx.sess.span_err(
|
||||||
main_span,
|
main_span,
|
||||||
~"main function is not allowed \
|
~"main function is not allowed \
|
||||||
|
@ -127,7 +127,7 @@ pub fn parse_hidden(+attrs: ~[ast::attribute]) -> bool {
|
|||||||
match attr::get_meta_item_list(*meta) {
|
match attr::get_meta_item_list(*meta) {
|
||||||
Some(metas) => {
|
Some(metas) => {
|
||||||
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
|
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
|
||||||
vec::is_not_empty(hiddens)
|
!hiddens.is_empty()
|
||||||
}
|
}
|
||||||
None => false
|
None => false
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ fn parse_desc(desc: ~str) -> Option<~str> {
|
|||||||
|
|
||||||
fn first_sentence(s: ~str) -> Option<~str> {
|
fn first_sentence(s: ~str) -> Option<~str> {
|
||||||
let paras = paragraphs(s);
|
let paras = paragraphs(s);
|
||||||
if vec::is_not_empty(paras) {
|
if !paras.is_empty() {
|
||||||
let first_para = vec::head(paras);
|
let first_para = vec::head(paras);
|
||||||
Some(str::replace(first_sentence_(first_para), ~"\n", ~" "))
|
Some(str::replace(first_sentence_(first_para), ~"\n", ~" "))
|
||||||
} else {
|
} else {
|
||||||
@ -193,7 +193,7 @@ fn paragraphs(s: ~str) -> ~[~str] {
|
|||||||
whitespace_lines += 1;
|
whitespace_lines += 1;
|
||||||
} else {
|
} else {
|
||||||
if whitespace_lines > 0 {
|
if whitespace_lines > 0 {
|
||||||
if str::is_not_empty(accum) {
|
if !accum.is_empty() {
|
||||||
res += ~[accum];
|
res += ~[accum];
|
||||||
accum = ~"";
|
accum = ~"";
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ fn paragraphs(s: ~str) -> ~[~str] {
|
|||||||
res
|
res
|
||||||
};
|
};
|
||||||
|
|
||||||
if str::is_not_empty(accum) {
|
if !accum.is_empty() {
|
||||||
paras + ~[accum]
|
paras + ~[accum]
|
||||||
} else {
|
} else {
|
||||||
paras
|
paras
|
||||||
|
@ -78,7 +78,7 @@ fn unindent(s: ~str) -> ~str {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if vec::is_not_empty(lines) {
|
if !lines.is_empty() {
|
||||||
let unindented = ~[str::trim(vec::head(lines))]
|
let unindented = ~[str::trim(vec::head(lines))]
|
||||||
+ do par::map(vec::tail(lines)) |line| {
|
+ do par::map(vec::tail(lines)) |line| {
|
||||||
if str::is_whitespace(*line) {
|
if str::is_whitespace(*line) {
|
||||||
|
@ -402,7 +402,7 @@ pub impl BigUint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pure fn is_zero(&self) -> bool { self.data.is_empty() }
|
pure fn is_zero(&self) -> bool { self.data.is_empty() }
|
||||||
pure fn is_not_zero(&self) -> bool { self.data.is_not_empty() }
|
pure fn is_not_zero(&self) -> bool { !self.data.is_empty() }
|
||||||
pure fn is_positive(&self) -> bool { self.is_not_zero() }
|
pure fn is_positive(&self) -> bool { self.is_not_zero() }
|
||||||
pure fn is_negative(&self) -> bool { false }
|
pure fn is_negative(&self) -> bool { false }
|
||||||
pure fn is_nonpositive(&self) -> bool { self.is_zero() }
|
pure fn is_nonpositive(&self) -> bool { self.is_zero() }
|
||||||
|
@ -599,7 +599,7 @@ pub mod bytepipes {
|
|||||||
} else if self.buf.is_empty() {
|
} else if self.buf.is_empty() {
|
||||||
match self.port.try_recv() {
|
match self.port.try_recv() {
|
||||||
Some(move buf) => {
|
Some(move buf) => {
|
||||||
assert buf.is_not_empty();
|
assert !buf.is_empty();
|
||||||
self.buf = move buf;
|
self.buf = move buf;
|
||||||
return self.try_recv(count);
|
return self.try_recv(count);
|
||||||
}
|
}
|
||||||
@ -904,7 +904,7 @@ mod test {
|
|||||||
fn pipe_port_loader(bytes: ~[u8]
|
fn pipe_port_loader(bytes: ~[u8]
|
||||||
) -> pod::PipePort<int> {
|
) -> pod::PipePort<int> {
|
||||||
let (port, chan) = pipes::stream();
|
let (port, chan) = pipes::stream();
|
||||||
if bytes.is_not_empty() {
|
if !bytes.is_empty() {
|
||||||
chan.send(move bytes);
|
chan.send(move bytes);
|
||||||
}
|
}
|
||||||
pod::pipe_port(move port)
|
pod::pipe_port(move port)
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* fn main(args: ~[str]) {
|
* fn main(args: ~[str]) {
|
||||||
* check vec::is_not_empty(args);
|
* check !args.is_empty()
|
||||||
*
|
*
|
||||||
* let program : str = vec::head(args);
|
* let program : str = vec::head(args);
|
||||||
*
|
*
|
||||||
@ -63,7 +63,7 @@
|
|||||||
* return;
|
* return;
|
||||||
* }
|
* }
|
||||||
* let output = opt_maybe_str(matches, "o");
|
* let output = opt_maybe_str(matches, "o");
|
||||||
* let input = if vec::is_not_empty(matches.free) {
|
* let input = if !matches.free.is_empty() {
|
||||||
* matches.free[0]
|
* matches.free[0]
|
||||||
* } else {
|
* } else {
|
||||||
* print_usage(program);
|
* print_usage(program);
|
||||||
@ -357,7 +357,7 @@ fn opt_val(mm: &Matches, nm: &str) -> Optval { return opt_vals(mm, nm)[0]; }
|
|||||||
|
|
||||||
/// Returns true if an option was matched
|
/// Returns true if an option was matched
|
||||||
pub fn opt_present(mm: &Matches, nm: &str) -> bool {
|
pub fn opt_present(mm: &Matches, nm: &str) -> bool {
|
||||||
opt_vals(mm, nm).is_not_empty()
|
!opt_vals(mm, nm).is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of times an option was matched
|
/// Returns the number of times an option was matched
|
||||||
|
@ -83,11 +83,6 @@ pub pure fn is_empty<T: Copy>(ls: @List<T>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the list is not empty
|
|
||||||
pub pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
|
|
||||||
return !is_empty(ls);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the length of a list
|
/// Returns the length of a list
|
||||||
pub pure fn len<T>(ls: @List<T>) -> uint {
|
pub pure fn len<T>(ls: @List<T>) -> uint {
|
||||||
let mut count = 0u;
|
let mut count = 0u;
|
||||||
@ -177,10 +172,6 @@ mod tests {
|
|||||||
assert is_empty(empty);
|
assert is_empty(empty);
|
||||||
assert !is_empty(full1);
|
assert !is_empty(full1);
|
||||||
assert !is_empty(full2);
|
assert !is_empty(full2);
|
||||||
|
|
||||||
assert !is_not_empty(empty);
|
|
||||||
assert is_not_empty(full1);
|
|
||||||
assert is_not_empty(full2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -245,7 +245,7 @@ fn contains_name(metas: &[@ast::meta_item], name: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool {
|
fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool {
|
||||||
vec::is_not_empty(find_attrs_by_name(attrs, name))
|
!find_attrs_by_name(attrs, name).is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: ~str)
|
fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: ~str)
|
||||||
|
@ -192,7 +192,7 @@ fn diagnosticcolor(lvl: level) -> u8 {
|
|||||||
fn print_diagnostic(topic: ~str, lvl: level, msg: &str) {
|
fn print_diagnostic(topic: ~str, lvl: level, msg: &str) {
|
||||||
let use_color = term::color_supported() &&
|
let use_color = term::color_supported() &&
|
||||||
io::stderr().get_type() == io::Screen;
|
io::stderr().get_type() == io::Screen;
|
||||||
if str::is_not_empty(topic) {
|
if !topic.is_empty() {
|
||||||
io::stderr().write_str(fmt!("%s ", topic));
|
io::stderr().write_str(fmt!("%s ", topic));
|
||||||
}
|
}
|
||||||
if use_color {
|
if use_color {
|
||||||
|
@ -2237,7 +2237,7 @@ impl Parser {
|
|||||||
|
|
||||||
fn check_expected_item(p: Parser, current_attrs: ~[attribute]) {
|
fn check_expected_item(p: Parser, current_attrs: ~[attribute]) {
|
||||||
// If we have attributes then we should have an item
|
// If we have attributes then we should have an item
|
||||||
if vec::is_not_empty(current_attrs) {
|
if !current_attrs.is_empty() {
|
||||||
p.fatal(~"expected item after attrs");
|
p.fatal(~"expected item after attrs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ fn print_item(s: ps, &&item: @ast::item) {
|
|||||||
|
|
||||||
ast::item_impl(tps, opt_trait, ty, methods) => {
|
ast::item_impl(tps, opt_trait, ty, methods) => {
|
||||||
head(s, visibility_qualified(item.vis, ~"impl"));
|
head(s, visibility_qualified(item.vis, ~"impl"));
|
||||||
if tps.is_not_empty() {
|
if !tps.is_empty() {
|
||||||
print_type_params(s, tps);
|
print_type_params(s, tps);
|
||||||
space(s.s);
|
space(s.s);
|
||||||
}
|
}
|
||||||
@ -770,7 +770,7 @@ fn print_variant(s: ps, v: ast::variant) {
|
|||||||
match v.node.kind {
|
match v.node.kind {
|
||||||
ast::tuple_variant_kind(args) => {
|
ast::tuple_variant_kind(args) => {
|
||||||
print_ident(s, v.node.name);
|
print_ident(s, v.node.name);
|
||||||
if args.is_not_empty() {
|
if !args.is_empty() {
|
||||||
popen(s);
|
popen(s);
|
||||||
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
|
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
|
||||||
print_type(s, arg.ty);
|
print_type(s, arg.ty);
|
||||||
@ -1054,7 +1054,7 @@ fn print_call_post(s: ps,
|
|||||||
has_block: bool,
|
has_block: bool,
|
||||||
blk: &Option<@ast::expr>,
|
blk: &Option<@ast::expr>,
|
||||||
base_args: &mut ~[@ast::expr]) {
|
base_args: &mut ~[@ast::expr]) {
|
||||||
if !has_block || base_args.is_not_empty() {
|
if !has_block || !base_args.is_empty() {
|
||||||
popen(s);
|
popen(s);
|
||||||
commasep_exprs(s, inconsistent, *base_args);
|
commasep_exprs(s, inconsistent, *base_args);
|
||||||
pclose(s);
|
pclose(s);
|
||||||
@ -1564,7 +1564,7 @@ fn print_pat(s: ps, &&pat: @ast::pat, refutable: bool) {
|
|||||||
match args_ {
|
match args_ {
|
||||||
None => word(s.s, ~"(*)"),
|
None => word(s.s, ~"(*)"),
|
||||||
Some(args) => {
|
Some(args) => {
|
||||||
if args.is_not_empty() {
|
if !args.is_empty() {
|
||||||
popen(s);
|
popen(s);
|
||||||
commasep(s, inconsistent, args,
|
commasep(s, inconsistent, args,
|
||||||
|s, p| print_pat(s, p, refutable));
|
|s, p| print_pat(s, p, refutable));
|
||||||
@ -1762,7 +1762,7 @@ fn print_arg_mode(s: ps, m: ast::mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
|
fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
|
||||||
if bounds.is_not_empty() {
|
if !bounds.is_empty() {
|
||||||
word(s.s, ~":");
|
word(s.s, ~":");
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for vec::each(*bounds) |&bound| {
|
for vec::each(*bounds) |&bound| {
|
||||||
@ -1855,7 +1855,7 @@ fn print_view_item(s: ps, item: @ast::view_item) {
|
|||||||
ast::view_item_use(id, mta, _) => {
|
ast::view_item_use(id, mta, _) => {
|
||||||
head(s, ~"extern mod");
|
head(s, ~"extern mod");
|
||||||
print_ident(s, id);
|
print_ident(s, id);
|
||||||
if mta.is_not_empty() {
|
if !mta.is_empty() {
|
||||||
popen(s);
|
popen(s);
|
||||||
commasep(s, consistent, mta, print_meta_item);
|
commasep(s, consistent, mta, print_meta_item);
|
||||||
pclose(s);
|
pclose(s);
|
||||||
@ -2101,7 +2101,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) {
|
|||||||
for cmnt.lines.each |line| {
|
for cmnt.lines.each |line| {
|
||||||
// Don't print empty lines because they will end up as trailing
|
// Don't print empty lines because they will end up as trailing
|
||||||
// whitespace
|
// whitespace
|
||||||
if str::is_not_empty(*line) { word(s.s, *line); }
|
if !line.is_empty() { word(s.s, *line); }
|
||||||
hardbreak(s.s);
|
hardbreak(s.s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2113,7 +2113,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) {
|
|||||||
} else {
|
} else {
|
||||||
ibox(s, 0u);
|
ibox(s, 0u);
|
||||||
for cmnt.lines.each |line| {
|
for cmnt.lines.each |line| {
|
||||||
if str::is_not_empty(*line) { word(s.s, *line); }
|
if !line.is_empty() { word(s.s, *line); }
|
||||||
hardbreak(s.s);
|
hardbreak(s.s);
|
||||||
}
|
}
|
||||||
end(s);
|
end(s);
|
||||||
|
@ -23,7 +23,7 @@ pure fn pure_length<T: Copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
|
|||||||
pure fn nonempty_list<T: Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
pure fn nonempty_list<T: Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
||||||
|
|
||||||
fn safe_head<T: Copy>(ls: @List<T>) -> T {
|
fn safe_head<T: Copy>(ls: @List<T>) -> T {
|
||||||
assert is_not_empty(ls);
|
assert !is_empty(ls);
|
||||||
return head(ls);
|
return head(ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
// In this case, the code should compile and should
|
// In this case, the code should compile and should
|
||||||
// succeed at runtime
|
// succeed at runtime
|
||||||
use vec::{head, is_not_empty, last, same_length, zip};
|
use vec::{head, last, same_length, zip};
|
||||||
|
|
||||||
fn enum_chars(start: u8, end: u8) -> ~[char] {
|
fn enum_chars(start: u8, end: u8) -> ~[char] {
|
||||||
assert start < end;
|
assert start < end;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user