Skip to content

Commit 09a63c1

Browse files
Add E0513 error explanation
1 parent 2d1d4d1 commit 09a63c1

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,6 +3766,45 @@ extern "platform-intrinsic" {
37663766
```
37673767
"##,
37683768

3769+
E0513: r##"
3770+
The type of the variable couldn't be found out.
3771+
3772+
Erroneous code example:
3773+
3774+
```compile_fail,E0513
3775+
use std::mem;
3776+
3777+
unsafe {
3778+
let size = mem::size_of::<u32>();
3779+
mem::transmute_copy::<u32, [u8; size]>(&8_8);
3780+
// error: no type for local variable
3781+
}
3782+
```
3783+
3784+
To fix this error, please use a constant size instead of `size`. To make
3785+
this error more obvious, you could run:
3786+
3787+
```compile_fail,E0080
3788+
use std::mem;
3789+
3790+
unsafe {
3791+
mem::transmute_copy::<u32, [u8; mem::size_of::<u32>()]>(&8_8);
3792+
// error: constant evaluation error
3793+
}
3794+
```
3795+
3796+
So now, you can fix your code by setting the size directly:
3797+
3798+
```
3799+
use std::mem;
3800+
3801+
unsafe {
3802+
mem::transmute_copy::<u32, [u8; 4]>(&8_8);
3803+
// `u32` is 4 bytes so we replace the `mem::size_of` call with its size
3804+
}
3805+
```
3806+
"##,
3807+
37693808
E0516: r##"
37703809
The `typeof` keyword is currently reserved but unimplemented.
37713810
Erroneous code example:
@@ -4064,7 +4103,6 @@ register_diagnostics! {
40644103
E0399, // trait items need to be implemented because the associated
40654104
// type `{}` was overridden
40664105
E0436, // functional record update requires a struct
4067-
E0513, // no type for local variable ..
40684106
E0521, // redundant default implementations of trait
40694107
E0533, // `{}` does not name a unit variant, unit struct or a constant
40704108
E0562, // `impl Trait` not allowed outside of function

0 commit comments

Comments
 (0)