diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-03 01:09:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-03 01:09:11 +0100 |
| commit | 7537b2036a472e80fce4295eb799a53f61f959c0 (patch) | |
| tree | ec75d349f3e5fc79f6f509bac6c229d3eebb6878 /compiler/rustc_codegen_llvm/src/context.rs | |
| parent | c9dc44be24c58ff13ce46416c4b97ab5c1bd8429 (diff) | |
| parent | f0a16b856011c8e63fac98fd6c127c2a0bbd532e (diff) | |
| download | rust-7537b2036a472e80fce4295eb799a53f61f959c0.tar.gz rust-7537b2036a472e80fce4295eb799a53f61f959c0.zip | |
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 :')
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/context.rs')
0 files changed, 0 insertions, 0 deletions
