rust-analyzer/crates
bors 7738ff4927 Auto merge of #14945 - justahero:gh-14626, r=Veykril
Fix Assist "replace named generic type with impl trait"

This is a follow-up PR to fix the assist "replace named generic type with impl trait" described in #14626 to filter invalid param types. It integrates the feedback given in PR #14816 .

The change updates the logic to determine when a function parameter is safe to replace a type param with its trait implementation. Some parameter definitions are invalid & should not be replaced by their traits, therefore skipping the assist completely.

First, all usages of the generic type under the cursor are determined. These usage references are checked to see if they occur outside the function parameter list. If an outside reference is found, e.g. in body, return type or where clause, the assist is skipped. All remaining usages need to appear only in the function param list. For each usage the param type is further inspected to see if it's valid. The logic to determine if a function parameter is valid, follows a heuristic and may not cover all possible parameter definitions.

With this change the following param types (as given in [this comment](https://github.com/rust-lang/rust-analyzer/pull/14816#discussion_r1206834603)) are not replaced & therefore skip the assist.

```rust
fn foo<P: Trait>(
    _: <P as Trait>::Assoc,          // within path type qualifier
    _: <() as OtherTrait<P>>::Assoc, // same as above
    _: P::Assoc,                     // associated type shorthand
    _: impl OtherTrait<P>            // generic arg in impl trait (note that associated type bindings are fine)
    _: &dyn Fn(P)                    // param type and/or return type for Fn* traits
) {}
```
2023-06-02 13:09:31 +00:00
..
base-db Add diagnostic for _ expressions (typed holes) 2023-05-28 14:55:28 +02:00
cfg Allow setting cfgs 2023-05-28 13:43:21 +02:00
flycheck Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00
hir Auto merge of #14947 - HKalbasi:render-const, r=HKalbasi 2023-06-02 10:18:36 +00:00
hir-def Auto merge of #14941 - Veykril:def-map, r=Veykril 2023-06-01 16:42:12 +00:00
hir-expand Don't add --all-targets to runnables for no-std crates 2023-05-28 14:18:44 +02:00
hir-ty Auto merge of #14947 - HKalbasi:render-const, r=HKalbasi 2023-06-02 10:18:36 +00:00
ide Auto merge of #14947 - HKalbasi:render-const, r=HKalbasi 2023-06-02 10:18:36 +00:00
ide-assists Improve assist to filter invalid params 2023-06-02 12:46:01 +02:00
ide-completion Slightly shrink DefMap 2023-06-01 14:46:36 +02:00
ide-db Slightly shrink DefMap 2023-06-01 14:46:36 +02:00
ide-diagnostics Auto merge of #14941 - Veykril:def-map, r=Veykril 2023-06-01 16:42:12 +00:00
ide-ssr internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
intern Remove double lookups from Interned 2023-05-24 12:54:25 +02:00
limit Move Expander and LowerCtx into separate modules 2023-04-17 20:44:06 +02:00
mbe Implement ${count()} metavariable expression 2023-05-28 19:54:36 +09:00
parser Recover from leading comma in tuple pat and expr 2023-06-01 08:40:50 +02:00
paths Add AbsPath::absolutize 2023-05-13 11:51:28 +02:00
proc-macro-api Use triomphe Arc 2023-05-02 20:02:43 +03:00
proc-macro-srv Add proof-of-concept QoS implementation 2023-05-20 22:29:32 +10:00
proc-macro-srv-cli Remove proc-macro server command from the rust-analyzer binary 2023-04-26 08:19:28 +02:00
proc-macro-test ⬆️ rust-analyzer 2023-02-13 13:55:14 +02:00
profile internal: Add some additional status ouput 2023-04-22 09:34:47 +02:00
project-model fix: Don't duplicate sysroot crates in rustc workspace 2023-05-31 15:37:35 +02:00
rust-analyzer Auto merge of #14888 - lunacookies:multi-qos, r=Veykril 2023-05-31 10:23:19 +00:00
sourcegen Use retain_mut in CommentBlock::extract 2023-03-31 17:41:40 -04:00
stdx Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00
syntax Auto merge of #14842 - alibektas:internal/ast-make-improve, r=Veykril 2023-05-30 16:09:46 +00:00
test-utils Add enum, reference, array and slice to render_const_scalar 2023-06-02 13:47:02 +03:30
text-edit Make text-size a workspace dep 2023-05-06 00:49:23 -07:00
toolchain ⬆️ rust-analyzer 2023-03-13 10:42:24 +02:00
tt Emit function bodies in expanding builtin derives 2023-05-03 14:14:47 +03:30
vfs Auto merge of #14755 - poliorcetics:clippy-fixes, r=Veykril 2023-05-24 11:13:52 +00:00
vfs-notify Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00