From 57feb323f79d1d7f7dd6251d4606ba12a800953a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 3 Jul 2020 17:39:06 +0200 Subject: Fix inference of indexing argument (partly) We need to add the `T: Index` obligation to be resolved later as well, otherwise we can't make inferences about `Arg` later based on the `Index` impls. This still doesn't fix indexing with integer variables though; there's a further problem with Chalk floundering because of the variable, I think. --- crates/ra_hir_ty/src/tests/traits.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 766790576..529d9e253 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -540,6 +540,42 @@ mod ops { ); } +#[test] +fn infer_ops_index_int() { + check_types( + r#" +//- /main.rs crate:main deps:std +struct Bar; +struct Foo; + +impl std::ops::Index for Bar { + type Output = Foo; +} + +struct Range; +impl std::ops::Index for Bar { + type Output = Bar; +} + +fn test() { + let a = Bar; + let b = a[1]; + b; + //^ Foo +} + +//- /std.rs crate:std +#[prelude_import] use ops::*; +mod ops { + #[lang = "index"] + pub trait Index { + type Output; + } +} +"#, + ); +} + #[test] fn infer_ops_index_autoderef() { check_types( -- cgit v1.2.3