diff options
author | Florian Diebold <[email protected]> | 2020-03-13 10:45:58 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-03-13 12:04:32 +0000 |
commit | d6195fa21f09aa3f987e09d847c156e1788ec834 (patch) | |
tree | fda6b0e03da9ef7fc7426dbf785bd6c050e845dd /crates/ra_ide/src/call_info.rs | |
parent | 02b44006b8e37a8cd3f96d5b1c949d62e01be2e8 (diff) |
Fix completion of HashMap::new
The `ty` function in code_model returned the type with placeholders for type
parameters. That's nice for printing, but not good for completion, because
placeholders won't unify with anything else: So the type we got for `HashMap`
was `HashMap<K, V, T>`, which doesn't unify with `HashMap<?, ?, RandomState>`,
so the `new` method wasn't shown.
Now we instead return `HashMap<{unknown}, {unknown}, {unknown}>`, which does
unify with the impl type. Maybe we should just expose this properly as variables
though, i.e. we'd return something like `exists<type, type, type> HashMap<?0,
?1, ?2>` (in Chalk notation). It'll make the API more complicated, but harder to
misuse. (And it would handle cases like `type TypeAlias<T> = HashMap<T, T>` more
correctly.)
Diffstat (limited to 'crates/ra_ide/src/call_info.rs')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 2b35a3803..39d09a07f 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -544,6 +544,20 @@ fn main() { | |||
544 | } | 544 | } |
545 | 545 | ||
546 | #[test] | 546 | #[test] |
547 | fn generic_struct() { | ||
548 | let info = call_info( | ||
549 | r#" | ||
550 | struct TS<T>(T); | ||
551 | fn main() { | ||
552 | let s = TS(<|>); | ||
553 | }"#, | ||
554 | ); | ||
555 | |||
556 | assert_eq!(info.label(), "struct TS<T>(T) -> TS"); | ||
557 | assert_eq!(info.active_parameter, Some(0)); | ||
558 | } | ||
559 | |||
560 | #[test] | ||
547 | #[should_panic] | 561 | #[should_panic] |
548 | fn cant_call_named_structs() { | 562 | fn cant_call_named_structs() { |
549 | let _ = call_info( | 563 | let _ = call_info( |