@@ -735,9 +735,12 @@ of numeric literal patterns can be expressed with `to`. The underscore
735
735
(` _ ` ) is a wildcard pattern that matches everything.
736
736
737
737
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.)
741
744
742
745
A powerful application of pattern matching is * destructuring* , where
743
746
you use the matching to get at the contents of data types. Remember
@@ -2500,8 +2503,8 @@ impl <T> of seq<T> for ~[T] {
2500
2503
}
2501
2504
~~~~
2502
2505
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
2505
2508
needed because it could also, for example, specify an implementation
2506
2509
of ` seq<int> ` —the ` of ` clause * refers* to a type, rather than defining
2507
2510
one.
@@ -2621,9 +2624,10 @@ OpenSSL libraries installed, it should 'just work'.
2621
2624
2622
2625
~~~~ {.xfail-test}
2623
2626
use std;
2627
+ import libc::c_uint;
2624
2628
2625
2629
extern mod crypto {
2626
- fn SHA1(src: *u8, sz: uint , out: *u8) -> *u8;
2630
+ fn SHA1(src: *u8, sz: c_uint , out: *u8) -> *u8;
2627
2631
}
2628
2632
2629
2633
fn as_hex(data: ~[u8]) -> ~str {
@@ -2635,7 +2639,7 @@ fn as_hex(data: ~[u8]) -> ~str {
2635
2639
fn sha1(data: ~str) -> ~str unsafe {
2636
2640
let bytes = str::bytes(data);
2637
2641
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
2638
- vec::len(bytes), ptr::null());
2642
+ vec::len(bytes) as c_uint , ptr::null());
2639
2643
ret as_hex(vec::unsafe::from_buf(hash, 20u));
2640
2644
}
2641
2645
@@ -2701,7 +2705,7 @@ return a pointer.
2701
2705
2702
2706
~~~~ {.xfail-test}
2703
2707
# 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;
2705
2709
# }
2706
2710
~~~~
2707
2711
@@ -2792,7 +2796,7 @@ This pointer will become invalid as soon as the vector it points into
2792
2796
is cleaned up, so you should be very careful how you use it. In this
2793
2797
case, the local variable ` bytes ` outlives the pointer, so we're good.
2794
2798
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
2796
2800
static buffer, and thus save us the effort of allocating memory
2797
2801
ourselves. ` ptr::null ` is a generic function that will return an
2798
2802
unsafe null pointer of the correct type (Rust generics are awesome
@@ -2815,15 +2819,17 @@ microsecond-resolution timer.
2815
2819
2816
2820
~~~~
2817
2821
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};
2820
2826
#[nolink]
2821
- extern mod libc {
2827
+ extern mod lib_c {
2822
2828
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
2823
2829
}
2824
2830
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());
2827
2833
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
2828
2834
}
2829
2835
@@ -2839,8 +2845,8 @@ define a record type with the same contents, and declare
2839
2845
2840
2846
The second argument to ` gettimeofday ` (the time zone) is not used by
2841
2847
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.
2844
2850
2845
2851
# Tasks
2846
2852
0 commit comments