diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-29 22:01:36 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-29 22:01:36 +0000 |
commit | ad4e108c39696b368705d9238f44b10fced91a58 (patch) | |
tree | 0597ebf09ac6c3216477c4993a8f16686f0ca452 /crates/ra_hir_ty/src/tests/traits.rs | |
parent | 5e78036e6c8752fda350818afdd411ab25f405ce (diff) | |
parent | 31171eed5eeab217280237e63ffe6adda62baf96 (diff) |
Merge #3380
3380: Unsizing in method resolution & autoderef for indexing r=matklad a=flodiebold
- do autoderef for indexing
- do array unsizing (`[T; N]` -> `[T]`) in both method resolution and indexing. It turns out array unsizing is actually the only unsizing coercion that rustc does for method receivers, so this is simpler than I expected.
Sadly, this doesn't fix indexing slices/arrays yet, there are still some trait solving problems...
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 7d796d0b9..547010b35 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -568,6 +568,34 @@ mod ops { | |||
568 | } | 568 | } |
569 | 569 | ||
570 | #[test] | 570 | #[test] |
571 | fn infer_ops_index_autoderef() { | ||
572 | let (db, pos) = TestDB::with_position( | ||
573 | r#" | ||
574 | //- /main.rs crate:main deps:std | ||
575 | fn test() { | ||
576 | let a = &[1u32, 2, 3]; | ||
577 | let b = a[1]; | ||
578 | b<|>; | ||
579 | } | ||
580 | |||
581 | //- /std.rs crate:std | ||
582 | impl<T> ops::Index<u32> for [T] { | ||
583 | type Output = T; | ||
584 | } | ||
585 | |||
586 | #[prelude_import] use ops::*; | ||
587 | mod ops { | ||
588 | #[lang = "index"] | ||
589 | pub trait Index<Idx> { | ||
590 | type Output; | ||
591 | } | ||
592 | } | ||
593 | "#, | ||
594 | ); | ||
595 | assert_eq!("u32", type_at_pos(&db, pos)); | ||
596 | } | ||
597 | |||
598 | #[test] | ||
571 | fn deref_trait() { | 599 | fn deref_trait() { |
572 | let t = type_at( | 600 | let t = type_at( |
573 | r#" | 601 | r#" |