Skip to content

Commit 69ffed7

Browse files
Add error explanation for E0755
1 parent 02fe309 commit 69ffed7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ E0751: include_str!("./error_codes/E0751.md"),
440440
E0752: include_str!("./error_codes/E0752.md"),
441441
E0753: include_str!("./error_codes/E0753.md"),
442442
E0754: include_str!("./error_codes/E0754.md"),
443+
E0755: include_str!("./error_codes/E0755.md"),
443444
E0758: include_str!("./error_codes/E0758.md"),
444445
E0759: include_str!("./error_codes/E0759.md"),
445446
E0760: include_str!("./error_codes/E0760.md"),
@@ -631,7 +632,6 @@ E0773: include_str!("./error_codes/E0773.md"),
631632
E0722, // Malformed `#[optimize]` attribute
632633
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
633634
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
634-
E0755, // `#[ffi_pure]` is only allowed on foreign functions
635635
E0756, // `#[ffi_const]` is only allowed on foreign functions
636636
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
637637
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
The `ffi_pure` attribute was used on a non-foreign function.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0755
6+
#![feature(ffi_pure)]
7+
8+
#[ffi_pure] // error!
9+
pub fn foo() {}
10+
# fn main() {}
11+
```
12+
13+
The `ffi_pure` attribute can only be used on foreign functions which do not have
14+
side effects or infinite loops:
15+
16+
```
17+
#![feature(ffi_pure)]
18+
19+
extern "C" {
20+
#[ffi_pure] // ok!
21+
pub fn strlen(s: *const i8) -> isize;
22+
}
23+
# fn main() {}
24+
```
25+
26+
You can find more information about it in the [unstable Rust Book].
27+
28+
[unstable Rust Book]: https://doc.rust-lang.org/unstable-book/language-features/ffi-pure.html

src/test/ui/ffi_pure.stderr

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

77
error: aborting due to previous error
88

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

0 commit comments

Comments
 (0)