Skip to content

Commit 3a8bc0d

Browse files
Rollup merge of #87342 - midgleyc:add-E0757-long, r=GuillaumeGomez
Add long explanation for E0757 Helps with #61137
2 parents 23ecb8b + 8b75fec commit 3a8bc0d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ E0753: include_str!("./error_codes/E0753.md"),
450450
E0754: include_str!("./error_codes/E0754.md"),
451451
E0755: include_str!("./error_codes/E0755.md"),
452452
E0756: include_str!("./error_codes/E0756.md"),
453+
E0757: include_str!("./error_codes/E0757.md"),
453454
E0758: include_str!("./error_codes/E0758.md"),
454455
E0759: include_str!("./error_codes/E0759.md"),
455456
E0760: include_str!("./error_codes/E0760.md"),
@@ -638,6 +639,5 @@ E0783: include_str!("./error_codes/E0783.md"),
638639
// E0723, unstable feature in `const` context
639640
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
640641
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
641-
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
642642
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
643643
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
A function was given both the `ffi_const` and `ffi_pure` attributes.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0757
6+
#![feature(ffi_const, ffi_pure)]
7+
8+
extern "C" {
9+
#[ffi_const]
10+
#[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]`
11+
pub fn square(num: i32) -> i32;
12+
}
13+
```
14+
15+
As `ffi_const` provides stronger guarantees than `ffi_pure`, remove the
16+
`ffi_pure` attribute:
17+
18+
```
19+
#![feature(ffi_const)]
20+
21+
extern "C" {
22+
#[ffi_const]
23+
pub fn square(num: i32) -> i32;
24+
}
25+
```
26+
27+
You can get more information about `const` and `pure` in the [GCC documentation
28+
on Common Function Attributes]. The unstable Rust Book has more information
29+
about [`ffi_const`] and [`ffi_pure`].
30+
31+
[GCC documentation on Common Function Attributes]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
32+
[`ffi_const`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
33+
[`ffi_pure`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-pure.html

src/test/ui/ffi_const2.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 E0757`.

0 commit comments

Comments
 (0)