Skip to content

Commit 0836a6f

Browse files
Add E0510 error explanation
1 parent 3448e3c commit 0836a6f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/librustc_trans/diagnostics.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@
1212

1313
register_long_diagnostics! {
1414

15+
E0510: r##"
16+
`return_address` was used in an invalid context. Erroneous code example:
17+
18+
```
19+
extern "rust-intrinsic" {
20+
fn return_address() -> *const u8;
21+
}
22+
23+
pub unsafe fn by_value() -> i32 {
24+
let _ = return_address();
25+
// error: invalid use of `return_address` intrinsic: function does
26+
// not use out pointer
27+
0
28+
}
29+
```
30+
31+
Returned values are stored in registers. In the case where the returned
32+
type doesn't fit in a register, the function returns `()` and has an
33+
additional input argument, this is a pointer where the result should
34+
be written. Example:
35+
36+
```
37+
extern "rust-intrinsic" {
38+
fn return_address() -> *const u8;
39+
}
40+
41+
pub unsafe fn by_pointer() -> String {
42+
let _ = return_address();
43+
String::new() // ok!
44+
}
45+
```
46+
"##,
47+
1548
E0512: r##"
1649
A transmute was called on types with different sizes. Erroneous code example:
1750
@@ -59,6 +92,5 @@ let x = &[0, 1, 2][2]; // ok
5992
}
6093

6194
register_diagnostics! {
62-
E0510, // invalid use of `return_address` intrinsic: function does not use out pointer
6395
E0511, // invalid monomorphization of `{}` intrinsic
6496
}

0 commit comments

Comments
 (0)