Skip to content

Mark some more core and std functions as pure #4261

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions src/libcore/dvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ pub pure fn DVec<A>() -> DVec<A> {
}

/// Creates a new dvec with a single element
pub fn from_elem<A>(e: A) -> DVec<A> {
pub pure fn from_elem<A>(e: A) -> DVec<A> {
DVec {mut data: ~[move e]}
}

/// Creates a new dvec with the contents of a vector
pub fn from_vec<A>(v: ~[A]) -> DVec<A> {
pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> {
DVec {mut data: move v}
}

/// Consumes the vector and returns its contents
pub fn unwrap<A>(d: DVec<A>) -> ~[A] {
pub pure fn unwrap<A>(d: DVec<A>) -> ~[A] {
let DVec {data: v} = move d;
move v
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
* * num - The float value
* * digits - The number of significant digits
*/
pub fn to_str_exact(num: float, digits: uint) -> ~str {
pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
to_str_common(num, digits, true)
}

Expand Down Expand Up @@ -238,7 +238,7 @@ pub pure fn to_str(num: float, digits: uint) -> ~str {
* `none` if the string did not represent a valid number. Otherwise,
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
*/
pub fn from_str(num: &str) -> Option<float> {
pub pure fn from_str(num: &str) -> Option<float> {
if num == "inf" {
return Some(infinity as float);
} else if num == "-inf" {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/int-template/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ mod inst {
pub const bits: uint = uint::bits;

/// Returns `base` raised to the power of `exponent`
pub fn pow(base: int, exponent: uint) -> int {
pub pure fn pow(base: int, exponent: uint) -> int {
if exponent == 0u {
//Not mathemtically true if ~[base == 0]
return 1;
}
if base == 0 { return 0; }
if base == 0 { return 0; }
let mut my_pow = exponent;
let mut acc = 1;
let mut multiplier = base;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
(I couldn't think of a cutesy name for this one.)
*/
#[inline(always)]
pub fn to_uint<T>(thing: &T) -> uint unsafe {
pub pure fn to_uint<T>(thing: &T) -> uint unsafe {
cast::reinterpret_cast(&thing)
}

/// Determine if two borrowed pointers point to the same thing.
#[inline(always)]
pub fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
to_uint(thing) == to_uint(other)
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ impl XorShiftState: Rng {
}
}

pub fn xorshift() -> Rng {
pub pure fn xorshift() -> Rng {
// constants taken from http://en.wikipedia.org/wiki/Xorshift
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
}

pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng {
{mut x: x, mut y: y, mut z: z, mut w: w} as Rng
}

Expand Down
6 changes: 2 additions & 4 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub pure fn connect(v: &[~str], sep: &str) -> ~str {
}

/// Given a string, make a new string with repeated copies of it
pub fn repeat(ss: &str, nn: uint) -> ~str {
pub pure fn repeat(ss: &str, nn: uint) -> ~str {
let mut acc = ~"";
for nn.times { acc += ss; }
acc
Expand Down Expand Up @@ -1684,9 +1684,7 @@ pub struct CharRange {
*
* This function can be used to iterate over a unicode string in reverse.
*/
pure fn char_range_at_reverse(ss: &str, start: uint)
-> CharRange {

pure fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
let mut prev = start;

// while there is a previous byte == 10......
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/uint-template/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod inst {

/// Returns the smallest power of 2 greater than or equal to `n`
#[inline(always)]
pub fn next_power_of_two(n: uint) -> uint {
pub pure fn next_power_of_two(n: uint) -> uint {
let halfbits: uint = sys::size_of::<uint>() * 4u;
let mut tmp: uint = n - 1u;
let mut shift: uint = 1u;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn Arena() -> Arena {
}

#[inline(always)]
fn round_up_to(base: uint, align: uint) -> uint {
pure fn round_up_to(base: uint, align: uint) -> uint {
(base + (align - 1)) & !(align - 1)
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/c_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
*/

/// Returns the length of the vector
pub fn len<T>(t: CVec<T>) -> uint {
pub pure fn len<T>(t: CVec<T>) -> uint {
return (*t).len;
}

Expand Down
12 changes: 6 additions & 6 deletions src/libstd/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub enum List<T> {
Nil,
}

/// Cregate a list from a vector
pub fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
/// Create a list from a vector
pub pure fn from_vec<T: Copy>(v: &[T]) -> @List<T> {
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
}

Expand Down Expand Up @@ -53,7 +53,7 @@ pub 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.
*/
pub fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
pub pure fn find<T: Copy>(ls: @List<T>, f: fn(&T) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
Expand Down Expand Up @@ -88,7 +88,7 @@ pub pure fn is_not_empty<T: Copy>(ls: @List<T>) -> bool {
}

/// Returns the length of a list
pub fn len<T>(ls: @List<T>) -> uint {
pub pure fn len<T>(ls: @List<T>) -> uint {
let mut count = 0u;
iter(ls, |_e| count += 1u);
count
Expand Down Expand Up @@ -131,7 +131,7 @@ pure fn push<T: Copy>(ll: &mut @list<T>, vv: T) {
*/

/// Iterate over a list
pub fn iter<T>(l: @List<T>, f: fn(&T)) {
pub pure fn iter<T>(l: @List<T>, f: fn(&T)) {
let mut cur = l;
loop {
cur = match *cur {
Expand All @@ -145,7 +145,7 @@ pub fn iter<T>(l: @List<T>, f: fn(&T)) {
}

/// Iterate over a list
pub fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
pub pure fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
let mut cur = l;
loop {
cur = match *cur {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub type Rope = node::Root;
*/

/// Create an empty rope
pub fn empty() -> Rope {
pub pure fn empty() -> Rope {
return node::Empty;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ pub mod iterator {
*
* Constant time.
*/
pub fn height(rope: Rope) -> uint {
pub pure fn height(rope: Rope) -> uint {
match (rope) {
node::Empty => return 0u,
node::Content(x) => return node::height(x)
Expand Down Expand Up @@ -1019,7 +1019,7 @@ mod node {
})
}

pub fn height(node: @Node) -> uint {
pub pure fn height(node: @Node) -> uint {
match (*node) {
Leaf(_) => return 0u,
Concat(ref x) => return x.height
Expand Down Expand Up @@ -1100,7 +1100,7 @@ mod node {
* proportional to the height of the rope + the (bounded)
* length of the largest leaf.
*/
pub fn char_at(node: @Node, pos: uint) -> char {
pub pure fn char_at(node: @Node, pos: uint) -> char {
let mut node = node;
let mut pos = pos;
loop {
Expand Down