rust/compiler
Dylan DPC 7537b2036a
Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank
Adt copy suggestions

Previously we've only suggested adding `Copy` bounds when the type being moved/copied is a type parameter (generic). With this PR we also suggest adding bounds when a type
- Can be copy
- All predicates that need to be satisfied for that are based on type params

i.e. we will suggest `T: Copy` for `Option<T>`, but won't suggest anything for `Option<String>`.

An example:
```rust
fn duplicate<T>(t: Option<T>) -> (Option<T>, Option<T>) {
    (t, t)
}
```
New error (current compiler doesn't provide `help`:):
```text
error[E0382]: use of moved value: `t`
 --> t.rs:2:9
  |
1 | fn duplicate<T>(t: Option<T>) -> (Option<T>, Option<T>) {
  |                 - move occurs because `t` has type `Option<T>`, which does not implement the `Copy` trait
2 |     (t, t)
  |      -  ^ value used here after move
  |      |
  |      value moved here
  |
help: consider restricting type parameter `T`
  |
1 | fn duplicate<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
  |               ++++++
```

Fixes #93623
r? ``````````@estebank``````````
``````````@rustbot`````````` label +A-diagnostics +A-suggestion-diagnostics +C-enhancement

----

I'm not at all sure if this is the right implementation for this kind of suggestion, but it seems to work :')
2022-03-03 01:09:11 +01:00
..
rustc remove unused jemallocator crate 2022-01-28 16:56:05 +01:00
rustc_apfloat
rustc_arena Remove unused dep from rustc_arena 2022-02-02 17:37:14 +01:00
rustc_ast 2 - Make more use of let_chains 2022-02-26 13:45:43 -03:00
rustc_ast_lowering compiler: fix some typos 2022-03-01 20:02:47 +08:00
rustc_ast_passes Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
rustc_ast_pretty Pretty print ItemKind::Use in rustfmt style 2022-02-07 21:51:05 -08:00
rustc_attr Rollup merge of #94175 - Urgau:check-cfg-improvements, r=petrochenkov 2022-02-24 21:42:13 +01:00
rustc_borrowck Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank 2022-03-03 01:09:11 +01:00
rustc_builtin_macros compiler: fix some typos 2022-03-01 20:02:47 +08:00
rustc_codegen_cranelift rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_codegen_gcc rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_codegen_llvm rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_codegen_ssa rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_const_eval rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_data_structures Auto merge of #94514 - matthiaskrgr:rollup-pdzn82h, r=matthiaskrgr 2022-03-02 05:32:00 +00:00
rustc_driver rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_error_codes Rollup merge of #94449 - GuillaumeGomez:explanation-e0726, r=Urgau 2022-02-28 20:05:18 +01:00
rustc_errors rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_expand rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_feature Remove in-band lifetimes 2022-02-24 18:50:33 -08:00
rustc_fs_util
rustc_graphviz
rustc_hir compiler: fix some typos 2022-03-01 20:02:47 +08:00
rustc_hir_pretty resolve: Fix incorrect results of opt_def_kind query for some built-in macros 2022-02-24 22:54:36 +03:00
rustc_incremental rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_index Fix test 2022-02-24 16:02:07 -05:00
rustc_infer rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_interface rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_lexer Improve scan_escape. 2022-02-24 17:01:01 +11:00
rustc_lint Rollup merge of #94397 - xFrednet:69838-deprecate-pre-expansion, r=cjgillot 2022-02-27 21:46:34 +01:00
rustc_lint_defs Improve diagnostic of the unexpected_cfgs lint 2022-02-22 23:17:13 +01:00
rustc_llvm Auto merge of #94229 - erikdesjardins:rem2, r=nikic 2022-03-02 08:48:33 +00:00
rustc_log
rustc_macros rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_metadata Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2022-02-25 18:34:02 +00:00
rustc_middle Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank 2022-03-03 01:09:11 +01:00
rustc_mir_build rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_mir_dataflow Rollup merge of #94087 - tmiasko:rm-ignore-borrow-on-drop, r=jackh726 2022-02-26 07:52:42 +01:00
rustc_mir_transform 7 - Make more use of let_chains 2022-03-01 07:43:12 -03:00
rustc_monomorphize rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_parse rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_parse_format Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
rustc_passes Rollup merge of #94448 - c410-f3r:yet-more-let-chains, r=estebank 2022-03-01 03:41:52 +01:00
rustc_plugin_impl
rustc_privacy Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
rustc_query_impl Auto merge of #94084 - Mark-Simulacrum:drop-sharded, r=cjgillot 2022-02-27 14:04:07 +00:00
rustc_query_system rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_resolve rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_save_analysis Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
rustc_serialize Delete Decoder::read_unit 2022-02-22 18:14:51 -05:00
rustc_session rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_span Auto merge of #94427 - cjgillot:inline-fresh-expn, r=oli-obk 2022-02-28 08:25:26 +00:00
rustc_symbol_mangling Rollup merge of #94359 - tmiasko:legacy-verbose-const, r=petrochenkov 2022-03-01 12:00:43 +01:00
rustc_target Auto merge of #94216 - psumbera:sparc64-abi-fix2, r=nagisa 2022-02-28 11:54:17 +00:00
rustc_trait_selection rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_traits chalk/db: use correct debrujin index when replacing opaque type. 2022-02-22 00:16:56 +01:00
rustc_ty_utils rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
rustc_type_ir Inline UnifyKey::index and UnifyKey::from_index 2022-02-15 19:07:06 +01:00
rustc_typeck Rollup merge of #93072 - m-ou-se:compatible-variants-suggestion-with-desugaring, r=estebank 2022-03-03 01:09:08 +01:00