rust/compiler/rustc_borrowck/src
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
..
constraints Remove ordering traits from rustc_borrowck::constraints::OutlivesConstraint 2022-01-19 13:12:26 -06:00
diagnostics Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank 2022-03-03 01:09:11 +01:00
region_infer compiler: fix some typos 2022-03-01 20:02:47 +08:00
type_check Rollup merge of #93603 - connorff:compute-polonius-liveness-facts-flag, r=ecstatic-morse 2022-02-26 00:49:20 +01:00
borrow_set.rs Remove in_band_lifetimes from borrowck 2021-12-15 08:39:21 +01:00
borrowck_errors.rs rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
constraint_generation.rs Overhaul RegionKind and Region. 2022-02-15 16:08:52 +11:00
consumers.rs Add InferCtxt::with_opaque_type_inference to get_body_with_borrowck_facts 2021-10-06 19:07:56 -07:00
dataflow.rs Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
def_use.rs Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
facts.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
invalidation.rs Remove no longer used MutateMode enum 2022-01-12 18:51:31 +01:00
lib.rs rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
location.rs Move rustc_mir::borrow_check to new crate rustc_borrowck. 2021-09-07 00:29:22 +02:00
member_constraints.rs Remove in_band_lifetimes from borrowck 2021-12-15 08:39:21 +01:00
nll.rs Rollup merge of #93603 - connorff:compute-polonius-liveness-facts-flag, r=ecstatic-morse 2022-02-26 00:49:20 +01:00
path_utils.rs Remove in_band_lifetimes from borrowck 2021-12-15 08:39:21 +01:00
place_ext.rs Move rustc_mir::borrow_check to new crate rustc_borrowck. 2021-09-07 00:29:22 +02:00
places_conflict.rs 3 - Make more use of let_chains 2022-02-27 11:10:20 -03:00
prefixes.rs Move rustc_mir::borrow_check to new crate rustc_borrowck. 2021-09-07 00:29:22 +02:00
renumber.rs Overhaul Const. 2022-02-15 16:19:59 +11:00
universal_regions.rs Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic. 2022-02-23 05:38:19 +00:00
used_muts.rs Move rustc_mir::borrow_check to new crate rustc_borrowck. 2021-09-07 00:29:22 +02:00