Skip to content

Commit 4463172

Browse files
committed
Tutorial fixes
Closes #3032 Closes #3031 Closes #3030 Closes #3028
1 parent afd9a75 commit 4463172

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

doc/tutorial.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,12 @@ of numeric literal patterns can be expressed with `to`. The underscore
735735
(`_`) is a wildcard pattern that matches everything.
736736

737737
If the arm with the wildcard pattern was left off in the above
738-
example, running it on a number greater than ten (or negative) would
739-
cause a run-time failure. When no arm matches, `alt` constructs do not
740-
silently fall through—they blow up instead.
738+
example, the typechecker would reject it at compile time. `alt`
739+
constructs must be exhaustive: they must have an arm covering every
740+
possible case. (You may use the `alt check` construct to write a
741+
non-exhaustive match, but it's highly undesirable to do so. You may
742+
reason that the missing cases will never occur, but the typechecker
743+
provides you with no assurance that your reasoning is correct.)
741744

742745
A powerful application of pattern matching is *destructuring*, where
743746
you use the matching to get at the contents of data types. Remember
@@ -2500,8 +2503,8 @@ impl <T> of seq<T> for ~[T] {
25002503
}
25012504
~~~~
25022505

2503-
Note that the implementation has to explicitly declare the its
2504-
parameter `T` before using it to specify its trait type. This is
2506+
Note that the implementation has to explicitly declare the type
2507+
parameter that it binds, `T`, before using it to specify its trait type. This is
25052508
needed because it could also, for example, specify an implementation
25062509
of `seq<int>`—the `of` clause *refers* to a type, rather than defining
25072510
one.
@@ -2621,9 +2624,10 @@ OpenSSL libraries installed, it should 'just work'.
26212624

26222625
~~~~ {.xfail-test}
26232626
use std;
2627+
import libc::c_uint;
26242628
26252629
extern mod crypto {
2626-
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
2630+
fn SHA1(src: *u8, sz: c_uint, out: *u8) -> *u8;
26272631
}
26282632
26292633
fn as_hex(data: ~[u8]) -> ~str {
@@ -2635,7 +2639,7 @@ fn as_hex(data: ~[u8]) -> ~str {
26352639
fn sha1(data: ~str) -> ~str unsafe {
26362640
let bytes = str::bytes(data);
26372641
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
2638-
vec::len(bytes), ptr::null());
2642+
vec::len(bytes) as c_uint, ptr::null());
26392643
ret as_hex(vec::unsafe::from_buf(hash, 20u));
26402644
}
26412645
@@ -2701,7 +2705,7 @@ return a pointer.
27012705

27022706
~~~~ {.xfail-test}
27032707
# extern mod crypto {
2704-
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
2708+
fn SHA1(src: *u8, sz: libc::c_uint, out: *u8) -> *u8;
27052709
# }
27062710
~~~~
27072711

@@ -2792,7 +2796,7 @@ This pointer will become invalid as soon as the vector it points into
27922796
is cleaned up, so you should be very careful how you use it. In this
27932797
case, the local variable `bytes` outlives the pointer, so we're good.
27942798

2795-
Passing a null pointer as third argument to `SHA1` causes it to use a
2799+
Passing a null pointer as the third argument to `SHA1` makes it use a
27962800
static buffer, and thus save us the effort of allocating memory
27972801
ourselves. `ptr::null` is a generic function that will return an
27982802
unsafe null pointer of the correct type (Rust generics are awesome
@@ -2815,15 +2819,17 @@ microsecond-resolution timer.
28152819

28162820
~~~~
28172821
use std;
2818-
type timeval = {mut tv_sec: uint,
2819-
mut tv_usec: uint};
2822+
import libc::c_ulonglong;
2823+
2824+
type timeval = {mut tv_sec: c_ulonglong,
2825+
mut tv_usec: c_ulonglong};
28202826
#[nolink]
2821-
extern mod libc {
2827+
extern mod lib_c {
28222828
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
28232829
}
28242830
fn unix_time_in_microseconds() -> u64 unsafe {
2825-
let x = {mut tv_sec: 0u, mut tv_usec: 0u};
2826-
libc::gettimeofday(ptr::addr_of(x), ptr::null());
2831+
let x = {mut tv_sec: 0 as c_ulonglong, mut tv_usec: 0 as c_ulonglong};
2832+
lib_c::gettimeofday(ptr::addr_of(x), ptr::null());
28272833
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
28282834
}
28292835
@@ -2839,8 +2845,8 @@ define a record type with the same contents, and declare
28392845

28402846
The second argument to `gettimeofday` (the time zone) is not used by
28412847
this program, so it simply declares it to be a pointer to the nil
2842-
type. Since null pointer look the same, no matter which type they are
2843-
supposed to point at, this is safe.
2848+
type. Since all null pointers have the same representation regardless of
2849+
their referent type, this is safe.
28442850

28452851
# Tasks
28462852

0 commit comments

Comments
 (0)