Skip to content
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

Add error explanation for E0755 #76439

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -440,6 +440,7 @@ E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.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 @@ -631,7 +632,6 @@ E0773: include_str!("./error_codes/E0773.md"),
E0722, // Malformed `#[optimize]` attribute
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0755, // `#[ffi_pure]` is only allowed on foreign functions
E0756, // `#[ffi_const]` is only allowed on foreign functions
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0755.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The `ffi_pure` attribute was used on a non-foreign function.

Erroneous code example:

```compile_fail,E0755
#![feature(ffi_pure)]

#[ffi_pure] // error!
pub fn foo() {}
# fn main() {}
```

The `ffi_pure` attribute can only be used on foreign functions which do not have
side effects or infinite loops:

```
#![feature(ffi_pure)]

extern "C" {
#[ffi_pure] // ok!
pub fn strlen(s: *const i8) -> isize;
}
Copy link
Contributor

@pickfire pickfire Sep 7, 2020

Choose a reason for hiding this comment

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

I believe this also work right? Or maybe a better example of this.

#[ffi_pure]
extern "C" pub fn foo() {}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's better to have a bigger contrast. :)

Copy link
Contributor

@pickfire pickfire Sep 9, 2020

Choose a reason for hiding this comment

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

Oh, I was just suggesting to show both methods so the readers know. Personally I know the second more.

# fn main() {}
```

You can find more information about it in the [unstable Rust Book].

[unstable Rust Book]: https://doc.rust-lang.org/unstable-book/language-features/ffi-pure.html
1 change: 1 addition & 0 deletions src/test/ui/ffi_pure.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 E0755`.