Skip to content

Commit bfbaadc

Browse files
committed
core: marked fns as pure where possible
1 parent 1fe4bd0 commit bfbaadc

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

src/libcore/bool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Returns:
123123
124124
An u8 whose first bit is set if `if_true(v)` holds
125125
*/
126-
fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
126+
pure fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
127127

128128
// Local Variables:
129129
// mode: rust;

src/libcore/box.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Function: ptr_eq
1010
1111
Determine if two shared boxes point to the same object
1212
*/
13-
fn ptr_eq<T>(a: @T, b: @T) -> bool {
13+
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
1414
// FIXME: ptr::addr_of
1515
unsafe {
1616
let a_ptr: uint = unsafe::reinterpret_cast(a);

src/libcore/char.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pure fn to_digit(c: char) -> u8 unsafe {
122122
Convert a char to the corresponding digit. Returns none when the
123123
character is not a valid hexadecimal digit.
124124
*/
125-
fn maybe_digit(c: char) -> option::t<u8> {
125+
pure fn maybe_digit(c: char) -> option::t<u8> {
126126
alt c {
127127
'0' to '9' { option::some(c as u8 - ('0' as u8)) }
128128
'a' to 'z' { option::some(c as u8 + 10u8 - ('a' as u8)) }
@@ -143,7 +143,7 @@ fn maybe_digit(c: char) -> option::t<u8> {
143143
Returns:
144144
-1 if a<b, 0 if a==b, +1 if a>b
145145
*/
146-
fn cmp(a: char, b: char) -> int {
146+
pure fn cmp(a: char, b: char) -> int {
147147
ret if b > a { -1 }
148148
else if b < a { 1 }
149149
else { 0 }

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Failure:
3030
3131
Fails if the value equals `none`.
3232
*/
33-
fn get<copy T>(opt: t<T>) -> T {
33+
pure fn get<copy T>(opt: t<T>) -> T {
3434
alt opt { some(x) { ret x; } none. { fail "option none"; } }
3535
}
3636

@@ -61,7 +61,7 @@ Function: from_maybe
6161
6262
Returns the contained value or a default
6363
*/
64-
fn from_maybe<T>(def: T, opt: t<T>) -> T {
64+
pure fn from_maybe<T>(def: T, opt: t<T>) -> T {
6565
alt opt { some(x) { x } none. { def } }
6666
}
6767

src/libcore/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Function: eq
2626
2727
Bytewise string equality
2828
*/
29-
fn eq(&&a: str, &&b: str) -> bool { a == b }
29+
pure fn eq(&&a: str, &&b: str) -> bool { a == b }
3030

3131
/*
3232
Function: lteq
3333
3434
Bytewise less than or equal
3535
*/
36-
fn lteq(&&a: str, &&b: str) -> bool { a <= b }
36+
pure fn lteq(&&a: str, &&b: str) -> bool { a <= b }
3737

3838
/*
3939
Function: hash
@@ -131,7 +131,7 @@ Function: byte_len
131131
132132
Returns the length in bytes of a string
133133
*/
134-
fn byte_len(s: str) -> uint unsafe {
134+
pure fn byte_len(s: str) -> uint unsafe {
135135
let v: [u8] = unsafe::reinterpret_cast(s);
136136
let vlen = vec::len(v);
137137
unsafe::leak(v);
@@ -261,7 +261,7 @@ Function: utf8_char_width
261261
262262
FIXME: What does this function do?
263263
*/
264-
fn utf8_char_width(b: u8) -> uint {
264+
pure fn utf8_char_width(b: u8) -> uint {
265265
let byte: uint = b as uint;
266266
if byte < 128u { ret 1u; }
267267
if byte < 192u {

src/libcore/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Function: last_os_error
4242
Get a string representing the platform-dependent last error
4343
*/
4444
fn last_os_error() -> str {
45-
ret rustrt::last_os_error();
45+
rustrt::last_os_error()
4646
}
4747

4848
/*

src/libcore/vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Returns the first element of a vector
181181
Predicates:
182182
<is_not_empty> (v)
183183
*/
184-
fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
184+
pure fn head<copy T>(v: [const T]) : is_not_empty(v) -> T { ret v[0]; }
185185

186186
/*
187187
Function: tail
@@ -221,7 +221,7 @@ Returns:
221221
An option containing the last element of `v` if `v` is not empty, or
222222
none if `v` is empty.
223223
*/
224-
fn last<copy T>(v: [const T]) -> option::t<T> {
224+
pure fn last<copy T>(v: [const T]) -> option::t<T> {
225225
if len(v) == 0u { ret none; }
226226
ret some(v[len(v) - 1u]);
227227
}
@@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v`
234234
Predicates:
235235
<is_not_empty> (v)
236236
*/
237-
fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
237+
pure fn last_total<copy T>(v: [const T]) : is_not_empty(v) -> T {
238238
ret v[len(v) - 1u];
239239
}
240240

0 commit comments

Comments
 (0)