]> git.lizzy.rs Git - rust.git/commitdiff
Add explanation for E0756
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 8 Sep 2020 19:02:18 +0000 (21:02 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 21 Sep 2020 19:04:56 +0000 (21:04 +0200)
compiler/rustc_error_codes/src/error_codes.rs
compiler/rustc_error_codes/src/error_codes/E0756.md [new file with mode: 0644]
src/test/ui/ffi_const.stderr

index 23a7b08016e509bbde955726d6b8527d9ea2afd6..a202736ea6cbeab90db5310ff1d0777264bb5af7 100644 (file)
 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"),
     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 {}`.
 }
diff --git a/compiler/rustc_error_codes/src/error_codes/E0756.md b/compiler/rustc_error_codes/src/error_codes/E0756.md
new file mode 100644 (file)
index 0000000..ffdc421
--- /dev/null
@@ -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
index 623551cc07bbb4ba288590180afa449d6c0bcf18..bc3c12eaf981b96f663a1d2b662f7d69b2e2139d 100644 (file)
@@ -6,3 +6,4 @@ LL | #[ffi_const]
 
 error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0756`.