@@ -37,7 +37,7 @@ match foo {
37
37
a wildcard arm above a more specific arm will make the latter arm irrelevant.
38
38
39
39
Ensure the ordering of the match arm is correct and remove any superfluous
40
- checks .
40
+ arms .
41
41
"## ,
42
42
43
43
E0002 : r##"
@@ -81,8 +81,8 @@ match number {
81
81
}
82
82
```
83
83
84
- To match against NaN values, you should
85
- instead use the `is_nan()` method in a guard, like so:
84
+ To match against NaN values, you should instead use the `is_nan()` method in a
85
+ guard, like so:
86
86
87
87
```
88
88
match number {
@@ -333,8 +333,8 @@ Statics are shared everywhere, and if they refer to mutable data one might
333
333
violate memory safety since holding multiple mutable references to shared data
334
334
is not allowed.
335
335
336
- If you really want global mutable state, try using a global `UnsafeCell` or
337
- `static mut `.
336
+ If you really want global mutable state, try using `static mut` or a global
337
+ `UnsafeCell `.
338
338
339
339
"## ,
340
340
@@ -416,7 +416,7 @@ is bad because the function body may not mutate `x`.
416
416
417
417
Remove any mutable bindings from the argument list to fix this error. In case
418
418
you need to mutate the argument, try lazily initializing a global variable
419
- instead of using a const fn, or refactoring the code to a functional style to
419
+ instead of using a ` const fn` , or refactoring the code to a functional style to
420
420
avoid mutation if possible.
421
421
"## ,
422
422
@@ -444,11 +444,11 @@ requirements are satisfied by the trait in question.
444
444
445
445
Trait objects are a form of dynamic dispatch and use a dynamically sized type
446
446
for the inner type. So, for a given trait `Trait`, when `Trait` is treated as a
447
- type, as in `Box<Trait>`, the inner type is " unsized" . In such cases the boxed
448
- pointer is a " fat pointer" that contains an extra pointer to a table of methods
447
+ type, as in `Box<Trait>`, the inner type is ' unsized' . In such cases the boxed
448
+ pointer is a ' fat pointer' that contains an extra pointer to a table of methods
449
449
(among other things) for dynamic dispatch. This design mandates some
450
450
restrictions on the types of traits that are allowed to be used in trait
451
- objects, which are collectively termed as " object safety" rules.
451
+ objects, which are collectively termed as ' object safety' rules.
452
452
453
453
Attempting to create a trait object for a non object-safe trait will trigger
454
454
this error.
@@ -513,7 +513,7 @@ fn call_foo(x: Box<Trait>) {
513
513
If only some methods aren't object-safe, you can add a `where Self: Sized` bound
514
514
on them to mark them as explicitly unavailable to trait objects. The
515
515
functionality will still be available to all other implementers, including
516
- `Box<Trait>` which is itself sized (assuming you `impl Trait for Box<Trait>`)
516
+ `Box<Trait>` which is itself sized (assuming you `impl Trait for Box<Trait>`).
517
517
518
518
```
519
519
trait Trait {
@@ -530,7 +530,7 @@ that trait that aren't behind trait objects.
530
530
### Method has generic type parameters
531
531
532
532
As mentioned before, trait objects contain pointers to method tables. So, if we
533
- have
533
+ have:
534
534
535
535
```
536
536
trait Trait {
@@ -549,7 +549,7 @@ impl Trait for u8 {
549
549
// ...
550
550
```
551
551
552
- at compile time each implementation of `Trait` will produce a table containing
552
+ At compile time each implementation of `Trait` will produce a table containing
553
553
the various methods (and other items) related to the implementation.
554
554
555
555
This works fine, but when the method gains generic parameters, we can have a
@@ -578,7 +578,7 @@ that implements the trait. Now, if it has type parameters, we need to add
578
578
implementations for every type that implements the trait, and there could
579
579
theoretically be an infinite number of types.
580
580
581
- For example, with
581
+ For example, with:
582
582
583
583
```
584
584
trait Trait {
@@ -598,7 +598,7 @@ impl Trait for u8 {
598
598
// 8 more implementations
599
599
```
600
600
601
- Now, if I have the following code:
601
+ Now, if we have the following code:
602
602
603
603
```
604
604
fn call_foo(thing: Box<Trait>) {
@@ -647,7 +647,6 @@ an implementation.
647
647
648
648
Adding a `Self: Sized` bound to these methods will generally make this compile.
649
649
650
-
651
650
```
652
651
trait Foo {
653
652
fn foo() -> u8 where Self: Sized;
@@ -752,7 +751,8 @@ https://doc.rust-lang.org/reference.html#ffi-attributes
752
751
"## ,
753
752
754
753
E0109 : r##"
755
- You tried to give a type parameter to a type which doesn't need it; for example:
754
+ You tried to give a type parameter to a type which doesn't need it. Erroneous
755
+ code example:
756
756
757
757
```
758
758
type X = u32<i32>; // error: type parameters are not allowed on this type
@@ -769,8 +769,8 @@ type X = u32; // this compiles
769
769
"## ,
770
770
771
771
E0110 : r##"
772
- You tried to give a lifetime parameter to a type which doesn't need it; for
773
- example:
772
+ You tried to give a lifetime parameter to a type which doesn't need it.
773
+ Erroneous code example:
774
774
775
775
```
776
776
type X = u32<'static>; // error: lifetime parameters are not allowed on
@@ -882,6 +882,14 @@ fn foo<T: MyTransmutableType>(x: Vec<T>) {
882
882
Each impl will be checked for a size match in the transmute as usual, and since
883
883
there are no unbound type parameters involved, this should compile unless there
884
884
is a size mismatch in one of the impls.
885
+
886
+ It is also possible to manually transmute:
887
+
888
+ ```
889
+ let result: SomeType = mem::uninitialized();
890
+ unsafe { copy_nonoverlapping(&v, &result) };
891
+ result // `v` transmuted to type `SomeType`
892
+ ```
885
893
"## ,
886
894
887
895
E0152 : r##"
@@ -1157,7 +1165,7 @@ returning an appropriate value or panicking if necessary.
1157
1165
1158
1166
E0270 : r##"
1159
1167
Rust lets you define functions which are known to never return, i.e. are
1160
- " diverging" , by marking its return type as `!`.
1168
+ ' diverging' , by marking its return type as `!`.
1161
1169
1162
1170
For example, the following functions never return:
1163
1171
@@ -1416,7 +1424,7 @@ add one of the same name as a type parameter. If you intended to use literal
1416
1424
braces, use `{{` and `}}` to escape them.
1417
1425
"## ,
1418
1426
1419
- E0273 : r##"
1427
+ E0274 : r##"
1420
1428
The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
1421
1429
message for when a particular trait isn't implemented on a type placed in a
1422
1430
position that needs that trait. For example, when the following code is
0 commit comments