Skip to content

Commit c588935

Browse files
committed
Address comments
1 parent 522a978 commit c588935

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/librustc/diagnostics.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ match foo {
3737
a wildcard arm above a more specific arm will make the latter arm irrelevant.
3838
3939
Ensure the ordering of the match arm is correct and remove any superfluous
40-
checks.
40+
arms.
4141
"##,
4242

4343
E0002: r##"
@@ -81,8 +81,8 @@ match number {
8181
}
8282
```
8383
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:
8686
8787
```
8888
match number {
@@ -333,8 +333,8 @@ Statics are shared everywhere, and if they refer to mutable data one might
333333
violate memory safety since holding multiple mutable references to shared data
334334
is not allowed.
335335
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`.
338338
339339
"##,
340340

@@ -416,7 +416,7 @@ is bad because the function body may not mutate `x`.
416416
417417
Remove any mutable bindings from the argument list to fix this error. In case
418418
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
420420
avoid mutation if possible.
421421
"##,
422422

@@ -444,11 +444,11 @@ requirements are satisfied by the trait in question.
444444
445445
Trait objects are a form of dynamic dispatch and use a dynamically sized type
446446
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
449449
(among other things) for dynamic dispatch. This design mandates some
450450
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.
452452
453453
Attempting to create a trait object for a non object-safe trait will trigger
454454
this error.
@@ -513,7 +513,7 @@ fn call_foo(x: Box<Trait>) {
513513
If only some methods aren't object-safe, you can add a `where Self: Sized` bound
514514
on them to mark them as explicitly unavailable to trait objects. The
515515
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>`).
517517
518518
```
519519
trait Trait {
@@ -530,7 +530,7 @@ that trait that aren't behind trait objects.
530530
### Method has generic type parameters
531531
532532
As mentioned before, trait objects contain pointers to method tables. So, if we
533-
have
533+
have:
534534
535535
```
536536
trait Trait {
@@ -549,7 +549,7 @@ impl Trait for u8 {
549549
// ...
550550
```
551551
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
553553
the various methods (and other items) related to the implementation.
554554
555555
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
578578
implementations for every type that implements the trait, and there could
579579
theoretically be an infinite number of types.
580580
581-
For example, with
581+
For example, with:
582582
583583
```
584584
trait Trait {
@@ -598,7 +598,7 @@ impl Trait for u8 {
598598
// 8 more implementations
599599
```
600600
601-
Now, if I have the following code:
601+
Now, if we have the following code:
602602
603603
```
604604
fn call_foo(thing: Box<Trait>) {
@@ -647,7 +647,6 @@ an implementation.
647647
648648
Adding a `Self: Sized` bound to these methods will generally make this compile.
649649
650-
651650
```
652651
trait Foo {
653652
fn foo() -> u8 where Self: Sized;
@@ -752,7 +751,8 @@ https://doc.rust-lang.org/reference.html#ffi-attributes
752751
"##,
753752

754753
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:
756756
757757
```
758758
type X = u32<i32>; // error: type parameters are not allowed on this type
@@ -769,8 +769,8 @@ type X = u32; // this compiles
769769
"##,
770770

771771
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:
774774
775775
```
776776
type X = u32<'static>; // error: lifetime parameters are not allowed on
@@ -882,6 +882,14 @@ fn foo<T: MyTransmutableType>(x: Vec<T>) {
882882
Each impl will be checked for a size match in the transmute as usual, and since
883883
there are no unbound type parameters involved, this should compile unless there
884884
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+
```
885893
"##,
886894

887895
E0152: r##"
@@ -1157,7 +1165,7 @@ returning an appropriate value or panicking if necessary.
11571165

11581166
E0270: r##"
11591167
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 `!`.
11611169
11621170
For example, the following functions never return:
11631171
@@ -1416,7 +1424,7 @@ add one of the same name as a type parameter. If you intended to use literal
14161424
braces, use `{{` and `}}` to escape them.
14171425
"##,
14181426

1419-
E0273: r##"
1427+
E0274: r##"
14201428
The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
14211429
message for when a particular trait isn't implemented on a type placed in a
14221430
position that needs that trait. For example, when the following code is

0 commit comments

Comments
 (0)