rust/src/test
Dylan DPC 12ac312351
Rollup merge of #80284 - ThePuzzlemaker:issue-80179-fix, r=varkor
Suggest fn ptr rather than fn item and suggest to use `Fn` trait bounds rather than the unique closure type in E0121

Previously, using `_` as a return type in a function that returned a function/closure would provide a diagnostic that would cause a papercut. For example:
```rust
fn f() -> i32 { 0 }
fn fn_ptr() -> _ { f }
fn closure() -> _ { || 0 }
```
would result in this diagnostic:
```rust
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:2:16
  |
2 | fn fn_ptr() -> _ { f }
  |                ^
  |                |
  |                not allowed in type signatures
  |                help: replace with the correct return type: `fn() -> i32 {f}`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:3:17
  |
3 | fn closure() -> _ { || 0 }
  |                 ^
  |                 |
  |                 not allowed in type signatures
  |                 help: replace with the correct return type: `[closure@<anon>:3:21: 3:25]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0121`.
```
As can be seen, it was suggested to use the function definition return type `fn() -> i32 { f }` which is not valid syntax as a return type. Additionally, closures cause a papercut as unique closure types (notated in this case as `[closure@<anon>:3:21: 3:25]`) are not valid syntax either.

Instead, this PR implements this version of the diagnostic (this example is for the same code featured above):
```rust
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:2:16
  |
2 | fn fn_ptr() -> _ { f }
  |                ^
  |                |
  |                not allowed in type signatures
  |                help: replace with the correct return type: `fn() -> i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:3:17
  |
3 | fn closure() -> _ { || 0 }
  |                 ^ not allowed in type signatures
  |
  = help: consider using an `Fn`, `FnMut`, or `FnOnce` trait bound
  = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0121`.
```
As can be seen in this diagnostic, the papercut for returning a function item is fixed by suggesting the usage of a function pointer as the return type. As for closures, it's suggested to use an `Fn`, `FnMut`, or `FnOnce` trait bound (with further reading on closures and `Fn` traits in *The Book* for beginners). I did not implement a suggestion to use `impl Fn() -> i32` syntax as that was out-of-scope for my abilities at the moment, therefore someone in the future may want to implement that. Also, it's possible to use either `impl Trait` syntax, generics, or generics with a `where` clause, and some users may not want to use `impl Trait` syntax for their own reasons.

This PR fixes #80179.
2020-12-28 14:13:08 +01:00
..
assembly Add wasm32 support to inline asm 2020-12-01 12:18:21 -06:00
auxiliary
codegen Remove pointer comparison from slice equality 2020-12-26 06:43:51 +00:00
codegen-units simplify-locals: Remove unused assignments regardless of rvalue kind 2020-10-26 10:48:28 +01:00
compile-fail Move test from compile-fail to ui/binop 2020-12-21 00:27:53 +08:00
debuginfo Auto merge of #78461 - TimDiekmann:vec-alloc, r=Amanieu 2020-11-21 22:46:50 +00:00
incremental Disable the constant debuginfo promotion pass by default 2020-12-14 19:56:10 -05:00
mir-opt Rollup merge of #79999 - hencrice:yenlinc/79799, r=oli-obk 2020-12-25 03:39:33 +01:00
pretty Rename optin_builtin_traits to auto_traits 2020-11-23 14:14:06 -08:00
run-make Auto merge of #78122 - fusion-engineering-forks:fmt-write-bounds-check, r=Mark-Simulacrum 2020-11-29 23:14:40 +00:00
run-make-fulldeps Auto merge of #80187 - 0dvictor:nativelib, r=bjorn3 2020-12-25 08:17:21 +00:00
run-pass-valgrind Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
rustdoc Auto merge of #80181 - jyn514:intra-doc-primitives, r=Manishearth 2020-12-27 18:55:33 +00:00
rustdoc-js Add more rustdoc-js test cases 2020-12-03 14:11:37 -08:00
rustdoc-js-std
rustdoc-json Use true ID for def_id. 2020-12-05 22:38:57 +00:00
rustdoc-ui Auto merge of #80181 - jyn514:intra-doc-primitives, r=Manishearth 2020-12-27 18:55:33 +00:00
rustfix
ui Rollup merge of #80284 - ThePuzzlemaker:issue-80179-fix, r=varkor 2020-12-28 14:13:08 +01:00
ui-fulldeps Only deny doc_keyword in std and set it as "allow" by default 2020-12-03 16:48:17 +01:00
COMPILER_TESTS.md