diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-20 14:36:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-20 14:36:53 +0000 |
commit | d590f6ce12bf4d0311138846e26951b613f0afd4 (patch) | |
tree | d73816f61ccdaa2b9710ff5c7efbb3b62367c9c3 /crates/ra_hir_ty/src/tests/traits.rs | |
parent | 81a1b14d78d6078c63dd42c09da5a3e171c85a3a (diff) | |
parent | 76d688a328ab53b6264f9e489b88524377a7271d (diff) |
Merge #2592
2592: Add std::ops::Index support for infering r=edwin0cheng a=edwin0cheng
see also #2534
Seem like this can't fix #2534 for this case:
```rust
fn foo3(bar: [usize; 2]) {
let baz = bar[1]; // <--- baz is still unknown ?
println!("{}", baz);
}
```
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 802937cb0..2d92a5eec 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -427,6 +427,38 @@ fn indexing_arrays() { | |||
427 | } | 427 | } |
428 | 428 | ||
429 | #[test] | 429 | #[test] |
430 | fn infer_ops_index() { | ||
431 | let (db, pos) = TestDB::with_position( | ||
432 | r#" | ||
433 | //- /main.rs crate:main deps:std | ||
434 | |||
435 | struct Bar; | ||
436 | struct Foo; | ||
437 | |||
438 | impl std::ops::Index<u32> for Bar { | ||
439 | type Output = Foo; | ||
440 | } | ||
441 | |||
442 | fn test() { | ||
443 | let a = Bar; | ||
444 | let b = a[1]; | ||
445 | b<|>; | ||
446 | } | ||
447 | |||
448 | //- /std.rs crate:std | ||
449 | |||
450 | #[prelude_import] use ops::*; | ||
451 | mod ops { | ||
452 | pub trait Index<Idx> { | ||
453 | type Output; | ||
454 | } | ||
455 | } | ||
456 | "#, | ||
457 | ); | ||
458 | assert_eq!("Foo", type_at_pos(&db, pos)); | ||
459 | } | ||
460 | |||
461 | #[test] | ||
430 | fn deref_trait() { | 462 | fn deref_trait() { |
431 | let t = type_at( | 463 | let t = type_at( |
432 | r#" | 464 | r#" |