Skip to content

Commit

Permalink
Rollup merge of rust-lang#76489 - GuillaumeGomez:add-explanation-e075…
Browse files Browse the repository at this point in the history
…6, r=jyn514

Add explanation for E0756

r? @pickfire
  • Loading branch information
Dylan-DPC authored Sep 22, 2020
2 parents b062780 + 63195ec commit b7a6aae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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 @@ -441,6 +441,7 @@ 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"),
E0756: include_str!("./error_codes/E0756.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 @@ -633,7 +634,6 @@ E0774: include_str!("./error_codes/E0774.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" { ... }`.
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 {}`.
}
29 changes: 29 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0756.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The `ffi_const` attribute was used on something other than a foreign function
declaration.

Erroneous code example:

```compile_fail,E0756
#![feature(ffi_const)]
#[ffi_const] // error!
pub fn foo() {}
# fn main() {}
```

The `ffi_const` attribute can only be used on foreign function declarations
which have no side effects except for their return value:

```
#![feature(ffi_const)]
extern "C" {
#[ffi_const] // ok!
pub fn strlen(s: *const i8) -> i32;
}
# fn main() {}
```

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

[unstable Rust Book]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
1 change: 1 addition & 0 deletions src/test/ui/ffi_const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | #[ffi_const]

error: aborting due to previous error

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

1 comment on commit b7a6aae

@pickfire
Copy link

@pickfire pickfire commented on b7a6aae Sep 22, 2020

Choose a reason for hiding this comment

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

@GuillaumeGomez next time can you please add r? @pickfire as part of the message in pull request but not in the commit? Otherwise I will get a ping when this is committed.

Please sign in to comment.