mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
7537b2036a
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 :') |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |