diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-22 19:58:22 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-22 19:58:22 +0000 |
commit | 3d8a0982a12f3aa4b8c193a841f864b15c3cb66e (patch) | |
tree | e20ae00628cc28417e22621f583ba6988677ffcd /crates/ra_ide_api/src | |
parent | bb665a70627cbc2f4fb930fefb04899941b6afa6 (diff) | |
parent | 247d1c17b385ff8a8c1dda2e899495146b643b98 (diff) |
Merge #866
866: Implement basic support for Associated Methods r=flodiebold a=vipentti
This is my attempt at learning to understand how the type inference works by adding basic support for associated methods. Currently it does not resolve associated types or constants.
The basic idea is that `Resolver::resolve_path` returns a new `PathResult` type, which has two variants, `FullyResolved` and `PartiallyResolved`, fully resolved matches the previous behavior, where as `PartiallyResolved` contains the `PerNs<Resolution` in addition to a `segment_index` which contains the index of the segment which we failed to resolve. This index can then be used to continue inference in `infer_path_expr` using the `Type` we managed to resolve.
This changes some of the previous apis, so looking for feedback and suggestions.
This should enable fixing #832
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index a41c4e546..c62683ad4 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -240,4 +240,24 @@ mod tests { | |||
240 | assert_eq!("usize", &type_name); | 240 | assert_eq!("usize", &type_name); |
241 | } | 241 | } |
242 | 242 | ||
243 | #[test] | ||
244 | fn test_hover_infer_associated_method_result() { | ||
245 | let (analysis, position) = single_file_with_position( | ||
246 | " | ||
247 | struct Thing { x: u32 }; | ||
248 | |||
249 | impl Thing { | ||
250 | fn new() -> Thing { | ||
251 | Thing { x: 0 } | ||
252 | } | ||
253 | } | ||
254 | |||
255 | fn main() { | ||
256 | let foo_<|>test = Thing::new(); | ||
257 | } | ||
258 | ", | ||
259 | ); | ||
260 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
261 | assert_eq!(hover.info, "Thing"); | ||
262 | } | ||
243 | } | 263 | } |