@@ -3527,8 +3527,8 @@ everyone plays by these rules. At compile time, it verifies that none of these
3527
3527
rules are broken. If our program compiles successfully, Rust can guarantee it
3528
3528
is free of data races and other memory errors, and there is no runtime overhead
3529
3529
for any of this. The borrow checker works only at compile time. If the borrow
3530
- checker did find a problem, it will report a ** lifetime error** , and your
3531
- program will refuse to compile.
3530
+ checker did find a problem, it will report an error and your program will
3531
+ refuse to compile.
3532
3532
3533
3533
That's a lot to take in. It's also one of the _ most_ important concepts in
3534
3534
all of Rust. Let's see this syntax in action:
@@ -3852,7 +3852,7 @@ the value to a name with `@`:
3852
3852
let x = 1i;
3853
3853
3854
3854
match x {
3855
- x @ 1 ... 5 => println!("got {}", x ),
3855
+ e @ 1 ... 5 => println!("got a range element {}", e ),
3856
3856
_ => println!("anything"),
3857
3857
}
3858
3858
```
@@ -3885,7 +3885,7 @@ enum OptionalInt {
3885
3885
let x = Value(5i);
3886
3886
3887
3887
match x {
3888
- Value(x ) if x > 5 => println!("Got an int bigger than five!"),
3888
+ Value(i ) if i > 5 => println!("Got an int bigger than five!"),
3889
3889
Value(..) => println!("Got an int!"),
3890
3890
Missing => println!("No such luck."),
3891
3891
}
@@ -3898,12 +3898,12 @@ with. First, `&`:
3898
3898
let x = &5i;
3899
3899
3900
3900
match x {
3901
- &x => println!("Got a value: {}", x ),
3901
+ &val => println!("Got a value: {}", val ),
3902
3902
}
3903
3903
```
3904
3904
3905
- Here, the ` x ` inside the ` match ` has type ` int ` . In other words, the left hand
3906
- side of the pattern destructures the value. If we have ` &5i ` , then in ` &x ` , ` x `
3905
+ Here, the ` val ` inside the ` match ` has type ` int ` . In other words, the left hand
3906
+ side of the pattern destructures the value. If we have ` &5i ` , then in ` &val ` , ` val `
3907
3907
would be ` 5i ` .
3908
3908
3909
3909
If you want to get a reference, use the ` ref ` keyword:
@@ -3912,19 +3912,19 @@ If you want to get a reference, use the `ref` keyword:
3912
3912
let x = 5i;
3913
3913
3914
3914
match x {
3915
- ref x => println!("Got a reference to {}", x ),
3915
+ ref r => println!("Got a reference to {}", r ),
3916
3916
}
3917
3917
```
3918
3918
3919
- Here, the ` x ` inside the ` match ` has the type ` &int ` . In other words, the ` ref `
3919
+ Here, the ` r ` inside the ` match ` has the type ` &int ` . In other words, the ` ref `
3920
3920
keyword _ creates_ a reference, for use in the pattern. If you need a mutable
3921
3921
reference, ` ref mut ` will work in the same way:
3922
3922
3923
3923
``` {rust}
3924
3924
let mut x = 5i;
3925
3925
3926
3926
match x {
3927
- ref mut x => println!("Got a mutable reference to {}", x ),
3927
+ ref mut mr => println!("Got a mutable reference to {}", mr ),
3928
3928
}
3929
3929
```
3930
3930
0 commit comments