Skip to content

Commit

Permalink
Merge pull request #3308 from killerswan/modes7
Browse files Browse the repository at this point in the history
Remove deprecated modes
  • Loading branch information
brson committed Aug 31, 2012
2 parents 3cd54ab + 7d57b48 commit afc1ccd
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 49 deletions.
22 changes: 12 additions & 10 deletions src/libstd/cmp.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
#[deny(non_camel_case_types)];
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
/// Additional general-purpose comparison functionality.

const fuzzy_epsilon: float = 1.0e-6;

trait FuzzyEq {
pure fn fuzzy_eq(&&other: self) -> bool;
pure fn fuzzy_eq(other: &self) -> bool;
}

impl float: FuzzyEq {
pure fn fuzzy_eq(&&other: float) -> bool {
return float::abs(self - other) < fuzzy_epsilon;
pure fn fuzzy_eq(other: &float) -> bool {
return float::abs(self - *other) < fuzzy_epsilon;
}
}

impl f32: FuzzyEq {
pure fn fuzzy_eq(&&other: f32) -> bool {
return f32::abs(self - other) < (fuzzy_epsilon as f32);
pure fn fuzzy_eq(other: &f32) -> bool {
return f32::abs(self - *other) < (fuzzy_epsilon as f32);
}
}

impl f64: FuzzyEq {
pure fn fuzzy_eq(&&other: f64) -> bool {
return f64::abs(self - other) < (fuzzy_epsilon as f64);
pure fn fuzzy_eq(other: &f64) -> bool {
return f64::abs(self - *other) < (fuzzy_epsilon as f64);
}
}

#[test]
fn test_fuzzy_equals() {
assert ((1.0).fuzzy_eq(1.0));
assert ((1.0f32).fuzzy_eq(1.0f32));
assert ((1.0f64).fuzzy_eq(1.0f64));
assert ((&1.0).fuzzy_eq(&1.0));
assert ((&1.0f32).fuzzy_eq(&1.0f32));
assert ((&1.0f64).fuzzy_eq(&1.0f64));
}

8 changes: 5 additions & 3 deletions src/libstd/dbg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[deny(non_camel_case_types)];
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
//! Unsafe debugging functions for inspecting values.

import unsafe::reinterpret_cast;
Expand Down Expand Up @@ -26,19 +28,19 @@ fn debug_tydesc<T>() {
rustrt::debug_tydesc(sys::get_type_desc::<T>());
}

fn debug_opaque<T>(x: T) {
fn debug_opaque<T>(+x: T) {
rustrt::debug_opaque(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
}

fn debug_box<T>(x: @T) {
rustrt::debug_box(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
}

fn debug_tag<T>(x: T) {
fn debug_tag<T>(+x: T) {
rustrt::debug_tag(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
}

fn debug_fn<T>(x: T) {
fn debug_fn<T>(+x: T) {
rustrt::debug_fn(sys::get_type_desc::<T>(), ptr::addr_of(x) as *());
}

Expand Down
36 changes: 23 additions & 13 deletions src/libstd/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! A standard linked list
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

import core::cmp::Eq;
import core::option;
Expand Down Expand Up @@ -28,9 +30,9 @@ fn from_vec<T: copy>(v: &[T]) -> @list<T> {
* * z - The initial value
* * f - The function to apply
*/
fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
fn foldl<T: copy, U>(+z: T, ls: @list<U>, f: fn((&T), (&U)) -> T) -> T {
let mut accum: T = z;
do iter(ls) |elt| { accum = f(accum, elt);}
do iter(ls) |elt| { accum = f(&accum, &elt);}
accum
}

Expand All @@ -41,12 +43,12 @@ fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
fn find<T: copy>(ls: @list<T>, f: fn((&T)) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
cons(hd, tl) => {
if f(hd) { return Some(hd); }
if f(&hd) { return Some(hd); }
tl
}
nil => return None
Expand All @@ -55,7 +57,7 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
}

/// Returns true if a list contains an element with the given value
fn has<T: copy Eq>(ls: @list<T>, elt: T) -> bool {
fn has<T: copy Eq>(ls: @list<T>, +elt: T) -> bool {
for each(ls) |e| {
if e == elt { return true; }
}
Expand Down Expand Up @@ -110,10 +112,13 @@ pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
}
}

/// Push an element to the front of a list
fn push<T: copy>(&l: list<T>, v: T) {
l = cons(v, @l);
/*
/// Push one element into the front of a list, returning a new list
/// THIS VERSION DOESN'T ACTUALLY WORK
pure fn push<T: copy>(ll: &mut @list<T>, +vv: T) {
ll = &mut @cons(vv, *ll)
}
*/

/// Iterate over a list
fn iter<T>(l: @list<T>, f: fn(T)) {
Expand Down Expand Up @@ -201,7 +206,7 @@ mod tests {

#[test]
fn test_foldl() {
fn add(&&a: uint, &&b: int) -> uint { return a + (b as uint); }
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
let l = from_vec(~[0, 1, 2, 3, 4]);
let empty = @list::nil::<int>;
assert (list::foldl(0u, l, add) == 10u);
Expand All @@ -210,23 +215,23 @@ mod tests {

#[test]
fn test_foldl2() {
fn sub(&&a: int, &&b: int) -> int {
a - b
fn sub(a: &int, b: &int) -> int {
*a - *b
}
let l = from_vec(~[1, 2, 3, 4]);
assert (list::foldl(0, l, sub) == -10);
}

#[test]
fn test_find_success() {
fn match_(&&i: int) -> bool { return i == 2; }
fn match_(i: &int) -> bool { return *i == 2; }
let l = from_vec(~[0, 1, 2]);
assert (list::find(l, match_) == option::Some(2));
}

#[test]
fn test_find_fail() {
fn match_(&&_i: int) -> bool { return false; }
fn match_(_i: &int) -> bool { return false; }
let l = from_vec(~[0, 1, 2]);
let empty = @list::nil::<int>;
assert (list::find(l, match_) == option::None::<int>);
Expand All @@ -251,6 +256,11 @@ mod tests {
assert (list::len(empty) == 0u);
}

#[test]
fn test_append() {
assert from_vec(~[1,2,3,4])
== list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]));
}
}

// Local Variables:
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/prettyprint.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

import io::Writer;
import io::WriterUtil;
import serialization::serializer;
Expand Down
46 changes: 24 additions & 22 deletions src/libstd/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* * access to a character by index is logarithmic (linear in strings);
*/

#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

/// The type of ropes.
type rope = node::root;
Expand Down Expand Up @@ -436,7 +438,7 @@ mod iterator {
node::content(x) => return node::leaf_iterator::start(x)
}
}
fn next(it: node::leaf_iterator::t) -> Option<node::leaf> {
fn next(it: &node::leaf_iterator::t) -> Option<node::leaf> {
return node::leaf_iterator::next(it);
}
}
Expand All @@ -447,7 +449,7 @@ mod iterator {
node::content(x) => return node::char_iterator::start(x)
}
}
fn next(it: node::char_iterator::t) -> Option<char> {
fn next(it: &node::char_iterator::t) -> Option<char> {
return node::char_iterator::next(it)
}
}
Expand Down Expand Up @@ -751,7 +753,7 @@ mod node {
* * forest - The forest. This vector is progressively rewritten during
* execution and should be discarded as meaningless afterwards.
*/
fn tree_from_forest_destructive(forest: ~[mut @node]) -> @node {
fn tree_from_forest_destructive(forest: &[mut @node]) -> @node {
let mut i;
let mut len = vec::len(forest);
while len > 1u {
Expand Down Expand Up @@ -800,7 +802,7 @@ mod node {
let mut offset = 0u;//Current position in the buffer
let it = leaf_iterator::start(node);
loop {
match (leaf_iterator::next(it)) {
match (leaf_iterator::next(&it)) {
option::None => break,
option::Some(x) => {
//FIXME (#2744): Replace with memcpy or something similar
Expand Down Expand Up @@ -861,7 +863,7 @@ mod node {
let mut forest = ~[mut];
let it = leaf_iterator::start(node);
loop {
match (leaf_iterator::next(it)) {
match (leaf_iterator::next(&it)) {
option::None => break,
option::Some(x) => vec::push(forest, @leaf(x))
}
Expand Down Expand Up @@ -1018,7 +1020,7 @@ mod node {
let itb = char_iterator::start(b);
let mut result = 0;
while result == 0 {
match ((char_iterator::next(ita), char_iterator::next(itb))) {
match ((char_iterator::next(&ita), char_iterator::next(&itb))) {
(option::None, option::None) => break,
(option::Some(chara), option::Some(charb)) => {
result = char::cmp(chara, charb);
Expand Down Expand Up @@ -1121,7 +1123,7 @@ mod node {
}
}

fn next(it: t) -> Option<leaf> {
fn next(it: &t) -> Option<leaf> {
if it.stackpos < 0 { return option::None; }
loop {
let current = it.stack[it.stackpos];
Expand Down Expand Up @@ -1162,7 +1164,7 @@ mod node {
}
}

fn next(it: t) -> Option<char> {
fn next(it: &t) -> Option<char> {
loop {
match (get_current_or_next_leaf(it)) {
option::None => return option::None,
Expand All @@ -1177,36 +1179,36 @@ mod node {
};
}

fn get_current_or_next_leaf(it: t) -> Option<leaf> {
match (it.leaf) {
option::Some(_) => return it.leaf,
fn get_current_or_next_leaf(it: &t) -> Option<leaf> {
match ((*it).leaf) {
option::Some(_) => return (*it).leaf,
option::None => {
let next = leaf_iterator::next(it.leaf_iterator);
let next = leaf_iterator::next(&((*it).leaf_iterator));
match (next) {
option::None => return option::None,
option::Some(_) => {
it.leaf = next;
it.leaf_byte_pos = 0u;
(*it).leaf = next;
(*it).leaf_byte_pos = 0u;
return next;
}
}
}
}
}

fn get_next_char_in_leaf(it: t) -> Option<char> {
match copy it.leaf {
fn get_next_char_in_leaf(it: &t) -> Option<char> {
match copy (*it).leaf {
option::None => return option::None,
option::Some(aleaf) => {
if it.leaf_byte_pos >= aleaf.byte_len {
if (*it).leaf_byte_pos >= aleaf.byte_len {
//We are actually past the end of the leaf
it.leaf = option::None;
(*it).leaf = option::None;
return option::None
} else {
let {ch, next} =
str::char_range_at(*aleaf.content,
it.leaf_byte_pos + aleaf.byte_offset);
it.leaf_byte_pos = next - aleaf.byte_offset;
(*it).leaf_byte_pos + aleaf.byte_offset);
(*it).leaf_byte_pos = next - aleaf.byte_offset;
return option::Some(ch)
}
}
Expand Down Expand Up @@ -1274,7 +1276,7 @@ mod tests {
let rope_iter = iterator::char::start(r);
let mut equal = true;
while equal {
match (node::char_iterator::next(rope_iter)) {
match (node::char_iterator::next(&rope_iter)) {
option::None => {
if string_iter < string_len {
equal = false;
Expand All @@ -1301,7 +1303,7 @@ mod tests {
let mut len = 0u;
let it = iterator::char::start(r);
loop {
match (node::char_iterator::next(it)) {
match (node::char_iterator::next(&it)) {
option::None => break,
option::Some(_) => len += 1u
}
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/tempfile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Temporary files and directories

#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

import core::option;
import option::{None, Some};
import rand;
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _)
| ty::ty_trait(_, _, _) => false,
ty::ty_enum(did, substs) => {
if option::is_none(list::find(enums_seen, |id| id == did)) {
if option::is_none(list::find(enums_seen, |id| *id == did)) {
let seen = @cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| {
Expand Down

0 comments on commit afc1ccd

Please sign in to comment.