Skip to content

Add long explanation for E0757 #87342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0756: include_str!("./error_codes/E0756.md"),
E0757: include_str!("./error_codes/E0757.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
Expand Down Expand Up @@ -638,6 +639,5 @@ E0783: include_str!("./error_codes/E0783.md"),
// E0723, unstable feature in `const` context
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
}
25 changes: 25 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0757.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A function was given both the `ffi_const` and `ffi_pure` attributes.

Erroneous code example:

```compile_fail,E0757
#![feature(ffi_const, ffi_pure)]

extern "C" {
#[ffi_const]
#[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]`
pub fn square(num: i32) -> i32;
}
```

As `const` has a stricter set of requirements than `pure`, remove the `ffi_pure`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ffi_const you mean? Also, is there a documentation we could link to by any chance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I mean const. const and pure are C function attributes (e.g. see Common Function Attributes). Annotating a function with ffi_const says that it's C const, and annotating with ffi_pure says that it's C pure. I could use ffi_const and ffi_pure instead, but I felt it was more readable to lift the covers up to what they mean in GCC or other C compilers. What do you think?

I could link to ffi-pure and ffi-const from the unstable rust book. The former does mention that #[ffi_const] provides stronger guarantees, which implies that it's stricter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ffi_* instead then. If I asked the questions, others will wonder about the same thing as well. Please add the links as well then.

attribute:

```
#![feature(ffi_const)]

extern "C" {
#[ffi_const]
pub fn square(num: i32) -> i32;
}
```
1 change: 1 addition & 0 deletions src/test/ui/ffi_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | #[ffi_pure]

error: aborting due to previous error

For more information about this error, try `rustc --explain E0757`.