diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2020-11-28 15:58:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-28 15:58:30 +0100 |
| commit | 208d680f771601cf5efb6a7bfb49cb2b9e655d3e (patch) | |
| tree | 74c4ea90fdc836713c72cb393d1b8f442dd0e4c4 | |
| parent | 248e5ad299de46bcdd8c5d8a35d6d8cd07de54c2 (diff) | |
| parent | 1b846bfbccbb3780ca1a9830f0ab72061f52ebb8 (diff) | |
| download | rust-208d680f771601cf5efb6a7bfb49cb2b9e655d3e.tar.gz rust-208d680f771601cf5efb6a7bfb49cb2b9e655d3e.zip | |
Rollup merge of #79486 - camelid:E0591-code-cleanup, r=lcnr
Slightly improve code samples in E0591 * Improve formatting * Don't hide `unsafe` block - it's important!
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0591.md | 20 | ||||
| -rw-r--r-- | src/test/ui/explain.stdout | 18 |
2 files changed, 26 insertions, 12 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0591.md b/compiler/rustc_error_codes/src/error_codes/E0591.md index 7f68815b1c2..f49805d9b4e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0591.md +++ b/compiler/rustc_error_codes/src/error_codes/E0591.md @@ -1,14 +1,20 @@ Per [RFC 401][rfc401], if you have a function declaration `foo`: ``` +struct S; + // For the purposes of this explanation, all of these // different kinds of `fn` declarations are equivalent: -struct S; + fn foo(x: S) { /* ... */ } # #[cfg(for_demonstration_only)] -extern "C" { fn foo(x: S); } +extern "C" { + fn foo(x: S); +} # #[cfg(for_demonstration_only)] -impl S { fn foo(self) { /* ... */ } } +impl S { + fn foo(self) { /* ... */ } +} ``` the type of `foo` is **not** `fn(S)`, as one might expect. @@ -40,10 +46,10 @@ extern "C" fn foo(userdata: Box<i32>) { # fn callback(_: extern "C" fn(*mut i32)) {} # use std::mem::transmute; -# unsafe { -let f: extern "C" fn(*mut i32) = transmute(foo); -callback(f); -# } +unsafe { + let f: extern "C" fn(*mut i32) = transmute(foo); + callback(f); +} ``` Here, transmute is being used to convert the types of the fn arguments. diff --git a/src/test/ui/explain.stdout b/src/test/ui/explain.stdout index c50c46ee564..62f1a7f98ea 100644 --- a/src/test/ui/explain.stdout +++ b/src/test/ui/explain.stdout @@ -1,12 +1,18 @@ Per [RFC 401][rfc401], if you have a function declaration `foo`: ``` +struct S; + // For the purposes of this explanation, all of these // different kinds of `fn` declarations are equivalent: -struct S; + fn foo(x: S) { /* ... */ } -extern "C" { fn foo(x: S); } -impl S { fn foo(self) { /* ... */ } } +extern "C" { + fn foo(x: S); +} +impl S { + fn foo(self) { /* ... */ } +} ``` the type of `foo` is **not** `fn(S)`, as one might expect. @@ -34,8 +40,10 @@ extern "C" fn foo(userdata: Box<i32>) { /* ... */ } -let f: extern "C" fn(*mut i32) = transmute(foo); -callback(f); +unsafe { + let f: extern "C" fn(*mut i32) = transmute(foo); + callback(f); +} ``` Here, transmute is being used to convert the types of the fn arguments. |
