Skip to content

Commit 63195ec

Browse files
Add explanation for E0756
1 parent 4eff9b0 commit 63195ec

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ E0752: include_str!("./error_codes/E0752.md"),
441441
E0753: include_str!("./error_codes/E0753.md"),
442442
E0754: include_str!("./error_codes/E0754.md"),
443443
E0755: include_str!("./error_codes/E0755.md"),
444+
E0756: include_str!("./error_codes/E0756.md"),
444445
E0758: include_str!("./error_codes/E0758.md"),
445446
E0759: include_str!("./error_codes/E0759.md"),
446447
E0760: include_str!("./error_codes/E0760.md"),
@@ -633,7 +634,6 @@ E0774: include_str!("./error_codes/E0774.md"),
633634
E0722, // Malformed `#[optimize]` attribute
634635
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
635636
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
636-
E0756, // `#[ffi_const]` is only allowed on foreign functions
637637
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
638638
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
639639
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
The `ffi_const` attribute was used on something other than a foreign function
2+
declaration.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0756
7+
#![feature(ffi_const)]
8+
9+
#[ffi_const] // error!
10+
pub fn foo() {}
11+
# fn main() {}
12+
```
13+
14+
The `ffi_const` attribute can only be used on foreign function declarations
15+
which have no side effects except for their return value:
16+
17+
```
18+
#![feature(ffi_const)]
19+
20+
extern "C" {
21+
#[ffi_const] // ok!
22+
pub fn strlen(s: *const i8) -> i32;
23+
}
24+
# fn main() {}
25+
```
26+
27+
You can get more information about it in the [unstable Rust Book].
28+
29+
[unstable Rust Book]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html

src/test/ui/ffi_const.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | #[ffi_const]
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0756`.

0 commit comments

Comments
 (0)